home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / gnu / termcap-1.2-bin.lha / info / termcap.info-1 (.txt) < prev    next >
GNU Info File  |  1994-02-24  |  48KB  |  853 lines

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