home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / emacs / info / termcap-1 (.txt) < prev    next >
GNU Info File  |  1992-10-30  |  49KB  |  875 lines

  1. This is Info file ../info/termcap, produced by Makeinfo-1.49 from the
  2. input file termcap.texi.
  3.    This file documents the termcap library of the GNU system.
  4.    Copyright (C) 1988 Free Software Foundation, Inc.
  5.    Permission is granted to make and distribute verbatim copies of this
  6. manual provided the copyright notice and this permission notice are
  7. preserved on all copies.
  8.    Permission is granted to copy and distribute modified versions of
  9. this manual under the conditions for verbatim copying, provided that
  10. the entire resulting derived work is distributed under the terms of a
  11. permission notice identical to this one.
  12.    Permission is granted to copy and distribute translations of this
  13. manual into another language, under the above conditions for modified
  14. versions, except that this permission notice may be stated in a
  15. translation approved by the Foundation.
  16. File: termcap,  Node: Top,  Next: Introduction,  Prev: (DIR),  Up: (DIR)
  17. * Menu:
  18. * Introduction::What is termcap?  Why this manual?
  19. * Library::     The termcap library functions.
  20. * Data Base::   What terminal descriptions in `/etc/termcap' look like.
  21. * Capabilities::Definitions of the individual terminal capabilities:
  22.                  how to write them in descriptions, and how to use
  23.                  their values to do display updating.
  24. * Summary::    Brief table of capability names and their meanings.
  25. * Var Index::   Index of C functions and variables.
  26. * Cap Index::   Index of termcap capabilities.
  27. * Index::       Concept index.
  28. File: termcap,  Node: Introduction,  Next: Library,  Prev: Top,  Up: Top
  29. Introduction
  30. ************
  31.    "Termcap" is a library and data base that enables programs to use
  32. display terminals in a terminal-independent manner.  It originated in
  33. Berkeley Unix.
  34.    The termcap data base describes the capabilities of hundreds of
  35. different display terminals in great detail.  Some examples of the
  36. information recorded for a terminal could include how many columns wide
  37. it is, what string to send to move the cursor to an arbitrary position
  38. (including how to encode the row and column numbers), how to scroll the
  39. screen up one or several lines, and how much padding is needed for such
  40. a scrolling operation.
  41.    The termcap library is provided for easy access this data base in
  42. programs that want to do terminal-independent character-based display
  43. output.
  44.    This manual describes the GNU version of the termcap library, which
  45. has some extensions over the Unix version.  All the extensions are
  46. identified as such, so this manual also tells you how to use the Unix
  47. termcap.
  48.    The GNU version of the termcap library is available free as source
  49. code, for use in free programs, and runs on Unix and VMS systems (at
  50. least).  You can find it in the GNU Emacs distribution in the files
  51. `termcap.c' and `tparam.c'.
  52.    This manual was written for the GNU project, whose goal is to
  53. develop a complete free operating system upward-compatible with Unix
  54. for user programs.  The project is approximately two thirds complete. 
  55. For more information on the GNU project, including the GNU Emacs editor
  56. and the mostly-portable optimizing C compiler, send one dollar to
  57.      Free Software Foundation
  58.      675 Mass Ave
  59.      Cambridge, MA 02139
  60. File: termcap,  Node: Library,  Next: Data Base,  Prev: Introduction,  Up: Top
  61. The Termcap Library
  62. *******************
  63.    The termcap library is the application programmer's interface to the
  64. termcap data base.  It contains functions for the following purposes:
  65.    * Finding the description of the user's terminal type (`tgetent').
  66.    * Interrogating the description for information on various topics
  67.      (`tgetnum', `tgetflag', `tgetstr').
  68.    * Computing and performing padding (`tputs').
  69.    * Encoding numeric parameters such as cursor positions into the
  70.      terminal-specific form required for display commands (`tparam',
  71.      `tgoto').
  72. * Menu:
  73. * Preparation:: Preparing to use the termcap library.
  74. * Find::        Finding the description of the terminal being used.
  75. * Interrogate:: Interrogating the description for particular capabilities.
  76. * Initialize::  Initialization for output using termcap.
  77. * Padding::     Outputting padding.
  78. * Parameters::  Encoding parameters such as cursor positions.
  79. File: termcap,  Node: Preparation,  Next: Find,  Prev: Library,  Up: Library
  80. Preparing to Use the Termcap Library
  81. ====================================
  82.    To use the termcap library in a program, you need two kinds of
  83. preparation:
  84.    * The compiler needs declarations of the functions and variables in
  85.      the library.
  86.      On GNU systems, it suffices to include the header file `termcap.h'
  87.      in each source file that uses these functions and variables.
  88.      On Unix systems, there is often no such header file.  Then you must
  89.      explictly declare the variables as external.  You can do likewise
  90.      for the functions, or let them be implicitly declared and cast
  91.      their values from type `int' to the appropriate type.
  92.      We illustrate the declarations of the individual termcap library
  93.      functions with ANSI C prototypes because they show how to pass the
  94.      arguments.  If you are not using the GNU C compiler, you probably
  95.      cannot use function prototypes, so omit the argument types and
  96.      names from your declarations.
  97.    * The linker needs to search the library.  Usually either
  98.      `-ltermcap' or `-ltermlib' as an argument when linking will do
  99.      this.
  100. File: termcap,  Node: Find,  Next: Interrogate,  Prev: Preparation,  Up: Library
  101. Finding a Terminal Description: `tgetent'
  102. =========================================
  103.    An application program that is going to use termcap must first look
  104. up the description of the terminal type in use.  This is done by calling
  105. `tgetent', whose declaration in ANSI Standard C looks like:
  106.      int tgetent (char *BUFFER, char *TERMTYPE);
  107. This function finds the description and remembers it internally so that
  108. you can interrogate it about specific terminal capabilities (*note
  109. Interrogate::.).
  110.    The argument TERMTYPE is a string which is the name for the type of
  111. terminal to look up.  Usually you would obtain this from the environment
  112. variable `TERM' using `getenv ("TERM")'.
  113.    If you are using the GNU version of termcap, you can alternatively
  114. ask `tgetent' to allocate enough space.  Pass a null pointer for
  115. BUFFER, and `tgetent' itself allocates the storage using `malloc'.  In
  116. this case the returned value on success is the address of the storage,
  117. cast to `int'.  But normally there is no need for you to look at the
  118. address.  Do not free the storage yourself.
  119.    With the Unix version of termcap, you must allocate space for the
  120. description yourself and pass the address of the space as the argument
  121. BUFFER.  There is no way you can tell how much space is needed, so the
  122. convention is to allocate a buffer 2048 characters long and assume that
  123. is enough.  (Formerly the convention was to allocate 1024 characters and
  124. assume that was enough.  But one day, for one kind of terminal, that was
  125. not enough.)
  126.    No matter how the space to store the description has been obtained,
  127. termcap records its address internally for use when you later
  128. interrogate the description with `tgetnum', `tgetstr' or `tgetflag'.  If
  129. the buffer was allocated by termcap, it will be freed by termcap too if
  130. you call `tgetent' again.  If the buffer was provided by you, you must
  131. make sure that its contents remain unchanged for as long as you still
  132. plan to interrogate the description.
  133.    The return value of `tgetent' is -1 if there is some difficulty
  134. accessing the data base of terminal types, 0 if the data base is
  135. accessible but the specified type is not defined in it, and some other
  136. value otherwise.
  137.    Here is how you might use the function `tgetent':
  138.      #ifdef unix
  139.      static char term_buffer[2048];
  140.      #else
  141.      #define term_buffer 0
  142.      #endif
  143.      
  144.      init_terminal_data ()
  145.      {
  146.        char *termtype = getenv ("TERM");
  147.        int success;
  148.      
  149.        if (termtype == 0)
  150.          fatal ("Specify a terminal type with `setenv TERM <yourtype>'.\n");
  151.      
  152.        success = tgetent (term_buffer, termtype);
  153.        if (success < 0)
  154.          fatal ("Could not access the termcap data base.\n");
  155.        if (success == 0)
  156.          fatal ("Terminal type `%s' is not defined.\n", termtype);
  157.      }
  158. Here we assume the function `fatal' prints an error message and exits.
  159.    If the environment variable `TERMCAP' is defined, its value is used
  160. to override the terminal type data base.  The function `tgetent' checks
  161. the value of `TERMCAP' automatically.  If the value starts with `/'
  162. then it is taken as a file name to use as the data base file, instead
  163. of `/etc/termcap' which is the standard data base.  If the value does
  164. not start with `/' then it is itself used as the terminal description,
  165. provided that the terminal type TERMTYPE is among the types it claims
  166. to apply to.  *Note Data Base::, for information on the format of a
  167. terminal description.
  168. File: termcap,  Node: Interrogate,  Next: Initialize,  Prev: Find,  Up: Library
  169. Interrogating the Terminal Description
  170. ======================================
  171.    Each piece of information recorded in a terminal description is
  172. called a "capability".  Each defined terminal capability has a
  173. two-letter code name and a specific meaning.  For example, the number
  174. of columns is named `co'.  *Note Capabilities::, for definitions of all
  175. the standard capability names.
  176.    Once you have found the proper terminal description with `tgetent'
  177. (*note Find::.), your application program must "interrogate" it for
  178. various terminal capabilities.  You must specify the two-letter code of
  179. the capability whose value you seek.
  180.    Capability values can be numeric, boolean (capability is either
  181. present or absent) or strings.  Any particular capability always has
  182. the same value type; for example, `co' always has a numeric value,
  183. while `am' (automatic wrap at margin) is always a flag, and `cm'
  184. (cursor motion command) always has a string value.  The documentation
  185. of each capability says which type of value it has.
  186.    There are three functions to use to get the value of a capability,
  187. depending on the type of value the capability has.  Here are their
  188. declarations in ANSI C:
  189.      int tgetnum (char *NAME);
  190.      int tgetflag (char *NAME);
  191.      char *tgetstr (char *NAME, char **AREA);
  192. `tgetnum'
  193.      Use `tgetnum' to get a capability value that is numeric.  The
  194.      argument NAME is the two-letter code name of the capability.  If
  195.      the capability is present, `tgetnum' returns the numeric value
  196.      (which is nonnegative).  If the capability is not mentioned in the
  197.      terminal description, `tgetnum' returns -1.
  198. `tgetflag'
  199.      Use `tgetflag' to get a boolean value.  If the capability NAME is
  200.      present in the terminal description, `tgetflag' returns 1;
  201.      otherwise, it returns 0.
  202. `tgetstr'
  203.      Use `tgetstr' to get a string value.  It returns a pointer to a
  204.      string which is the capability value, or a null pointer if the
  205.      capability is not present in the terminal description.
  206.      There are two ways `tgetstr' can find space to store the string
  207.      value:
  208.         * You can ask `tgetstr' to allocate the space.  Pass a null
  209.           pointer for the argument AREA, and `tgetstr' will use
  210.           `malloc' to allocate storage big enough for the value.
  211.           Termcap will never free this storage or refer to it again; you
  212.           should free it when you are finished with it.
  213.           This method is more robust, since there is no need to guess
  214.           how much space is needed.  But it is supported only by the GNU
  215.           termcap library.
  216.         * You can provide the space.  Provide for the argument AREA the
  217.           address of a pointer variable of type `char *'.  Before
  218.           calling `tgetstr', initialize the variable to point at
  219.           available space. Then `tgetstr' will store the string value
  220.           in that space and will increment the pointer variable to
  221.           point after the space that has been used.  You can use the
  222.           same pointer variable for many calls to `tgetstr'.
  223.           There is no way to determine how much space is needed for a
  224.           single string, and no way for you to prevent or handle
  225.           overflow of the area you have provided.  However, you can be
  226.           sure that the total size of all the string values you will
  227.           obtain from the terminal description is no greater than the
  228.           size of the description (unless you get the same capability
  229.           twice).  You can determine that size with `strlen' on the
  230.           buffer you provided to `tgetent'.  See below for an example.
  231.           Providing the space yourself is the only method supported by
  232.           the Unix version of termcap.
  233.    Note that you do not have to specify a terminal type or terminal
  234. description for the interrogation functions.  They automatically use the
  235. description found by the most recent call to `tgetent'.
  236.    Here is an example of interrogating a terminal description for
  237. various capabilities, with conditionals to select between the Unix and
  238. GNU methods of providing buffer space.
  239.      char *tgetstr ();
  240.      
  241.      char *cl_string, *cm_string;
  242.      int height;
  243.      int width;
  244.      int auto_wrap;
  245.      
  246.      char PC;   /* For tputs.  */
  247.      char *BC;  /* For tgoto.  */
  248.      char *UP;
  249.      
  250.      interrogate_terminal ()
  251.      {
  252.      #ifdef UNIX
  253.        /* Here we assume that an explicit term_buffer
  254.           was provided to tgetent.  */
  255.        char *buffer
  256.          = (char *) malloc (strlen (term_buffer));
  257.      #define BUFFADDR &buffer
  258.      #else
  259.      #define BUFFADDR 0
  260.      #endif
  261.      
  262.        char *temp;
  263.      
  264.        /* Extract information we will use.  */
  265.        cl_string = tgetstr ("cl", BUFFADDR);
  266.        cm_string = tgetstr ("cm", BUFFADDR);
  267.        auto_wrap = tgetflag ("am");
  268.        height = tgetnum ("li");
  269.        width = tgetnum ("co");
  270.      
  271.        /* Extract information that termcap functions use.  */
  272.        temp = tgetstr ("pc", BUFFADDR);
  273.        PC = temp ? *temp : 0;
  274.        BC = tgetstr ("le", BUFFADDR);
  275.        UP = tgetstr ("up", BUFFADDR);
  276.      }
  277. *Note Padding::, for information on the variable `PC'.  *Note Using
  278. Parameters::, for information on `UP' and `BC'.
  279. File: termcap,  Node: Initialize,  Next: Padding,  Prev: Interrogate,  Up: Library
  280. Initialization for Use of Termcap
  281. =================================
  282.    Before starting to output commands to a terminal using termcap, an
  283. application program should do two things:
  284.    * Initialize various global variables which termcap library output
  285.      functions refer to.  These include `PC' and `ospeed' for padding
  286.      (*note Output Padding::.) and `UP' and `BC' for cursor motion
  287.      (*note tgoto::.).
  288.    * Tell the kernel to turn off alteration and padding of
  289.      horizontal-tab characters sent to the terminal.
  290.    To turn off output processing in Berkeley Unix you would use `ioctl'
  291. with code `TIOCLSET' to set the bit named `LLITOUT', and clear the bits
  292. `ANYDELAY' using `TIOCSETN'.  In POSIX or System V, you must clear the
  293. bit named `OPOST'.  Refer to the system documentation for details.
  294.    If you do not set the terminal flags properly, some older terminals
  295. will not work.  This is because their commands may contain the
  296. characters that normally signify newline, carriage return and
  297. horizontal tab--characters which the kernel thinks it ought to modify
  298. before output.
  299.    When you change the kernel's terminal flags, you must arrange to
  300. restore them to their normal state when your program exits.  This
  301. implies that the program must catch fatal signals such as `SIGQUIT' and
  302. `SIGINT' and restore the old terminal flags before actually terminating.
  303.    Modern terminals' commands do not use these special characters, so
  304. if you do not care about problems with old terminals, you can leave the
  305. kernel's terminal flags unaltered.
  306. File: termcap,  Node: Padding,  Next: Parameters,  Prev: Initialize,  Up: Library
  307. Padding
  308. =======
  309.    "Padding" means outputting null characters following a terminal
  310. display command that takes a long time to execute.  The terminal
  311. description says which commands require padding and how much; the
  312. function `tputs', described below, outputs a terminal command while
  313. extracting from it the padding information, and then outputs the
  314. padding that is necessary.
  315. * Menu:
  316. * Why Pad::          Explanation of padding.
  317. * Describe Padding:: The data base says how much padding a terminal needs.
  318. * Output Padding::   Using `tputs' to output the needed padding.
  319. File: termcap,  Node: Why Pad,  Next: Describe Padding,  Prev: Padding,  Up: Padding
  320. Why Pad, and How
  321. ----------------
  322.    Most types of terminal have commands that take longer to execute
  323. than they do to send over a high-speed line.  For example, clearing the
  324. screen may take 20msec once the entire command is received.  During
  325. that time, on a 9600 bps line, the terminal could receive about 20
  326. additional output characters while still busy clearing the screen. 
  327. Every terminal has a certain amount of buffering capacity to remember
  328. output characters that cannot be processed yet, but too many slow
  329. commands in a row can cause the buffer to fill up.  Then any additional
  330. output that cannot be processed immediately will be lost.
  331.    To avoid this problem, we normally follow each display command with
  332. enough useless charaters (usually null characters) to fill up the time
  333. that the display command needs to execute.  This does the job if the
  334. terminal throws away null characters without using up space in the
  335. buffer (which most terminals do).  If enough padding is used, no output
  336. can ever be lost.  The right amount of padding avoids loss of output
  337. without slowing down operation, since the time used to transmit padding
  338. is time that nothing else could be done.
  339.    The number of padding characters needed for an operation depends on
  340. the line speed.  In fact, it is proportional to the line speed.  A 9600
  341. baud line transmits about one character per msec, so the clear screen
  342. command in the example above would need about 20 characters of padding.
  343.  At 1200 baud, however, only about 3 characters of padding are needed
  344. to fill up 20msec.
  345. File: termcap,  Node: Describe Padding,  Next: Output Padding,  Prev: Why Pad,  Up: Padding
  346. Specifying Padding in a Terminal Description
  347. --------------------------------------------
  348.    In the terminal description, the amount of padding required by each
  349. display command is recorded as a sequence of digits at the front of the
  350. command. These digits specify the padding time in msec.  They can be
  351. followed optionally by a decimal point and one more digit, which is a
  352. number of tenths of msec.
  353.    Sometimes the padding needed by a command depends on the cursor
  354. position. For example, the time taken by an "insert line" command is
  355. usually proportional to the number of lines that need to be moved down
  356. or cleared. An asterisk (`*') following the padding time says that the
  357. time should be multiplied by the number of screen lines affected by the
  358. command.
  359.      :al=1.3*\E[L:
  360. is used to describe the "insert line" command for a certain terminal.
  361. The padding required is 1.3 msec per line affected.  The command itself
  362. is `ESC [ L'.
  363.    The padding time specified in this way tells `tputs' how many pad
  364. characters to output.  *Note Output Padding::.
  365.    Two special capability values affect padding for all commands. 
  366. These are the `pc' and `pb'.  The variable `pc' specifies the character
  367. to pad with, and `pb' the speed below which no padding is needed.  The
  368. defaults for these variables, a null character and 0, are correct for
  369. most terminals.  *Note Pad Specs::.
  370. File: termcap,  Node: Output Padding,  Prev: Describe Padding,  Up: Padding
  371. Performing Padding with `tputs'
  372. -------------------------------
  373.    Use the termcap function `tputs' to output a string containing an
  374. optional padding spec of the form described above (*note Describe
  375. Padding::.).  The function `tputs' strips off and decodes the padding
  376. spec, outputs the rest of the string, and then outputs the appropriate
  377. padding.  Here is its declaration in ANSI C:
  378.      char PC;
  379.      short ospeed;
  380.      
  381.      int tputs (char *STRING, int NLINES, int (*OUTFUN) ());
  382.    Here STRING is the string (including padding spec) to be output;
  383. NLINES is the number of lines affected by the operation, which is used
  384. to multiply the amount of padding if the padding spec ends with a `*'. 
  385. Finally, OUTFUN is a function (such as `fputchar') that is called to
  386. output each character.  When actually called, OUTFUN should expect one
  387. argument, a character.
  388.    The operation of `tputs' is controlled by two global variables,
  389. `ospeed' and `PC'.  The value of `ospeed' is supposed to be the
  390. terminal output speed, encoded as in the `ioctl' system call which gets
  391. the speed information.  This is needed to compute the number of padding
  392. characters.  The value of `PC' is the character used for padding.
  393.    You are responsible for storing suitable values into these variables
  394. before using `tputs'.  The value stored into the `PC' variable should be
  395. taken from the `pc' capability in the terminal description (*note Pad
  396. Specs::.).  Store zero in `PC' if there is no `pc' capability.
  397.    The argument NLINES requires some thought.  Normally, it should be
  398. the number of lines whose contents will be cleared or moved by the
  399. command. For cursor motion commands, or commands that do editing within
  400. one line, use the value 1.  For most commands that affect multiple
  401. lines, such as `al' (insert a line) and `cd' (clear from the cursor to
  402. the end of the screen), NLINES should be the screen height minus the
  403. current vertical position (origin 0).  For multiple insert and scroll
  404. commands such as `AL' (insert multiple lines), that same value for
  405. NLINES is correct; the number of lines being inserted is not correct.
  406.    If a "scroll window" feature is used to reduce the number of lines
  407. affected by a command, the value of NLINES should take this into
  408. account.  This is because the delay time required depends on how much
  409. work the terminal has to do, and the scroll window feature reduces the
  410. work. *Note Scrolling::.
  411.    Commands such as `ic' and `dc' (insert or delete characters) are
  412. problematical because the padding needed by these commands is
  413. proportional to the number of characters affected, which is the number
  414. of columns from the cursor to the end of the line.  It would be nice to
  415. have a way to specify such a dependence, and there is no need for
  416. dependence on vertical position in these commands, so it is an obvious
  417. idea to say that for these commands NLINES should really be the number
  418. of columns affected. However, the definition of termcap clearly says
  419. that NLINES is always the number of lines affected, even in this case,
  420. where it is always 1.  It is not easy to change this rule now, because
  421. too many programs and terminal descriptions have been written to follow
  422.    Because NLINES is always 1 for the `ic' and `dc' strings, there is
  423. no reason for them to use `*', but some of them do.  These should be
  424. corrected by deleting the `*'.  If, some day, such entries have
  425. disappeared, it may be possible to change to a more useful convention
  426. for the NLINES argument for these operations without breaking any
  427. programs.
  428. File: termcap,  Node: Parameters,  Prev: Padding,  Up: Library
  429. Filling In Parameters
  430. =====================
  431.    Some terminal control strings require numeric "parameters".  For
  432. example, when you move the cursor, you need to say what horizontal and
  433. vertical positions to move it to.  The value of the terminal's `cm'
  434. capability, which says how to move the cursor, cannot simply be a
  435. string of characters; it must say how to express the cursor position
  436. numbers and where to put them within the command.
  437.    The specifications of termcap include conventions as to which
  438. string-valued capabilities require parameters, how many parameters, and
  439. what the parameters mean; for example, it defines the `cm' string to
  440. take two parameters, the vertical and horizontal positions, with 0,0
  441. being the upper left corner.  These conventions are described where the
  442. individual commands are documented.
  443.    Termcap also defines a language used within the capability
  444. definition for specifying how and where to encode the parameters for
  445. output.  This language uses character sequences starting with `%'. 
  446. (This is the same idea as `printf', but the details are different.) 
  447. The language for parameter encoding is described in this section.
  448.    A program that is doing display output calls the functions `tparam'
  449. or `tgoto' to encode parameters according to the specifications.  These
  450. functions produce a string containing the actual commands to be output
  451. (as well a padding spec which must be processed with `tputs'; *note
  452. Padding::.).
  453. * Menu:
  454. * Encode Parameters:: The language for encoding parameters.
  455. * Using Parameters::  Outputting a string command with parameters.
  456. File: termcap,  Node: Encode Parameters,  Next: Using Parameters,  Prev: Parameters,  Up: Parameters
  457. Describing the Encoding
  458. -----------------------
  459.    A terminal command string that requires parameters contains special
  460. character sequences starting with `%' to say how to encode the
  461. parameters.  These sequences control the actions of `tparam' and
  462. `tgoto'.
  463.    The parameters values passed to `tparam' or `tgoto' are considered
  464. to form a vector.  A pointer into this vector determines the next
  465. parameter to be processed.  Some of the `%'-sequences encode one
  466. parameter and advance the pointer to the next parameter. Other
  467. `%'-sequences alter the pointer or alter the parameter values without
  468. generating output.
  469.    For example, the `cm' string for a standard ANSI terminal is written
  470. as `\E[%i%d;%dH'.  (`\E' stands for ESC.)  `cm' by convention always
  471. requires two parameters, the vertical and horizontal goal positions, so
  472. this string specifies the encoding of two parameters.  Here `%i'
  473. increments the two values supplied, and each `%d' encodes one of the
  474. values in decimal.  If the cursor position values 20,58 are encoded
  475. with this string, the result is `\E[21;59H'.
  476.    First, here are the `%'-sequences that generate output.  Except for
  477. `%%', each of them encodes one parameter and advances the pointer to
  478. the following parameter.
  479.      Output a single `%'.  This is the only way to represent a literal
  480.      `%' in a terminal command with parameters.  `%%' does not use up a
  481.      parameter.
  482.      As in `printf', output the next parameter in decimal.
  483.      Like `%02d' in `printf': output the next parameter in decimal, and
  484.      always use at least two digits.
  485.      Like `%03d' in `printf': output the next parameter in decimal, and
  486.      always use at least three digits.  Note that `%4' and so on are
  487.      *not* defined.
  488.      Output the next parameter as a single character whose ASCII code is
  489.      the parameter value.  Like `%c' in `printf'.
  490. `%+CHAR'
  491.      Add the next parameter to the character CHAR, and output the
  492.      resulting character.  For example, `%+ ' represents 0 as a space,
  493.      1 as `!', etc.
  494.    The following `%'-sequences specify alteration of the parameters
  495. (their values, or their order) rather than encoding a parameter for
  496. output. They generate no output; they are used only for their side
  497. effects on the parameters.  Also, they do not advance the "next
  498. parameter" pointer except as explicitly stated.  Only `%i', `%r' and
  499. `%>' are defined in standard Unix termcap.  The others are GNU
  500. extensions.
  501.      Increment the next two parameters.  This is used for terminals that
  502.      expect cursor positions in origin 1.  For example, `%i%d,%d' would
  503.      output two parameters with `1' for 0, `2' for 1, etc.
  504.      Interchange the next two parameters.  This is used for terminals
  505.      whose cursor positioning command expects the horizontal position
  506.      first.
  507.      Skip the next parameter.  Do not output anything.
  508.      Back up one parameter.  The last parameter used will become once
  509.      again the next parameter to be output, and the next output command
  510.      will use it.  Using `%b' more than once, you can back up any
  511.      number of parameters, and you can refer to each parameter any
  512.      number of times.
  513. `%>C1C2'
  514.      Conditionally increment the next parameter.  Here C1 and C2 are
  515.      characters which stand for their ASCII codes as numbers. If the
  516.      next parameter is greater than the ASCII code of C1, the ASCII
  517.      code of C2 is added to it.
  518. `%a OP TYPE POS'
  519.      Perform arithmetic on the next parameter, do not use it up, and do
  520.      not output anything.  Here OP specifies the arithmetic operation,
  521.      while TYPE and POS together specify the other operand.
  522.      Spaces are used above to separate the operands for clarity; the
  523.      spaces don't appear in the data base, where this sequence is
  524.      exactly five characters long.
  525.      The character OP says what kind of arithmetic operation to
  526.      perform.  It can be any of these characters:
  527.     `='
  528.           assign a value to the next parameter, ignoring its old value.
  529.           The new value comes from the other operand.
  530.     `+'
  531.           add the other operand to the next parameter.
  532.     `-'
  533.           subtract the other operand from the next parameter.
  534.     `*'
  535.           multiply the next parameter by the other operand.
  536.     `/'
  537.           divide the next parameter by the other operand.
  538.      The "other operand" may be another parameter's value or a constant;
  539.      the character TYPE says which.  It can be:
  540.     `p'
  541.           Use another parameter.  The character POS says which
  542.           parameter to use.  Subtract 64 from its ASCII code to get the
  543.           position of the desired parameter relative to this one.  Thus,
  544.           the character `A' as POS means the parameter after the next
  545.           one; the character `?' means the parameter before the next
  546.           one.
  547.     `c'
  548.           Use a constant value.  The character POS specifies the value
  549.           of the constant.  The 0200 bit is cleared out, so that 0200
  550.           can be used to represent zero.
  551.    The following `%'-sequences are special purpose hacks to compensate
  552. for the weird designs of obscure terminals.  They modify the next
  553. parameter or the next two parameters but do not generate output and do
  554. not use up any parameters.  `%m' is a GNU extension; the others are
  555. defined in standard Unix termcap.
  556.      Exclusive-or the next parameter with 0140, and likewise the
  557.      parameter after next.
  558.      Complement all the bits of the next parameter and the parameter
  559.      after next.
  560.      Encode the next parameter in BCD.  It alters the value of the
  561.      parameter by adding six times the quotient of the parameter by ten.
  562.      Here is a C statement that shows how the new value is computed:
  563.           PARM = (PARM / 10) * 16 + PARM % 10;
  564.      Transform the next parameter as needed by Delta Data terminals.
  565.      This involves subtracting twice the remainder of the parameter by
  566.      16.
  567.           PARM -= 2 * (PARM % 16);
  568. File: termcap,  Node: Using Parameters,  Prev: Encode Parameters,  Up: Parameters
  569. Sending Display Commands with Parameters
  570. ----------------------------------------
  571.    The termcap library functions `tparam' and `tgoto' serve as the
  572. analog of `printf' for terminal string parameters.  The newer function
  573. `tparam' is a GNU extension, more general but missing from Unix
  574. termcap.  The original parameter-encoding function is `tgoto', which is
  575. preferable for cursor motion.
  576. * Menu:
  577. * tparam::   The general case, for GNU termcap only.
  578. * tgoto::    The special case of cursor motion.
  579. File: termcap,  Node: tparam,  Next: tgoto,  Prev: Using Parameters,  Up: Using Parameters
  580. `tparam'
  581. ........
  582.    The function `tparam' can encode display commands with any number of
  583. parameters and allows you to specify the buffer space.  It is the
  584. preferred function for encoding parameters for all but the `cm'
  585. capability.  Its ANSI C declaration is as follows:
  586.      char *tparam (char *CTLSTRING, char *BUFFER, int SIZE, int PARM1,...)
  587.    The arguments are a control string CTLSTRING (the value of a terminal
  588. capability, presumably), an output buffer BUFFER and SIZE, and any
  589. number of integer parameters to be encoded.  The effect of `tparam' is
  590. to copy the control string into the buffer, encoding parameters
  591. according to the `%' sequences in the control string.
  592.    You describe the output buffer by its address, BUFFER, and its size
  593. in bytes, SIZE.  If the buffer is not big enough for the data to be
  594. stored in it, `tparam' calls `malloc' to get a larger buffer.  In
  595. either case, `tparam' returns the address of the buffer it ultimately
  596. uses.  If the value equals BUFFER, your original buffer was used.
  597. Otherwise, a new buffer was allocated, and you must free it after you
  598. are done with printing the results.  If you pass zero for SIZE and
  599. BUFFER, `tparam' always allocates the space with `malloc'.
  600.    All capabilities that require parameters also have the ability to
  601. specify padding, so you should use `tputs' to output the string
  602. produced by `tparam'.  *Note Padding::.  Here is an example.
  603.      {
  604.        char *buf;
  605.        char buffer[40];
  606.      
  607.        buf = tparam (command, buffer, 40, parm);
  608.        tputs (buf, 1, fputchar);
  609.        if (buf != buffer)
  610.          free (buf);
  611.      }
  612.    If a parameter whose value is zero is encoded with `%.'-style
  613. encoding, the result is a null character, which will confuse `tputs'.
  614. This would be a serious problem, but luckily `%.' encoding is used only
  615. by a few old models of terminal, and only for the `cm' capability.  To
  616. solve the problem, use `tgoto' rather than `tparam' to encode the `cm'
  617. capability.
  618. File: termcap,  Node: tgoto,  Prev: tparam,  Up: Using Parameters
  619. `tgoto'
  620. .......
  621.    The special case of cursor motion is handled by `tgoto'.  There are
  622. two reasons why you might choose to use `tgoto':
  623.    * For Unix compatibility, because Unix termcap does not have
  624.      `tparam'.
  625.    * For the `cm' capability, since `tgoto' has a special feature to
  626.      avoid problems with null characters, tabs and newlines on certain
  627.      old terminal types that use `%.' encoding for that capability.
  628.    Here is how `tgoto' might be declared in ANSI C:
  629.      char *tgoto (char *CSTRING, int HPOS, int VPOS)
  630.    There are three arguments, the terminal description's `cm' string and
  631. the two cursor position numbers; `tgoto' computes the parametrized
  632. string in an internal static buffer and returns the address of that
  633. buffer. The next time you use `tgoto' the same buffer will be reused.
  634.    Parameters encoded with `%.' encoding can generate null characters,
  635. tabs or newlines.  These might cause trouble: the null character because
  636. `tputs' would think that was the end of the string, the tab because the
  637. kernel or other software might expand it into spaces, and the newline
  638. becaue the kernel might add a carriage-return, or padding characters
  639. normally used for a newline.  To prevent such problems, `tgoto' is
  640. careful to avoid these characters.  Here is how this works: if the
  641. target cursor position value is such as to cause a problem (that is to
  642. say, zero, nine or ten), `tgoto' increments it by one, then compensates
  643. by appending a string to move the cursor back or up one position.
  644.    The compensation strings to use for moving back or up are found in
  645. global variables named `BC' and `UP'.  These are actual external C
  646. variables with upper case names; they are declared `char *'.  It is up
  647. to you to store suitable values in them, normally obtained from the
  648. `le' and `up' terminal capabilities in the terminal description with
  649. `tgetstr'.  Alternatively, if these two variables are both zero, the
  650. feature of avoiding nulls, tabs and newlines is turned off.
  651.    It is safe to use `tgoto' for commands other than `cm' only if you
  652. have stored zero in `BC' and `UP'.
  653.    Note that `tgoto' reverses the order of its operands: the horizontal
  654. position comes before the vertical position in the arguments to
  655. `tgoto', even though the vertical position comes before the horizontal
  656. in the parameters of the `cm' string.  If you use `tgoto' with a
  657. command such as `AL' that takes one parameter, you must pass the
  658. parameter to `tgoto' as the "vertical position".
  659. File: termcap,  Node: Data Base,  Next: Capabilities,  Prev: Library,  Up: Top
  660. The Format of the Data Base
  661. ***************************
  662.    The termcap data base of terminal descriptions is stored in the file
  663. `/etc/termcap'.  It contains terminal descriptions, blank lines, and
  664. comments.
  665.    A terminal description starts with one or more names for the
  666. terminal type. The information in the description is a series of
  667. "capability names" and values.  The capability names have standard
  668. meanings (*note Capabilities::.) and their values describe the terminal.
  669. * Menu:
  670. * Format::            Overall format of a terminal description.
  671. * Capability Format:: Format of capabilities within a description.
  672. * Naming::            Naming conventions for terminal types.
  673. * Inheriting::        Inheriting part of a description from
  674.                         a related terminal type.
  675. File: termcap,  Node: Format,  Next: Capability Format,  Prev: Data Base,  Up: Data Base
  676. Terminal Description Format
  677. ===========================
  678.    Aside from comments (lines starting with `#', which are ignored),
  679. each nonblank line in the termcap data base is a terminal description.
  680. A terminal description is nominally a single line, but it can be split
  681. into multiple lines by inserting the two characters `\ newline'. This
  682. sequence is ignored wherever it appears in a description.
  683.    The preferred way to split the description is between capabilities:
  684. insert the four characters `: \ newline tab' immediately before any
  685. colon. This allows each sub-line to start with some indentation.  This
  686. works because, after the `\ newline' are ignored, the result is `: tab
  687. :'; the first colon ends the preceding capability and the second colon
  688. starts the next capability.  If you split with `\ newline' alone, you
  689. may not add any indentation after them.
  690.    Here is a real example of a terminal description:
  691.      dw|vt52|DEC vt52:\
  692.              :cr=^M:do=^J:nl=^J:bl=^G:\
  693.              :le=^H:bs:cd=\EJ:ce=\EK:cl=\EH\EJ:cm=\EY%+ %+ :co#80:li#24:\
  694.              :nd=\EC:ta=^I:pt:sr=\EI:up=\EA:\
  695.              :ku=\EA:kd=\EB:kr=\EC:kl=\ED:kb=^H:
  696.    Each terminal description begins with several names for the terminal
  697. type. The names are separated by `|' characters, and a colon ends the
  698. last name.  The first name should be two characters long; it exists
  699. only for the sake of very old Unix systems and is never used in modern
  700. systems.  The last name should be a fully verbose name such as "DEC
  701. vt52" or "Ann Arbor Ambassador with 48 lines".  The other names should
  702. include whatever the user ought to be able to specify to get this
  703. terminal type, such as `vt52' or `aaa-48'.  *Note Naming::, for
  704. information on how to choose terminal type names.
  705.    After the terminal type names come the terminal capabilities,
  706. separated by colons and with a colon after the last one.  Each
  707. capability has a two-letter name, such as `cm' for "cursor motion
  708. string" or `li' for "number of display lines".
  709. File: termcap,  Node: Capability Format,  Next: Naming,  Prev: Format,  Up: Data Base
  710. Writing the Capabilities
  711. ========================
  712.    There are three kinds of capabilities: flags, numbers, and strings. 
  713. Each kind has its own way of being written in the description.  Each
  714. defined capability has by convention a particular kind of value; for
  715. example, `li' always has a numeric value and `cm' always a string value.
  716.    A flag capability is thought of as having a boolean value: the value
  717. is true if the capability is present, false if not.  When the
  718. capability is present, just write its name between two colons.
  719.    A numeric capability has a value which is a nonnegative number. 
  720. Write the capability name, a `#', and the number, between two colons. 
  721. For example, `...:li#48:...' is how you specify the `li' capability for
  722. 48 lines.
  723.    A string-valued capability has a value which is a sequence of
  724. characters. Usually these are the characters used to perform some
  725. display operation. Write the capability name, a `=', and the characters
  726. of the value, between two colons.  For example,
  727. `...:cm=\E[%i%d;%dH:...' is how the cursor motion command for a
  728. standard ANSI terminal would be specified.
  729.    Special characters in the string value can be expressed using
  730. `\'-escape sequences as in C; in addition, `\E' stands for ESC.  `^' is
  731. also a kind of escape character; `^' followed by CHAR stands for the
  732. control-equivalent of CHAR.  Thus, `^a' stands for the character
  733. control-a, just like `\001'. `\' and `^' themselves can be represented
  734. as `\\' and `\^'.
  735.    To include a colon in the string, you must write `\072'.  You might
  736. ask, "Why can't `\:' be used to represent a colon?"  The reason is that
  737. the interrogation functions do not count slashes while looking for a
  738. capability.  Even if `:ce=ab\:cd:' were interpreted as giving the `ce'
  739. capability the value `ab:cd', it would also appear to define `cd' as a
  740. flag.
  741.    The string value will often contain digits at the front to specify
  742. padding (*note Padding::.) and/or `%'-sequences within to specify how
  743. to encode parameters (*note Parameters::.).  Although these things are
  744. not to be output literally to the terminal, they are considered part of
  745. the value of the capability.  They are special only when the string
  746. value is processed by `tputs', `tparam' or `tgoto'.  By contrast, `\'
  747. and `^' are considered part of the syntax for specifying the characters
  748. in the string.
  749.    Let's look at the VT52 example again:
  750.      dw|vt52|DEC vt52:\
  751.              :cr=^M:do=^J:nl=^J:bl=^G:\
  752.              :le=^H:bs:cd=\EJ:ce=\EK:cl=\EH\EJ:cm=\EY%+ %+ :co#80:li#24:\
  753.              :nd=\EC:ta=^I:pt:sr=\EI:up=\EA:\
  754.              :ku=\EA:kd=\EB:kr=\EC:kl=\ED:kb=^H:
  755.    Here we see the numeric-valued capabilities `co' and `li', the flags
  756. `bs' and `pt', and many string-valued capabilities.  Most of the
  757. strings start with ESC represented as `\E'.  The rest contain control
  758. characters represented using `^'.  The meanings of the individual
  759. capabilities are defined elsewhere (*note Capabilities::.).
  760. File: termcap,  Node: Naming,  Next: Inheriting,  Prev: Capability Format,  Up: Data Base
  761. Terminal Type Name Conventions
  762. ==============================
  763.    There are conventions for choosing names of terminal types.  For one
  764. thing, all letters should be in lower case.  The terminal type for a
  765. terminal in its most usual or most fundamental mode of operation should
  766. not have a hyphen in it.
  767.    If the same terminal has other modes of operation which require
  768. different terminal descriptions, these variant descriptions are given
  769. names made by adding suffixes with hyphens.  Such alternate descriptions
  770. are used for two reasons:
  771.    * When the terminal has a switch that changes its behavior.  Since
  772.      the computer cannot tell how the switch is set, the user must tell
  773.      the computer by choosing the appropriate terminal type name.
  774.      For example, the VT-100 has a setup flag that controls whether the
  775.      cursor wraps at the right margin.  If this flag is set to "wrap",
  776.      you must use the terminal type `vt100-am'.  Otherwise you must use
  777.      `vt100-nam'.  Plain `vt100' is defined as a synonym for either
  778.      `vt100-am' or `vt100-nam' depending on the preferences of the
  779.      local site.
  780.      The standard suffix `-am' stands for "automatic margins".
  781.    * To give the user a choice in how to use the terminal.  This is done
  782.      when the terminal has a switch that the computer normally controls.
  783.      For example, the Ann Arbor Ambassador can be configured with many
  784.      screen sizes ranging from 20 to 60 lines.  Fewer lines make bigger
  785.      characters but more lines let you see more of what you are editing.
  786.      As a result, users have different preferences.  Therefore, termcap
  787.      provides terminal types for many screen sizes.  If you choose type
  788.      `aaa-30', the terminal will be configured to use 30 lines; if you
  789.      choose `aaa-48', 48 lines will be used, and so on.
  790.    Here is a list of standard suffixes and their conventional meanings:
  791.      Short for "wide".  This is a mode that gives the terminal more
  792.      columns than usual.  This is normally a user option.
  793. `-am'
  794.      "Automatic margins".  This is an alternate description for use when
  795.      the terminal's margin-wrap switch is on; it contains the `am'
  796.      flag.  The implication is that normally the switch is off and the
  797.      usual description for the terminal says that the switch is off.
  798. `-nam'
  799.      "No automatic margins".  The opposite of `-am', this names an
  800.      alternative description which lacks the `am' flag.  This implies
  801.      that the terminal is normally operated with the margin-wrap switch
  802.      turned on, and the normal description of the terminal says so.
  803. `-na'
  804.      "No arrows".  This terminal description initializes the terminal to
  805.      keep its arrow keys in local mode.  This is a user option.
  806. `-rv'
  807.      "Reverse video".  This terminal description causes text output for
  808.      normal video to appear as reverse, and text output for reverse
  809.      video to come out as normal.  Often this description differs from
  810.      the usual one by interchanging the two strings which turn reverse
  811.      video on and off.
  812.      This is a user option; you can choose either the "reverse video"
  813.      variant terminal type or the normal terminal type, and termcap will
  814.      obey.
  815.      "Status".  Says to enable use of a status line which ordinary
  816.      output does not touch (*note Status Line::.).
  817.      Some terminals have a special line that is used only as a status
  818.      line. For these terminals, there is no need for an `-s' variant;
  819.      the status line commands should be defined by default.  On other
  820.      terminals, enabling a status line means removing one screen line
  821.      from ordinary use and reducing the effective screen height.  For
  822.      these terminals, the user can choose the `-s' variant type to
  823.      request use of a status line.
  824. `-NLINES'
  825.      Says to operate with NLINES lines on the screen, for terminals
  826.      such as the Ambassador which provide this as an option.  Normally
  827.      this is a user option; by choosing the terminal type, you control
  828.      how many lines termcap will use.
  829. `-NPAGESp'
  830.      Says that the terminal has NPAGES pages worth of screen memory,
  831.      for terminals where this is a hardware option.
  832. `-unk'
  833.      Says that description is not for direct use, but only for
  834.      reference in `tc' capabilities.  Such a description is a kind of
  835.      subroutine, because it describes the common characteristics of
  836.      several variant descriptions that would use other suffixes in
  837.      place of `-unk'.
  838. File: termcap,  Node: Inheriting,  Prev: Naming,  Up: Data Base
  839. Inheriting from Related Descriptions
  840. ====================================
  841.    When two terminal descriptions are similar, their identical parts do
  842. not need to be given twice.  Instead, one of the two can be defined in
  843. terms of the other, using the `tc' capability.  We say that one
  844. description "refers to" the other, or "inherits from" the other.
  845.    The `tc' capability must be the last one in the terminal description,
  846. and its value is a string which is the name of another terminal type
  847. which is referred to.  For example,
  848.      N9|aaa|ambassador|aaa-30|ann arbor ambassador/30 lines:\
  849.              :ti=\E[2J\E[30;0;0;30p:\
  850.              :te=\E[60;0;0;30p\E[30;1H\E[J:\
  851.              :li#30:tc=aaa-unk:
  852. defines the terminal type `aaa-30' (also known as plain `aaa') in terms
  853. of `aaa-unk', which defines everything about the Ambassador that is
  854. independent of screen height.  The types `aaa-36', `aaa-48' and so on
  855. for other screen heights are likewise defined to inherit from `aaa-unk'.
  856.    The capabilities overridden by `aaa-30' include `li', which says how
  857. many lines there are, and `ti' and `te', which configure the terminal
  858. to use that many lines.
  859.    The effective terminal description for type `aaa' consists of the
  860. text shown above followed by the text of the description of `aaa-unk'. 
  861. The `tc' capability is handled automatically by `tgetent', which finds
  862. the description thus referenced and combines the two descriptions
  863. (*note Find::.).  Therefore, only the implementor of the terminal
  864. descriptions needs to think about using `tc'.  Users and application
  865. programmers do not need to be concerned with it.
  866.    Since the reference terminal description is used last, capabilities
  867. specified in the referring description override any specifications of
  868. the same capabilities in the reference description.
  869.    The referring description can cancel out a capability without
  870. specifying any new value for it by means of a special trick.  Write the
  871. capability in the referring description, with the character `@' after
  872. the capability name, as follows:
  873.      NZ|aaa-30-nam|ann arbor ambassador/30 lines/no automatic-margins:\
  874.              :am@:tc=aaa-30:
  875.