1curs_termcap(3X)                                              curs_termcap(3X)
2
3
4

NAME

6       PC, UP, BC, ospeed, tgetent, tgetflag, tgetnum, tgetstr, tgoto, tputs -
7       curses emulation of termcap
8

SYNOPSIS

10       #include <curses.h>
11       #include <term.h>
12
13       extern char PC;
14       extern char * UP;
15       extern char * BC;
16       extern unsigned ospeed;
17
18       int tgetent(char *bp, const char *name);
19       int tgetflag(const char *id);
20       int tgetnum(const char *id);
21       char *tgetstr(const char *id, char **area);
22       char *tgoto(const char *cap, int col, int row);
23       int tputs(const char *str, int affcnt, int (*putc)(int));
24

DESCRIPTION

26       These routines are included as a conversion aid for programs  that  use
27       the  termcap  library.  Their parameters are the same, but the routines
28       are emulated using the terminfo database.  Thus, they can only be  used
29       to  query  the  capabilities  of entries for which a terminfo entry has
30       been compiled.
31
32   Initialization
33       The tgetent routine loads the entry for name.  It returns:
34
35          1  on success,
36
37          0  if there is no such entry (or that it is a generic  type,  having
38             too little information for curses applications to run), and
39
40          -1 if the terminfo database could not be found.
41
42       This differs from the termcap library in two ways:
43
44          •   The  emulation  ignores  the buffer pointer bp.  The termcap li‐
45              brary would store a copy of the terminal description in the area
46              referenced  by this pointer.  However, ncurses stores its termi‐
47              nal descriptions in compiled binary form, which is not the  same
48              thing.
49
50          •   There is a difference in return codes.  The termcap library does
51              not check if the terminal description is marked with the generic
52              capability,  or  if the terminal description has cursor-address‐
53              ing.
54
55   Capability Values
56       The tgetflag routine gets the boolean entry for id, or zero  if  it  is
57       not available.
58
59       The  tgetnum  routine gets the numeric entry for id, or -1 if it is not
60       available.
61
62       The tgetstr routine returns the string entry for id, or zero if  it  is
63       not  available.  Use tputs to output the returned string.  The area pa‐
64       rameter is used as follows:
65
66          •   It is assumed to be the address of a pointer to a buffer managed
67              by the calling application.
68
69          •   However, ncurses checks to ensure that area is not NULL, and al‐
70              so that the resulting buffer pointer is  not  NULL.   If  either
71              check fails, the area parameter is ignored.
72
73          •   If  the  checks succeed, ncurses also copies the return value to
74              the buffer pointed to by area, and the area value will be updat‐
75              ed to point past the null ending this value.
76
77          •   The  return  value itself is an address in the terminal descrip‐
78              tion which is loaded into memory.
79
80       Only the first two characters of the id parameter of tgetflag,  tgetnum
81       and tgetstr are compared in lookups.
82
83   Formatting Capabilities
84       The tgoto routine expands the given capability using the parameters.
85
86       •   Because  the  capability may have padding characters, the output of
87           tgoto should be passed to tputs rather than some other output func‐
88           tion such as printf(3).
89
90       •   While  tgoto is assumed to be used for the two-parameter cursor po‐
91           sitioning capability, termcap applications also use it for  single-
92           parameter capabilities.
93
94           Doing this shows a quirk in tgoto: most hardware terminals use cur‐
95           sor addressing with row first, but the original developers  of  the
96           termcap  interface  chose  to  put the column parameter first.  The
97           tgoto function swaps the order of parameters.  It  does  this  also
98           for  calls  requiring  only  a single parameter.  In that case, the
99           first parameter is merely a placeholder.
100
101       •   Normally the ncurses library is compiled with terminfo support.  In
102           that  case, tgoto uses an internal version of tparm(3X) (a more ca‐
103           pable formatter).
104
105           With terminfo support, tgoto is able to use some  of  the  terminfo
106           features,  but  not all.  In particular, it allows only numeric pa‐
107           rameters; tparm supports string parameters.
108
109           However, tparm is not a termcap feature, and portable  termcap  ap‐
110           plications should not rely upon its availability.
111
112       The  tputs  routine  is described on the curs_terminfo(3X) manual page.
113       It can retrieve capabilities by either termcap or terminfo name.
114
115   Global Variables
116       The variables PC, UP and BC are set by tgetent to the terminfo  entry's
117       data for pad_char, cursor_up and backspace_if_not_bs, respectively.  UP
118       is not used by ncurses.  PC is used in the tdelay_output function.   BC
119       is  used in the tgoto emulation.  The variable ospeed is set by ncurses
120       in a system-specific coding to reflect the terminal speed.
121
122   Releasing Memory
123       The termcap functions provide no  means  for  freeing  memory,  because
124       legacy  termcap  implementations used only the buffer areas provided by
125       the caller via tgetent and tgetstr.  Those buffers are unused  in  ter‐
126       minfo.
127
128       On the other hand, terminfo allocates memory.  It uses setupterm to re‐
129       trieve the data used by tgetent and the functions which return capabil‐
130       ity values such as tgetstr.  One could use
131
132            del_curterm(cur_term);
133
134
135       to  free  this  memory,  but  there  is an additional complication with
136       ncurses.  It uses a fixed-size pool of storage locations, one per  set‐
137       ting  of  the TERM variable when tgetent is called.  The screen(1) pro‐
138       gram relies upon this arrangement, to improve its performance.
139
140       An application which uses only the low-level  termcap  functions  could
141       free the memory using del_curterm, because the pool is freed using oth‐
142       er functions (see curs_memleaks(3X)).
143

RETURN VALUE

145       Except where explicitly noted, routines that return an  integer  return
146       ERR  upon  failure  and OK (SVr4 only specifies "an integer value other
147       than ERR") upon successful completion.
148
149       Routines that return pointers return NULL on error.
150
151       A few special cases apply:
152
153       •   If the terminal database has not been initialized, these return  an
154           error.
155
156       •   The  calls  with  a  string  parameter  (tgoto, tputs) check if the
157           string is null, or cancelled.  Those return an error.
158
159       •   A call to tgoto using a capability with string parameters is an er‐
160           ror.
161
162       •   A call to tgoto using a capability with more than two parameters is
163           an error.
164

BUGS

166       If you call tgetstr to fetch ca or any other parameterized  string,  be
167       aware  that it will be returned in terminfo notation, not the older and
168       not-quite-compatible termcap notation.  This will not cause problems if
169       all  you do with it is call tgoto or tparm, which both expand terminfo-
170       style strings as terminfo.  (The tgoto function, if configured to  sup‐
171       port  termcap,  will  check  if  the string is indeed terminfo-style by
172       looking for "%p" parameters or "$<..>" delays, and  invoke  a  termcap-
173       style parser if the string does not appear to be terminfo).
174
175       Because  terminfo  conventions for representing padding in string capa‐
176       bilities differ from termcap's, users can be surprised:
177
178tputs("50") in a terminfo system will put out a literal “50” rather
179           than busy-waiting for 50 milliseconds.
180
181       •   However,  if  ncurses is configured to support termcap, it may also
182           have been configured to support the BSD-style padding.
183
184           In that case, tputs inspects strings passed to it, looking for dig‐
185           its at the beginning of the string.
186
187           tputs("50") in a termcap system may wait for 50 milliseconds rather
188           than put out a literal “50”
189
190       Note that termcap has nothing analogous to terminfo's sgr string.   One
191       consequence  of  this  is that termcap applications assume me (terminfo
192       sgr0) does not reset the alternate character set.  This  implementation
193       checks for, and modifies the data shown to the termcap interface to ac‐
194       commodate termcap's limitation in this respect.
195

PORTABILITY

197   Standards
198       These functions are provided for supporting  legacy  applications,  and
199       should not be used in new programs:
200
201       •   The XSI Curses standard, Issue 4 describes these functions.  Howev‐
202           er, they are marked TO BE WITHDRAWN and may be  removed  in  future
203           versions.
204
205       •   X/Open Curses, Issue 5 (December 2007) marked the termcap interface
206           (along with vwprintw and vwscanw) as withdrawn.
207
208       Neither the XSI Curses standard nor the SVr4 man pages  documented  the
209       return  values  of tgetent correctly, though all three were in fact re‐
210       turned ever since SVr1.  In particular, an omission in the  XSI  Curses
211       documentation  has  been misinterpreted to mean that tgetent returns OK
212       or ERR.  Because the purpose of these functions is to provide  compati‐
213       bility  with the termcap library, that is a defect in XCurses, Issue 4,
214       Version 2 rather than in ncurses.
215
216   Compatibility with BSD Termcap
217       External variables are provided for support of certain termcap applica‐
218       tions.  However, termcap applications' use of those variables is poorly
219       documented, e.g., not distinguishing between input and output.  In par‐
220       ticular,  some  applications  are reported to declare and/or modify os‐
221       peed.
222
223       The comment that only the first two characters of the id parameter  are
224       used escapes many application developers.  The original BSD 4.2 termcap
225       library (and historical relics thereof) did not require a trailing null
226       NUL  on  the  parameter  name  passed to tgetstr, tgetnum and tgetflag.
227       Some applications assume that the termcap interface  does  not  require
228       the trailing NUL for the parameter name.  Taking into account these is‐
229       sues:
230
231       •   As a special case,  tgetflag  matched  against  a  single-character
232           identifier  provided  that  was at the end of the terminal descrip‐
233           tion.  You should not rely upon this behavior in portable programs.
234           This  implementation disallows matches against single-character ca‐
235           pability names.
236
237       •   This implementation disallows  matches  by  the  termcap  interface
238           against extended capability names which are longer than two charac‐
239           ters.
240
241       The BSD termcap function tgetent returns the text of a termcap entry in
242       the  buffer  passed  as an argument.  This library (like other terminfo
243       implementations) does not store terminal descriptions as text.  It sets
244       the buffer contents to a null-terminated string.
245
246   Other Compatibility
247       This  library includes a termcap.h header, for compatibility with other
248       implementations.  But the header is rarely used because the  other  im‐
249       plementations are not strictly compatible.
250
251       The original BSD termcap (through 4.3BSD) had no header file which gave
252       function prototypes, because that was a feature of ANSI C.  BSD termcap
253       was  written  several  years before C was standardized.  However, there
254       were two different termcap.h header files in the BSD sources:
255
256       •   One was used internally by the jove editor in 2BSD through  4.4BSD.
257           It defined global symbols for the termcap variables which it used.
258
259       •   The  other  appeared in 4.4BSD Lite Release 2 (mid-1993) as part of
260           libedit (also known as the editline library).  The CSRG source his‐
261           tory  shows  that  this  was added in mid-1992.  The libedit header
262           file was used internally, as a convenience for compiling the  edit‐
263           line library.  It declared function prototypes, but no global vari‐
264           ables.
265
266       The header file from libedit was added to NetBSD's termcap  library  in
267       mid-1994.
268
269       Meanwhile,  GNU  termcap  was under development, starting in 1990.  The
270       first release (termcap 1.0) in 1991 included a termcap.h  header.   The
271       second  release  (termcap 1.1) in September 1992 modified the header to
272       use const for the function prototypes in the header where one would ex‐
273       pect  the parameters to be read-only.  This was a difference versus the
274       original BSD termcap.  The prototype for tputs also  differed,  but  in
275       that instance, it was libedit which differed from BSD termcap.
276
277       A copy of GNU termcap 1.3 was bundled with bash in mid-1993, to support
278       the readline(3) library.
279
280       A termcap.h file was provided in ncurses 1.8.1 (November  1993).   That
281       reflected influence by emacs(1) (rather than jove(1)) and GNU termcap:
282
283       •   it provided declarations for a few global symbols used by emacs
284
285       •   it provided function prototypes (using const).
286
287       •   a prototype for tparam (a GNU termcap feature) was provided.
288
289       Later (in mid-1996) the tparam function was removed from ncurses.  As a
290       result, there are differences between any of the four  implementations,
291       which  must  be  taken into account by programs which can work with all
292       termcap library interfaces.
293

SEE ALSO

295       curses(3X), putc(3), term_variables(3X), terminfo(5).
296
297       https://invisible-island.net/ncurses/tctest.html
298
299
300
301                                                              curs_termcap(3X)
Impressum