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 tparm(3X) (a more capable formatter).
103
104           However,  tparm  is not a termcap feature, and portable termcap ap‐
105           plications should not rely upon its availability.
106
107       The tputs routine is described on the  curs_terminfo(3X)  manual  page.
108       It can retrieve capabilities by either termcap or terminfo name.
109
110   Global Variables
111       The  variables PC, UP and BC are set by tgetent to the terminfo entry's
112       data for pad_char, cursor_up and backspace_if_not_bs, respectively.  UP
113       is  not used by ncurses.  PC is used in the tdelay_output function.  BC
114       is used in the tgoto emulation.  The variable ospeed is set by  ncurses
115       in a system-specific coding to reflect the terminal speed.
116
117   Releasing Memory
118       The  termcap  functions  provide  no  means for freeing memory, because
119       legacy termcap implementations used only the buffer areas  provided  by
120       the  caller  via tgetent and tgetstr.  Those buffers are unused in ter‐
121       minfo.
122
123       On the other hand, terminfo allocates memory.  It uses setupterm to re‐
124       trieve the data used by tgetent and the functions which return capabil‐
125       ity values such as tgetstr.  One could use
126
127            del_curterm(cur_term);
128
129
130       to free this memory, but  there  is  an  additional  complication  with
131       ncurses.   It uses a fixed-size pool of storage locations, one per set‐
132       ting of the TERM variable when tgetent is called.  The  screen(1)  pro‐
133       gram relies upon this arrangement, to improve its performance.
134
135       An  application  which  uses only the low-level termcap functions could
136       free the memory using del_curterm, because the pool is freed using oth‐
137       er functions (see curs_memleaks(3X)).
138

RETURN VALUE

140       Except  where  explicitly noted, routines that return an integer return
141       ERR upon failure and OK (SVr4 only specifies "an  integer  value  other
142       than ERR") upon successful completion.
143
144       Routines that return pointers return NULL on error.
145

BUGS

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

PORTABILITY

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

SEE ALSO

276       curses(3X), putc(3), term_variables(3X), terminfo(5).
277
278       https://invisible-island.net/ncurses/tctest.html
279
280
281
282                                                              curs_termcap(3X)
Impressum