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