COHERENT manpages

This page displays the COHERENT manpage for termcap [Terminal-description language].

List of available manpages
Index


termcap -- System Administration

Terminal-description language
/etc/termcap

termcap  is a  language for  describing  terminals and  their capabilities.
Terminal descriptions  are collected in the file  /etc/termcap and are read
by tgetent and  its related programs to ensure that  output to a particular
terminal is in a format that that terminal can understand.

COHERENT also  supports the  terminal-description language terminfo.  For a
description  of  how these  languages  differ, see  the  Lexicon entry  for
terminfo.

Overview

A terminal  description written in termcap consists of  a series of fields,
which  are separated  from each  other by  colons `:'.   Every line  in the
description, with the  exception of the last line, must  end in a backslash
`\'.   Tab  characters  are ignored.   Lines  that  begin  with  a `#'  are
comments.  A termcap description must not exceed 1,024 characters.

The first  field names the terminal.  Several different  names may be used,
each separated  by a vertical  bar `|'; each  name given, however,  must be
unique within the file  /etc/termcap.  By convention, the first listed must
be two characters long.  The second  name is the name by which the terminal
is  most commonly  known; this  name may  contain no  blanks in  it.  Other
versions of  the name may follow.   By convention, the last  version is the
full name of the terminal; here, spaces may be used for legibility.  Any of
these  may be  used to  name  your terminal  to the  COHERENT system.   For
example, the name field for the VT-100 terminal is as follows:

    d1|vt100|vt-100|pt100|pt-100|dec vt100:\

Note that the names are separated by vertical bars `|', that the field ends
with a colon, and that the  line ends with a backslash.  Using any of these
names  in an  export command  will  make  the correct  terminal description
available to programs that need to use it.

The  remaining  fields  in  the  entry  describe the  capabilities  of  the
terminal.  Each  capability field  consists of  a two-letter code,  and may
include additional information.  There are three types of capability:

Boolean
     This indicates  whether or not a terminal has  a specific feature.  If
     the field is present, the terminal  is assumed to have the feature; if
     it is absend,  the terminal is assumed not to  have that feature.  For
     example, the field

         am:

     is present,  termcap assumes that the  terminal has automatic margins,
     whereas  if  that field  is  not present,  the  program using  termcap
     assumes that the terminal does not have them.

Numeric
     This  gives  the  size  of  some  aspect  of  the  terminal.   Numeric
     capability fields  have the capability  code, followed by a  `#' and a
     number.  For example, the entry

         co#80:

     means that the terminal screen is 80 columns wide.

String capabilities
     These give a sequence of characters that trigger a terminal operation.
     These fields  consist of the  capability code, an equal  sign `=', and
     the string.

     Strings  often  include  escape  sequences.   A  ``\E''  indicates  an
     <ESC> character;  a control character is  indicated with a carat
     `^' plus the appropriate letter; and the sequences \b, \f, \n, \r, and
     \t  are, respectively,  backspace, formfeed,  newline, <return>,
     and tab.

     An integer or an integer followed  by an asterisk in the string (e.g.,
     `int*') indicates that execution  of the function should be delayed by
     int  milliseconds; this  delay is termed  padding.  Thus,  deletion on
     lines on the Microterm Mime-2A is coded as:

         dl=20*^W:

     dl is  the capability code  for delete, the equal  sign introduces the
     deletion  sequence, 20*  indicates that each  line deletion  should be
     delayed by  20 milliseconds, and  ^W indicates that  the line-deletion
     code on the Mime-2A is <ctrl-W>.

     The asterisk  indicates that the  padding required is  proportional to
     the number of lines affected  by the operation.  In the above example,
     the deletion  of four  lines on  the Mime-2A generates  a total  of 80
     milliseconds  of padding;  if no asterisk  were present,  however, the
     padding would  be only 20 milliseconds, no matter  how many lines were
     deleted.  Also, when  an asterisk is used, the number  may be given to
     one decimal place, to show tenths of a millisecond of padding.

     Note  that with  string  capabilities, characters  may be  given as  a
     backslash followed by the  three octal digits of the character's ASCII
     code.  Thus, a  colon in a capability field may  be given by \072.  To
     put a null character into the string, use \200, because termcap strips
     the high bit from each character.

     Finally, the  literal characters `^'  and `\' are given  by ``\^'' and
     ``\\''.

Capability Codes

The  following  table lists  termcap's  capability  codes.  Type  indicates
whether the  code is  boolean, numeric, or  string; a dagger  `+' indicates
that this  capability may  include padding, and  a dagger plus  an asterisk
``+*'' indicates  that it  may be used  with the asterisk  padding function
described above.

Variable  Type      Definition
ae........string+...End alternate set of characters
al........string+*..Add blank line
am........boolean...Automatic margins
as........string+...Start alternate set of characters
bc........string....Backspace character, if not <ctrl-H>
bs........boolean...Backspace character is <ctrl-H>
bt........string+...Backtab
bw........boolean...Backspace wraps from column 0 to last column
CC........string....Command character in prototype if it can be set at terminal
cd........string+*..Clear to end of display
ce........string+...Clear line
ch........string+...Horizontal cursor motion
cl........string+*..Clear screen
cm........string+...Cursor motion, both vertical and horizontal
co........number....Number of columns
cr........string+*..<return>; default <ctrl-M>
cs........string+...Change scrolling region (DEC VT100 only); resembles cm
cv........string+...Vertical cursor motion
da........boolean+..Display above may be retained
dB........number....Milliseconds of delay needed by bs
db........boolean...Display below may be retained
dC........number....Milliseconds of delay needed by cr
dc........string+*..Delete a character
dF........number....Milliseconds of delay needed by ff
dl........string+*..Delete a line
dm........string....Enter delete mode
dN........number....Milliseconds of delay needed by nl
do........string....Move down one line
dT........number....Milliseconds of delay needed by tab
ed........string....Leave delete mode
ei........string....Leave insert mode; use :ei=: if this string is the same as ic
eo........string....Erase overstrikes with a blank
ff........string+*..Eject hardcopy terminal page; default <ctrl-L>
hc........boolean...Hardcopy terminal
hd........string....Move half-line down, i.e., forward 1/2 line feed)
ho........string....Move cursor to home position; use if cm is not set
hu........string....Move half-line up, i.e., reverse 1/2 line feed
hz........string....Cannot print tilde `~' (Hazeltine terminals only)
ic........string+...Insert a character
if........string....Name of the file that contains is
im........string....Begin insert mode; use :im=: if ic has not been set
in........boolean...Nulls are distinguished in display
ip........string+*..Insert padding after each character listed
is........string....Initialize terminal
k0-k9.....string....Codes sent by function keys 1 through 10 (k0 = F10)
kb........string....Code sent by backspace key
kd........string....Code sent by down-arrow key
ke........string....Leave ``keypad transmit'' mode
kh........string....Code sent by home key
kl........string....Code sent by left-arrow key
kn........number....No. of function keys; default is 10
ko........string....Entries for for all other non-function keys
kr........string....Code sent by right-arrow key
ks........string....Begin ``keypad transmit'' mode
ku........string....Code sent by up-arrow key
l0-l9.....string....Function keys labels if not f0-f9
li........number....Number of lines
ll........string....Move cursor to first column of last line (cm not set)
ma........string....Map keypad-to-cursor movement for vi version 2
mi........boolean...Cursor may be safely moved while in insert mode
ml........string....Turn on memory lock for area of screen above cursor
ms........boolean...Cursor can be moved while in standout or underline mode
mu........string....Turn off memory lock
nc........boolean...<return> does not work
nd........string....Move cursor right non-destructively
nl........string+*..Newline character; default is \n (Obsolete)
ns........boolean...Terminal is CRT, but does not scroll
os........boolean...Terminal can overstrike
pc........string....Pad character any character other than null
PS........string....Print start: redirect input to auxiliary port
PN........string....Print end: stop redirecting input to auxiliary port
pt........boolean...Terminal's tabs set by hardware; may need to be set with is
se........string....Exit standout mode
sf........string+...Scroll forward
sg........number....Blank characters left by so or se
so........string....Enter standout mode
sr........string+...Reverse scroll
ta........string+...Tab character other than <ctrl-I>, or with padding
tc........string....Similar terminal -- must be last field in entry
te........string....End a program that uses cm
ti........string....Begin a program that uses cm
uc........string....Underscore character and skip it
ue........string....Leave underscore mode
ug........number....Blank characters left by us or ue
ul........boolean...Terminal underlines but does not overstrike
up........string....Move up one line
us........string....Begin underscore mode
vb........string....Visible bell; may not move cursor
ve........string....Exit open/visual mode
vs........string....Begin open/visual mode
xb........boolean...Beehive terminal (f1=<esc>, f2=<crtl-C>)
xn........boolean...Newline is ignored after wrap
xr........boolean...<return> behaves like ce \r \n
xs........boolean...Standout mode is not erased by writing over it
xt........boolean...Tabs are destructive

Examples

The following  is the  termcap description  for the IBM  Personal Computer,
also  known as  ansipc.  This is  the  default description  used with  your
COHERENT system console:

ap|ansipc|ansi personal computer:\
     :al=\E[L:am:bs:bt=\E[Z:bw:cd=\E[O:ce=\E[K:ch=\E[%i%d`:\
     :cl=\E[2O:cm=\E[%i%d;%dH:co#80:cs=\E[%i%d;%dr:\
     :cv=\E[%i%dd:dl=\E[M:ho=\E[H:is=\E[25f\E[2K\E[m\E[H:\
     :k0=\E[0x:k1=\E[1x:k2=\E[2x:k3=\E[3x:k4=\E[4x:k5=\E[5x:\
     :k6=\E[6x:k7=\E[7x:k8=\E[8x:k9=\E[9x:kb=^h:kd=\E[B:kh=\E[H:\
     :kl=\E[D:kr=\E[C:ku=\E[A:li#24:ll=\E[24;1H:hd=\E[C:se=\E[m:\
     :sf=\E[S:sg#0:so=\E[7m:sr=\E[T:ue=\E[m:up=\E[A:us=\E[4m:\
     :KI=\E[5x:KD=\E[3x:Kd=\E[P:KB=\E[6x:KU=\E[4x:Ku=\E[@:\
     :KM=\E[7x:KJ=\E[8x:Kt=\E[Z:KT=\t:KL=\E[1x:KR=\E[2x:KP=\E[U:\
     :Kp=\E[V:KX=\E[9x:KC=\E[0x:KE=\E[24H:KW=^F:Kw=^R:Kr=^N:do=\E[B:

The first field, which occupies line  1, gives the various aliases for this
device.  The remaining fields mean the following:

:al=\E[L:\  <esc>L adds new  blank line; use one millisecond for each
            line added.
:am:\       Terminal has automatic margins.
:bs:\       Backspace character is <ctrl>-H (the default).
:bt=\E[Z:\  <esc>[Z back-tabs.
:bw:\       On this  device, a backspace  character wraps from  column 0 to
            the last column (in this case, column 79) on the previous line.
:cd=\E[O:\  <esc>[O clears to the end of display.
:ce=\E[K:\  <esc>[K clears to end of line.
:ch=\E[%i%d`:\
            The string for horizontal cursor motion (described later).
:cl=\E[2O:\ <esc>[2O clears screen.
:cm=\E[%i%d;%dH:\
            Cursor motion (described later).
:co#80:\    Screen has 80 columns.
:cs=\E[%i%d;%dr:\
            String for changing the scrolling region.
:cv=\E[%i%dd:\
            String for vertical cursor motion.
:dl=\E[M:\  <esc>E[M deletes a line.
:ho=\E[H:\  <esc>[H moves cursor to home position.
:is=\E[25f\E[2K\E[m\E[H:\
            The string with which the device is initialized.
:k0=\E[0x:\ Function key 10 sends sequence <esc>[0x.
:k1=\E[1x:\ Function key 1 sends sequence <esc>[1x.
:k2=\E[2x:\ Function key 2 sends sequence <esc>[2x.
:k3=\E[3x:\ Function key 3 sends sequence <esc>[3x.
:k4=\E[4x:\ Function key 4 sends sequence <esc>[4x.
:k5=\E[5x:\ Function key 5 sends sequence <esc>[5x.
:k6=\E[6x:\ Function key 6 sends sequence <esc>[6x.
:k7=\E[7x:\ Function key 7 sends sequence <esc>[7x.
:k8=\E[8x:\ Function key 8 sends sequence <esc>[8x.
:k9=\E[9x:\ Function key 9 sends sequence <esc>[9x.
:kb=^h:\    Backspace key sends <Ctrl>-H.
:kd=\E[B:\  Down-arrow key sends <esc>[B.
:kh=\E[H:\  Home key sends <esc>[H.
:kl=\E[D:\  Left-arrow key sends <esc>[D.
:kr=\E[C:\  Right-arrow key sends <esc>[C.
:ku=\E[A:\  Up-arrow key sends <esc>[A.
:li#24:\    Terminal has 24 lines.
:ll=\E[24;1H:\
            <esc>[24;1H moves  the cursor to the  first column of the
            last line.
:hd=\E[C:\  <esc>[C moves the cursor downward by one-half line.
:se=\E[m:\  <esc>[m exits standout mode.
:sf=\E[S:\  <esc>[S scrolls the screen forward.
:sg#0:\     The  so  and se  instructions  leave zero  blank  lines on  the
            screen.
:so=\E[7m:\ <esc>[7m begins standout mode.
:sr=\E[T:\  <esc>[T reverse-scrolls the screen.
:ue=\E[m:\  <esc>m ends underline mode.
:up=\E[A:\  <esc>[A moves the cursor up one line.
:us=\E[4m:\ <esc>4m begins underscore mode.
:do=\E[B:   <esc>E[B moves cursor down one line.

Note that  the last field did  not end with a  backslash; this indicated to
the COHERENT system that the termcap description was finished.

A terminal description does not have to be nearly so detailed.  If you wish
to use a new terminal, first check the following table to see if it already
appears by termcap.  If it  does not, check the terminal's documentation to
see if it  mimics a terminal that is already  in /etc/termcap, and use that
description, modifying  it if necessary and changing the  name to suit your
terminal.  If you must create  an entirely new description, first prepare a
skeleton file that contains  the following basic elements: number of lines,
number  of columns,  backspace, cursor motion,  line delete,  clear screen,
move cursor  to home  position, newline,  move cursor up  a line,  and non-
destructive  right  space.   For  example,  the  following is  the  termcap
description for the Lear-Siegler ADM-3A terminal:

la|adm3a|3a|lsi adm3a:\
     :am:bs:cd=^W:ce=^X:cm=\E=%+ %+ :cl=^Z:co#80:ho=^^:li#24:\
     :nd=<ctrl-L>:up=^K:

Once you have installed  and debugged the skeleton description, add details
gradually until every feature of the terminal is described.

Cursor Motion

The cursor motion  characteristic contains printf-like escape sequences not
used elsewhere.  These encode the  line and column positions of the cursor,
whereas  other  characters  are passed  unchanged.   If  the  cm string  is
considered as a function, then its arguments are the line and the column to
which the cursor is to move; the % codes have the following meanings:

%d   Decimal number, as in printf. The origin is 0.

%2   Two-digit decimal number.  The same as %2d in printf().

%3   Three-digit decimal number.  The same as %3d in printf().

%.   Single byte.  The same as %c in printf().

%+n  Add n  to the current position  value.  n may be either  a number or a
     character.

%>nm
     If the  current position value is  greater than n+m; then  there is no
     output.

%r   Reverse order  of line and column, giving column  first and then line.
     No output.

%i   Increment line and column.

%%   Give a % sign in the string.

%n   Exclusive or line and column with 0140 (Datamedia 2500 terminal only).

%B   Binary coded decimal (16 * (n/10))+(n%10).  No output.

%D   Reverse coding (n-(2*(n%16)).  No output (Delta Data terminal only).

To send  the cursor to line  3, column 12 on  the Hewlett-Packard 2645, the
terminal must  be sent  <esc>&amp;a12c03Y padded for  6 milliseconds.
Note that  the column is given  first and then the line,  and that the line
and column are  given as two digits each.  Thus,  the cm capability for the
Hewlett-Packard 2645 is given by:

    :cm=6\E&%r%2c%2Y:

The  Microterm  ACT-IV  needs  the  current  position sent  preceded  by  a
<Ctrl-T>, with the line and column encoded in binary:

    :cm=^T%.%.:

Terminals that use  %. must be able to backspace  the cursor (bs or bc) and
to  move the  cursor  up one  line  on the  screen (up).   This is  because
transmitting   \t,  \n,   \r,  or   <ctrl-D>  may   have  undesirable
consequences or be ignored by the system.

Similar Terminals

If your system uses two similar terminals, one can be defined as resembling
the  other,  with  certain  exceptions.   The  code tc  names  the  similar
terminal.  This field  must be last in the termcap  entry, and the combined
length  of the  two entries cannot  exceed 1,024  characters.  Capabilities
given first  over-ride those in  the similar terminal,  and capabilities in
the similar  terminal can be cancelled  by xx@ where xx  is the capability.
For example, the entry

    hn|2621nl|HP 2621nl:ks@:ke@:tc=2621

defines a  Hewlett-Packard 2621 terminal that  does not have the  ks and ke
capabilities,  and thus  cannot turn  on the function  keys when  in visual
mode.

Initialization

A terminal  initialization string may  be given with the  is capability; if
the string  is too long, it may  be read from a file given  by the if code.
Usually, these strings  set the tabs on a terminal  with settable tabs.  If
both is and if are given,  is will be printed first to clear the tabs, then
the tabs  will be set  from the file  specified by if.  The Hewlett-Packard
2626 has:

    :is=\E&j@\r\E3\r:if=/usr/lib/tabset/stdcrt:

Programming With termcap

The COHERENT library libterm.a contains the following routines that extract
and use the descriptions for termcap:

tgetent() Read a termcap entry.

tgetflag()
          Check if a given  Boolean capability is present in the terminal's
          termcap entry.

tgetnum() Return the  value of a numeric termcap  feature (e.g., the number
          of columns on the terminal).

tgetstr() Read and decode a termcap string feature.

tgoto()   Read and decode a cursor-addressing string.

tputs()   Read  and decode  the leading  padding  information of  a termcap
          string feature.

See the Lexicon entry for each function for details.

The external variable ospeed is the output speed to the terminal as encoded
by  stty.  The  external variable  PC  is  a  padding  character if  a  NUL
(<crtl-@>) is not appropriate.

The following example shows how to read a termcap entry:

#include <stdio.h>

static char *CM, *SO, *SE, *CL;
static int rows, cols;
static int am;
static int errflag;
static char *ptr;
static char *tv_stype;

extern char *tgoto();         /* termcap cursor position command */
extern char *tgetstr();       /* get string code from termcap */
extern int tgetflag();        /* get boolean flag from termcap */
extern int tgetnum();         /* get numeric code from termcap */
extern void tputs();          /* termcap put data command */
extern char PC;               /* termcap's pad character */

/*
 * Get a required termcap string or exit with a message.
 */
static char *
qgetstr(ref)
char *ref;
{
                              register char *tmp;

                              if ((tmp = tgetstr(ref, &ptr)) == NULL) {
                              printf("/etc/termcap terminal %s must have a %s= entry\n",
                               tv_stype, ref);
                              errflag = 1;
                              }
                              return (tmp);
}

/*
 * Get required termcap information for this terminal type.
 */
static void
tcapopen()
{
                              extern char *getenv(), *realloc();
                              char *tcapbuf;
                              char tcbuf[1024]; /* this must hold the whole tml entry */
                              char *p;

                              /* set up termcap type */
                              if ((tv_stype = getenv("TERM")) == NULL) {
                              printf("Environment variable TERM not defined\n");
                              exit(1);
                              }

                              if (tgetent(tcbuf, tv_stype) != 1) {
                              printf("Terminal type %s not in /etc/termcap\n", tv_stype);
                              exit(1);
                              }

                              /* get far too much and shrink later */
                              if ((ptr = tcapbuf = malloc(1024)) == NULL) {
                              printf("out of space\n");
                              exit(1);
                              }

                              /* get termcap entries for later use */
                              CM = qgetstr("cm"); /* this string used by tgoto() */
                              CL = qgetstr("cl"); /* this string used to clear screen */
                              SO = qgetstr("so"); /* this string used to set standout */
                              SE = qgetstr("se"); /* this string used by clear standout */
                              if (errflag)/* set if any missing entries */
                              exit(1);

                              /* set termcap's pad char */
                              PC = (((p = tgetstr("pc", &ptr)) == NULL) ? 0 : *p);

                              if (tcapbuf != realloc(tcapbuf, (unsigned)(ptr - tcapbuf))) {
                              printf("Buffer not shrunk in place!\n");
                              exit(1);
                              }

                              if ((cols = tgetnum("co")) < 0)/* Get rows and columns */
                              cols = 80;
                              if ((rows = tgetnum("li")) < 0)
                              rows = 24;

                              am = tgetflag("am");/* automatic margins ? */
}

/*
 * output char function.
 */
static void
ttputc(c)
{
                              fputc(c, stdout);
}

/*
 * output command string, set padding to one line affected.
 * use ttputc as character output function. Use only for
 * termcap created data not your own strings.
 */
void
putpad(str)
char *str;
{
                              tputs(str, 1, ttputc);
}

/*
 * Move cursor.
 */
void
move(col, row)
{
                              putpad(tgoto(CM, col, row));
}

/*
 * Demonstrate termcap.
 */
main()
{
                              tcapopen();

                              putpad(CL);  /* clear the screen */

                              move(30, 5);
                              putpad(SO);  /* standout mode */
                              printf("Termcap Demo");
                              putpad(SE);  /* end standout mode */

                              move(0, 7);
                              printf("This terminal has %d columns and %d rows.", cols, rows);

                              if (am) {
                              move(0, 8);
                              printf("Automatic margins.");
                              }

                              move(0, rows);/* quit at bottom of screen */
                              exit(0);
}

Files

/etc/termcap -- Terminal-description data base
/usr/lib/libterm.a -- Routines for reading a termcap description

See Also

Administering COHERENT,
captoinfo,
curses,
libterm,
terminal,
terminfo,
tgetent(),
tgetflag(),
tgetnum(),
tgetstr(),
tgoto(),
tputs()
Strang, J., Mui, L.,  O'Reilly, T.: Termcap &amp; Terminfo. Sebastopol, CA:
O'Reilly & Associates, Inc., 1991.  Highly recommended.

Notes

To see which terminals are currently supported, see file /etc/termcap.

COHERENT also  supports terminfo,  a clone  of the UNIX  System-V terminal-
description  system.  terminfo  enjoys a number  of features  not available
under termcap, and is the preferred system under COHERENT.

Should you  wish to convert  to terminfo, the command  captoinfo converts a
file of termcap descriptions to their terminfo analogues.