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