These functions extract and use capabilities from a terminal capability database, usually
/usr/share/misc/terminfo, the format of which is described in
terminfo(5). These are low level routines; see
curses(3) for a higher level package.
The
setupterm() function extracts the entry for terminal
name and then calls
set_curterm() to set
cur_term to it. If
name is
NULL then it is replaced by the environment variable
TERM. The
setupterm() function returns 0 on success and -1 on error.
errret is set to -1 if the
terminfo database could not be opened, 0 if the terminal could not be found in the database, and 1 if all went well.
The
set_curterm() function sets the variable
cur_term to
nterm and makes all of the
terminfo boolean, numeric and string variables use the values from
nterm. The global variables
PC and
ospeed are then set. The old value of
cur_term is returned. The
del_curterm() function frees space pointed to by
oterm.
The
tigetflag() function gets the boolean value of capability
id, returning -1 if it is not a valid capability. The
tigetnum() function gets the numeric value of the capability
id, returning -2 if it is not a valid capability. The
tigetstr() function returns the string value of the capability
id, returning (char *)-1 if it is not a valid capability.
The
tparm() function returns a string decoded from
cm with the parameters
p1 ...
p9 applied. Some capabilities require string parameters and only platforms that can fit a
char * pointer inside a
long can use them. The string encoding and parameter application is described in
terminfo(5).
The
tputs() function applies padding information to the string
cp;
affcnt gives the number of lines affected by the operation, or 1 if this is not applicable;
outc is a function which is called by each character in turn. The external variable
ospeed controls how many padding characters are sent in relation to the terminal speed. The
putp() function calls tputs(str, 1, putchar). The output from
putp() always goes to stdout.
NetBSD Extensions To Terminfo
The
vtparm() function allows variadic parameters instead of 9 fixed longs. Numeric parameters must be longs. String parameters can be used even if the platform cannot fit a
char * into a
long.
The
ti_*() functions correspond to the standard
t*() functions but take an additional
TERMINAL * parameter so that the terminal can be specified instead of assuming
cur_term. These functions use private variables to the
TERMINAL instead of the global variables, such as
PC and
ospeed.