]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_termcap.3x
ncurses 6.4 - patch 20231007
[ncurses.git] / man / curs_termcap.3x
1 .\"***************************************************************************
2 .\" Copyright 2018-2022,2023 Thomas E. Dickey                                *
3 .\" Copyright 1998-2017,2018 Free Software Foundation, Inc.                  *
4 .\"                                                                          *
5 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
6 .\" copy of this software and associated documentation files (the            *
7 .\" "Software"), to deal in the Software without restriction, including      *
8 .\" without limitation the rights to use, copy, modify, merge, publish,      *
9 .\" distribute, distribute with modifications, sublicense, and/or sell       *
10 .\" copies of the Software, and to permit persons to whom the Software is    *
11 .\" furnished to do so, subject to the following conditions:                 *
12 .\"                                                                          *
13 .\" The above copyright notice and this permission notice shall be included  *
14 .\" in all copies or substantial portions of the Software.                   *
15 .\"                                                                          *
16 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23 .\"                                                                          *
24 .\" Except as contained in this notice, the name(s) of the above copyright   *
25 .\" holders shall not be used in advertising or otherwise to promote the     *
26 .\" sale, use or other dealings in this Software without prior written       *
27 .\" authorization.                                                           *
28 .\"***************************************************************************
29 .\"
30 .\" $Id: curs_termcap.3x,v 1.69 2023/10/07 21:19:07 tom Exp $
31 .TH curs_termcap 3X 2023-10-07 "ncurses 6.4" "Library calls"
32 .ie \n(.g \{\
33 .ds `` \(lq
34 .ds '' \(rq
35 .\}
36 .el \{\
37 .ie t .ds `` ``
38 .el   .ds `` ""
39 .ie t .ds '' ''
40 .el   .ds '' ""
41 .\}
42 .
43 .de bP
44 .ie n  .IP \(bu 4
45 .el    .IP \(bu 2
46 ..
47 .
48 .ds n 5
49 .SH NAME
50 \fB\%PC\fP,
51 \fB\%UP\fP,
52 \fB\%BC\fP,
53 \fB\%ospeed\fP,
54 \fB\%tgetent\fP,
55 \fB\%tgetflag\fP,
56 \fB\%tgetnum\fP,
57 \fB\%tgetstr\fP,
58 \fB\%tgoto\fP,
59 \fB\%tputs\fP \-
60 \fIcurses\fR emulation of \fItermcap\fR
61 .SH SYNOPSIS
62 .nf
63 \fB#include <curses.h>
64 \fB#include <term.h>
65 .PP
66 \fBextern char PC;
67 \fBextern char * UP;
68 \fBextern char * BC;
69 \fBextern @NCURSES_OSPEED@ ospeed;
70 .PP
71 \fBint tgetent(char *\fIbp\fP, const char *\fIname\fP);
72 \fBint tgetflag(const char *\fIid\fP);
73 \fBint tgetnum(const char *\fIid\fP);
74 \fBchar *tgetstr(const char *\fIid\fP, char **\fIarea\fP);
75 \fBchar *tgoto(const char *\fIcap\fP, int \fIcol\fP, int \fIrow\fP);
76 \fBint tputs(const char *\fIstr\fP, int \fIaffcnt\fP, int (*\fIputc\fP)(int));
77 .fi
78 .SH DESCRIPTION
79 These routines are included as a conversion aid for programs that use
80 the \fItermcap\fP library.
81 Their parameters are the same, but the
82 routines are emulated using the \fIterminfo\fP database.
83 Thus, they
84 can only be used to query the capabilities of entries for which a
85 terminfo entry has been compiled.
86 .SS Initialization
87 The \fBtgetent\fP routine loads the entry for \fIname\fP.
88 It returns:
89 .RS 3
90 .TP 3
91 1
92 on success,
93 .TP 3
94 0
95 if there is no such entry
96 (or that it is a generic type, having too little information for curses
97 applications to run), and
98 .TP 3
99 \-1
100 if the terminfo database could not be found.
101 .RE
102 .PP
103 This differs from the \fItermcap\fP library in two ways:
104 .RS 3
105 .bP
106 The emulation ignores the buffer pointer \fIbp\fP.
107 The \fItermcap\fP library would store a copy of the terminal
108 description in the area referenced by this pointer.
109 However, ncurses stores its terminal descriptions in compiled
110 binary form, which is not the same thing.
111 .bP
112 There is a difference in return codes.
113 The \fItermcap\fP library does not check if the terminal
114 description is marked with the \fIgeneric\fP capability,
115 or if the terminal description has cursor-addressing.
116 .RE
117 .SS Capability Values
118 The \fBtgetflag\fP routine gets the boolean entry for \fIid\fP,
119 or zero if it is not available.
120 .PP
121 The \fBtgetnum\fP routine gets the numeric entry for \fIid\fP,
122 or \-1 if it is not available.
123 .PP
124 The \fBtgetstr\fP routine returns the string entry for \fIid\fP,
125 or zero if it is not available.
126 Use \fBtputs\fP to output the returned string.
127 The \fIarea\fP parameter is used as follows:
128 .RS 3
129 .bP
130 It is assumed to be the address of a pointer to a buffer managed by the
131 calling application.
132 .bP
133 However, ncurses checks to ensure that \fBarea\fP is not NULL,
134 and also that the resulting buffer pointer is not NULL.
135 If either check fails, the \fIarea\fP parameter is ignored.
136 .bP
137 If the checks succeed, ncurses also copies the return value to
138 the buffer pointed to by \fIarea\fP,
139 and the \fIarea\fP value will be updated to point past the null ending
140 this value.
141 .bP
142 The return value itself is an address in the terminal description which
143 is loaded into memory.
144 .RE
145 .PP
146 Only the first two characters of the \fBid\fP parameter of
147 \fBtgetflag\fP,
148 \fBtgetnum\fP and
149 \fBtgetstr\fP are compared in lookups.
150 .SS Formatting Capabilities
151 The \fBtgoto\fP routine expands the given capability using the parameters.
152 .bP
153 Because the capability may have padding characters,
154 the output of \fBtgoto\fP should be passed to \fBtputs\fP
155 rather than some other output function such as \fBprintf\fP(3).
156 .bP
157 While \fBtgoto\fP is assumed to be used for the two-parameter
158 cursor positioning capability,
159 termcap applications also use it for single-parameter capabilities.
160 .IP
161 Doing this shows a quirk in \fBtgoto\fP: most hardware
162 terminals use cursor addressing with \fIrow\fP first,
163 but the original developers of the termcap interface chose to
164 put the \fIcolumn\fP parameter first.
165 The \fBtgoto\fP function swaps the order of parameters.
166 It does this also for calls requiring only a single parameter.
167 In that case, the first parameter is merely a placeholder.
168 .bP
169 Normally the ncurses library is compiled with terminfo support.
170 In that case, \fBtgoto\fP uses an internal version of
171 \fBtparm\fP(3X) (a more capable formatter).
172 .IP
173 With terminfo support, \fBtgoto\fP is able to use some of the terminfo
174 features, but not all.
175 In particular, it allows only numeric parameters;
176 \fBtparm\fP supports string parameters.
177 .IP
178 However, \fBtparm\fP is not a \fItermcap\fP feature,
179 and portable \fItermcap\fP applications should not rely upon its availability.
180 .PP
181 The \fBtputs\fP routine is described on the \fBcurs_terminfo\fP(3X) manual
182 page.
183 It can retrieve capabilities by either termcap or terminfo name.
184 .SS Global Variables
185 The variables
186 \fBPC\fP,
187 \fBUP\fP and
188 \fBBC\fP
189 are set by \fBtgetent\fP to the terminfo entry's data for
190 \fBpad_char\fP,
191 \fBcursor_up\fP and
192 \fBbackspace_if_not_bs\fP,
193 respectively.
194 \fBUP\fP is not used by ncurses.
195 \fBPC\fP is used in the \fBtdelay_output\fP function.
196 \fBBC\fP is used in the \fBtgoto\fP emulation.
197 The variable \fBospeed\fP is set by ncurses in a system-specific coding
198 to reflect the terminal speed.
199 .SS Releasing Memory
200 The termcap functions provide no means for freeing memory,
201 because legacy termcap implementations used only the buffer
202 areas provided by the caller via \fBtgetent\fP and \fBtgetstr\fP.
203 Those buffers are unused in terminfo.
204 .PP
205 On the other hand, terminfo allocates memory.
206 It uses \fBsetupterm\fP to retrieve the data used by \fBtgetent\fP
207 and the functions which return capability values such as \fBtgetstr\fP.
208 One could use
209 .sp
210         \fBdel_curterm(cur_term);\fP
211 .sp
212 .PP
213 to free this memory, but there is an additional complication with ncurses.
214 It uses a fixed-size \fIpool\fP of storage locations,
215 one per setting of the \fBTERM\fP variable when \fBtgetent\fP is called.
216 The \fBscreen\fP(1) program relies upon this arrangement,
217 to improve its performance.
218 .PP
219 An application which uses only the low-level termcap functions could
220 free the memory using \fBdel_curterm\fP,
221 because the pool is freed using other functions
222 (see \fBcurs_memleaks\fP(3X)).
223 .
224 .SH RETURN VALUE
225 Except where explicitly noted,
226 routines that return an integer return \fBERR\fP upon failure and \fBOK\fP
227 (SVr4 only specifies "an integer value other than \fBERR\fP") upon successful
228 completion.
229 .PP
230 Routines that return pointers return \fBNULL\fP on error.
231 .PP
232 A few special cases apply:
233 .bP
234 If the terminal database has not been initialized,
235 these return an error.
236 .bP
237 The calls with a string parameter (\fBtgoto\fP, \fBtputs\fP)
238 check if the string is null, or cancelled.
239 Those return an error.
240 .bP
241 A call to \fBtgoto\fP using a capability with string parameters is an error.
242 .bP
243 A call to \fBtgoto\fP using a capability with more than two parameters
244 is an error.
245 .SH BUGS
246 If you call \fBtgetstr\fP to fetch \fBca\fP or any other parameterized string,
247 be aware that it will be returned in terminfo notation, not the older and
248 not-quite-compatible termcap notation.
249 This will not cause problems if all
250 you do with it is call \fBtgoto\fP or \fBtparm\fP, which both expand
251 terminfo-style strings as terminfo.
252 (The \fBtgoto\fP function, if configured to support termcap, will check
253 if the string is indeed terminfo-style by looking for "%p" parameters or
254 "$<..>" delays, and invoke a termcap-style parser if the string does not
255 appear to be terminfo).
256 .PP
257 Because terminfo conventions for representing padding in string capabilities
258 differ from termcap's,
259 users can be surprised:
260 .bP
261 \fBtputs("50")\fP in a terminfo system will put out a literal \*(``50\*(''
262 rather than busy-waiting for 50 milliseconds.
263 .bP
264 However, if ncurses is configured to support termcap,
265 it may also have been configured to support the BSD-style padding.
266 .IP
267 In that case, \fBtputs\fP inspects strings passed to it,
268 looking for digits at the beginning of the string.
269 .IP
270 \fBtputs("50")\fP in a termcap system may wait for 50 milliseconds
271 rather than put out a literal \*(``50\*(''
272 .PP
273 Note that termcap has nothing analogous to terminfo's \fBsgr\fP string.
274 One consequence of this is that termcap applications assume \fBme\fP
275 (terminfo \fBsgr0\fP) does not reset the alternate character set.
276 This implementation checks for, and modifies the data shown to the
277 termcap interface to accommodate termcap's limitation in this respect.
278 .SH PORTABILITY
279 .SS Standards
280 These functions are provided for supporting legacy applications,
281 and should not be used in new programs:
282 .bP
283 The XSI Curses standard, Issue 4 describes these functions.
284 However, they
285 are marked TO BE WITHDRAWN and may be removed in future versions.
286 .bP
287 X/Open Curses, Issue 5 (December 2007) marked the termcap interface
288 (along with \fBvwprintw\fP and \fBvwscanw\fP) as withdrawn.
289 .PP
290 Neither the XSI Curses standard nor the SVr4 man pages documented the return
291 values of \fBtgetent\fP correctly, though all three were in fact returned ever
292 since SVr1.
293 In particular, an omission in the XSI Curses documentation has been
294 misinterpreted to mean that \fBtgetent\fP returns \fBOK\fP or \fBERR\fP.
295 Because the purpose of these functions is to provide compatibility with
296 the \fItermcap\fP library, that is a defect in XCurses, Issue 4, Version 2
297 rather than in ncurses.
298 .SS Compatibility with BSD Termcap
299 External variables are provided for support of certain termcap applications.
300 However, termcap applications' use of those variables is poorly documented,
301 e.g., not distinguishing between input and output.
302 In particular, some applications are reported to declare and/or
303 modify \fBospeed\fP.
304 .PP
305 The comment that only the first two characters of the \fBid\fP parameter
306 are used escapes many application developers.
307 The original BSD 4.2 termcap library (and historical relics thereof)
308 did not require a trailing null NUL on the parameter name passed
309 to \fBtgetstr\fP, \fBtgetnum\fP and \fBtgetflag\fP.
310 Some applications assume that the termcap interface does not require
311 the trailing NUL for the parameter name.
312 Taking into account these issues:
313 .bP
314 As a special case,
315 \fBtgetflag\fP matched against a single-character identifier
316 provided that was at the end of the terminal description.
317 You should not rely upon this behavior in portable programs.
318 This implementation disallows matches against single-character capability names.
319 .bP
320 This implementation disallows matches by the termcap interface against
321 extended capability names which are longer than two characters.
322 .PP
323 The BSD termcap function \fBtgetent\fP returns the text of a termcap
324 entry in the buffer passed as an argument.
325 This library (like other terminfo implementations) does not store
326 terminal descriptions as text.
327 It sets the buffer contents to a null-terminated string.
328 .SS Other Compatibility
329 This library includes a termcap.h header,
330 for compatibility with other implementations.
331 But the header is rarely used because the other implementations
332 are not strictly compatible.
333 .PP
334 The original BSD termcap (through 4.3BSD) had no header file which
335 gave function prototypes, because that was a feature of ANSI C.
336 BSD termcap was written several years before C was standardized.
337 However, there were two different termcap.h header files in the BSD
338 sources:
339 .bP
340 One was used internally by the \fBjove\fP editor in 2BSD through 4.4BSD.
341 It defined global symbols for the termcap variables which it used.
342 .bP
343 The other appeared in 4.4BSD Lite Release 2 (mid-1993)
344 as part of \fIlibedit\fP (also known as the \fIeditline\fP library).
345 The CSRG source history shows that this was added in mid-1992.
346 The \fIlibedit\fP header file was used internally,
347 as a convenience for compiling the \fIeditline\fP library.
348 It declared function prototypes, but no global variables.
349 .PP
350 The header file from \fIlibedit\fP was added to NetBSD's termcap
351 library in mid-1994.
352 .PP
353 Meanwhile, GNU termcap was under development, starting in 1990.
354 The first release (termcap 1.0) in 1991 included a termcap.h header.
355 The second release (termcap 1.1) in September 1992 modified the
356 header to use \fBconst\fP for the function prototypes in the header
357 where one would expect the parameters to be read-only.
358 This was a difference versus the original BSD termcap.
359 The prototype for \fBtputs\fP also differed,
360 but in that instance, it was \fIlibedit\fP which differed from BSD termcap.
361 .PP
362 A copy of GNU termcap 1.3 was bundled with \fIbash\fP in mid-1993,
363 to support the \fBreadline\fP(3) library.
364 .PP
365 A termcap.h file was provided in ncurses 1.8.1 (November 1993).
366 That reflected influence by \fBemacs\fP(1) (rather than \fBjove\fP(1))
367 and GNU termcap:
368 .bP
369 it provided declarations for a few global symbols used by \fBemacs\fP
370 .bP
371 it provided function prototypes (using \fBconst\fP).
372 .bP
373 a prototype for \fBtparam\fP (a GNU termcap feature) was provided.
374 .PP
375 Later (in mid-1996) the \fBtparam\fP function was removed from ncurses.
376 As a result, there are differences between any of the four implementations,
377 which must be taken into account by programs which can work with all
378 termcap library interfaces.
379 .SH SEE ALSO
380 \fB\%curses\fP(3X),
381 \fB\%putc\fP(3),
382 \fB\%term_variables\fP(3X),
383 \fB\%terminfo\fP(\*n)
384 .PP
385 https://invisible-island.net/ncurses/tctest.html