home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / trmcap11.zip / termcap-1.1 / termcap.info-1 (.txt) < prev    next >
GNU Info File  |  1992-04-11  |  49KB  |  861 lines

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