]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_termcap.3x
ncurses 6.4 - patch 20231014
[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.70 2023/10/14 19:26:28 tom Exp $
31 .TH curs_termcap 3X 2023-10-14 "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 PORTABILITY
246 .SS Standards
247 These functions are provided for supporting legacy applications,
248 and should not be used in new programs:
249 .bP
250 The XSI Curses standard, Issue 4 describes these functions.
251 However, they
252 are marked TO BE WITHDRAWN and may be removed in future versions.
253 .bP
254 X/Open Curses, Issue 5 (December 2007) marked the termcap interface
255 (along with \fBvwprintw\fP and \fBvwscanw\fP) as withdrawn.
256 .PP
257 Neither the XSI Curses standard nor the SVr4 man pages documented the return
258 values of \fBtgetent\fP correctly, though all three were in fact returned ever
259 since SVr1.
260 In particular, an omission in the XSI Curses documentation has been
261 misinterpreted to mean that \fBtgetent\fP returns \fBOK\fP or \fBERR\fP.
262 Because the purpose of these functions is to provide compatibility with
263 the \fItermcap\fP library, that is a defect in XCurses, Issue 4, Version 2
264 rather than in ncurses.
265 .SS Compatibility with BSD Termcap
266 External variables are provided for support of certain termcap applications.
267 However, termcap applications' use of those variables is poorly documented,
268 e.g., not distinguishing between input and output.
269 In particular, some applications are reported to declare and/or
270 modify \fBospeed\fP.
271 .PP
272 The comment that only the first two characters of the \fBid\fP parameter
273 are used escapes many application developers.
274 The original BSD 4.2 termcap library (and historical relics thereof)
275 did not require a trailing null NUL on the parameter name passed
276 to \fBtgetstr\fP, \fBtgetnum\fP and \fBtgetflag\fP.
277 Some applications assume that the termcap interface does not require
278 the trailing NUL for the parameter name.
279 Taking into account these issues:
280 .bP
281 As a special case,
282 \fBtgetflag\fP matched against a single-character identifier
283 provided that was at the end of the terminal description.
284 You should not rely upon this behavior in portable programs.
285 This implementation disallows matches against single-character capability names.
286 .bP
287 This implementation disallows matches by the termcap interface against
288 extended capability names which are longer than two characters.
289 .PP
290 The BSD termcap function \fBtgetent\fP returns the text of a termcap
291 entry in the buffer passed as an argument.
292 This library (like other terminfo implementations) does not store
293 terminal descriptions as text.
294 It sets the buffer contents to a null-terminated string.
295 .SS Other Compatibility
296 This library includes a termcap.h header,
297 for compatibility with other implementations.
298 But the header is rarely used because the other implementations
299 are not strictly compatible.
300 .PP
301 The original BSD termcap (through 4.3BSD) had no header file which
302 gave function prototypes, because that was a feature of ANSI C.
303 BSD termcap was written several years before C was standardized.
304 However, there were two different termcap.h header files in the BSD
305 sources:
306 .bP
307 One was used internally by the \fBjove\fP editor in 2BSD through 4.4BSD.
308 It defined global symbols for the termcap variables which it used.
309 .bP
310 The other appeared in 4.4BSD Lite Release 2 (mid-1993)
311 as part of \fIlibedit\fP (also known as the \fIeditline\fP library).
312 The CSRG source history shows that this was added in mid-1992.
313 The \fIlibedit\fP header file was used internally,
314 as a convenience for compiling the \fIeditline\fP library.
315 It declared function prototypes, but no global variables.
316 .PP
317 The header file from \fIlibedit\fP was added to NetBSD's termcap
318 library in mid-1994.
319 .PP
320 Meanwhile, GNU termcap was under development, starting in 1990.
321 The first release (termcap 1.0) in 1991 included a termcap.h header.
322 The second release (termcap 1.1) in September 1992 modified the
323 header to use \fBconst\fP for the function prototypes in the header
324 where one would expect the parameters to be read-only.
325 This was a difference versus the original BSD termcap.
326 The prototype for \fBtputs\fP also differed,
327 but in that instance, it was \fIlibedit\fP which differed from BSD termcap.
328 .PP
329 A copy of GNU termcap 1.3 was bundled with \fIbash\fP in mid-1993,
330 to support the \fBreadline\fP(3) library.
331 .PP
332 A termcap.h file was provided in ncurses 1.8.1 (November 1993).
333 That reflected influence by \fBemacs\fP(1) (rather than \fBjove\fP(1))
334 and GNU termcap:
335 .bP
336 it provided declarations for a few global symbols used by \fBemacs\fP
337 .bP
338 it provided function prototypes (using \fBconst\fP).
339 .bP
340 a prototype for \fBtparam\fP (a GNU termcap feature) was provided.
341 .PP
342 Later (in mid-1996) the \fBtparam\fP function was removed from ncurses.
343 As a result, there are differences between any of the four implementations,
344 which must be taken into account by programs which can work with all
345 termcap library interfaces.
346 .SH BUGS
347 If you call \fB\%tgetstr\fP to fetch \fB\%ca\fP or any other
348 parameterized string capability,
349 be aware that it is returned in \fI\%terminfo\fP notation,
350 not the older and not-quite-compatible \fI\%termcap\fP notation.
351 This does not cause problems if all you do with it is call \fB\%tgoto\fP
352 or \fB\%tparm\fP, which both expand
353 \fI\%terminfo\fP-style strings as \fI\%terminfo\fP does.
354 (The \fB\%tgoto\fP function,
355 if configured to support \fI\%termcap,\fP
356 checks if the string is indeed \fI\%terminfo\fP-style by looking for
357 \*(``\fB%p\fP\*('' parameters or \*(``\fB<\fP.\|.\|.\fB>\fP\*('' delays,
358 and invokes a \fI\%termcap\fP-style parser if the string appears not to
359 use \fI\%terminfo\fP syntax.)
360 .PP
361 Because \fI\%terminfo\fP's syntax for padding in string capabilities
362 differs from \fI\%termcap\fP's,
363 users can be surprised.
364 .IP \(bu 4
365 \fB\%tputs("50")\fP in a \fI\%terminfo\fP system transmits \*(``50\*(''
366 rather than busy-waiting for 50 milliseconds.
367 .IP \(bu 4
368 However,
369 if \fI\%ncurses\fP is configured to support \fI\%termcap\fP,
370 it may also have been configured to support BSD-style padding.
371 .IP
372 In that case,
373 \fB\%tputs\fP inspects strings passed to it,
374 looking for digits at the beginning of the string.
375 .IP
376 \fB\%tputs("50")\fP in a \fI\%termcap\fP system may busy-wait for 50
377 milliseconds rather than transmitting \*(``50\*(''.
378 .PP
379 \fI\%termcap\fP has nothing analogous to \fI\%terminfo\fP's \fBsgr\fP
380 string.
381 One consequence is that \fI\%termcap\fP applications assume that
382 \fBme\fP
383 (equivalent to \fI\%terminfo\fP's \fBsgr0\fP capability)
384 does not reset the alternate character set.
385 \fI\%ncurses\fP checks for,
386 and modifies the data shared with,
387 the \fI\%termcap\fP interface to accommodate the latter's limitation in
388 this respect.
389 .SH SEE ALSO
390 \fB\%curses\fP(3X),
391 \fB\%putc\fP(3),
392 \fB\%term_variables\fP(3X),
393 \fB\%terminfo\fP(\*n)
394 .PP
395 https://invisible\-island.net/ncurses/tctest.html