home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / termcap-1.3-bin.lha / info / termcap.info-1 (.txt) < prev    next >
GNU Info File  |  1996-10-12  |  47KB  |  852 lines

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