]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_termcap.3x
ncurses 6.4 - patch 20230408
[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.57 2023/04/08 21:43:01 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 an internal version of
177 \fBtparm\fP(3X) (a more capable formatter).
178 .IP
179 With terminfo support, \fBtgoto\fP is able to use some of the terminfo
180 features, but not all.
181 In particular, it allows only numeric parameters;
182 \fBtparm\fP supports string parameters.
183 .IP
184 However, \fBtparm\fP is not a \fItermcap\fP feature,
185 and portable \fItermcap\fP applications should not rely upon its availability.
186 .PP
187 The \fBtputs\fP routine is described on the \fBcurs_terminfo\fP(3X) manual
188 page.
189 It can retrieve capabilities by either termcap or terminfo name.
190 .SS Global Variables
191 .PP
192 The variables
193 \fBPC\fP,
194 \fBUP\fP and
195 \fBBC\fP
196 are set by \fBtgetent\fP to the terminfo entry's data for
197 \fBpad_char\fP,
198 \fBcursor_up\fP and
199 \fBbackspace_if_not_bs\fP,
200 respectively.
201 \fBUP\fP is not used by ncurses.
202 \fBPC\fP is used in the \fBtdelay_output\fP function.
203 \fBBC\fP is used in the \fBtgoto\fP emulation.
204 The variable \fBospeed\fP is set by ncurses in a system-specific coding
205 to reflect the terminal speed.
206 .SS Releasing Memory
207 The termcap functions provide no means for freeing memory,
208 because legacy termcap implementations used only the buffer
209 areas provided by the caller via \fBtgetent\fP and \fBtgetstr\fP.
210 Those buffers are unused in terminfo.
211 .PP
212 On the other hand, terminfo allocates memory.
213 It uses \fBsetupterm\fP to retrieve the data used by \fBtgetent\fP
214 and the functions which return capability values such as \fBtgetstr\fP.
215 One could use
216 .sp
217         \fBdel_curterm(cur_term);\fP
218 .sp
219 .PP
220 to free this memory, but there is an additional complication with ncurses.
221 It uses a fixed-size \fIpool\fP of storage locations,
222 one per setting of the \fBTERM\fP variable when \fBtgetent\fP is called.
223 The \fBscreen\fP(1) program relies upon this arrangement,
224 to improve its performance.
225 .PP
226 An application which uses only the low-level termcap functions could
227 free the memory using \fBdel_curterm\fP,
228 because the pool is freed using other functions
229 (see \fBcurs_memleaks\fP(3X)).
230 .
231 .SH RETURN VALUE
232 Except where explicitly noted,
233 routines that return an integer return \fBERR\fP upon failure and \fBOK\fP
234 (SVr4 only specifies "an integer value other than \fBERR\fP") upon successful
235 completion.
236 .PP
237 Routines that return pointers return \fBNULL\fP on error.
238 .PP
239 A few special cases apply:
240 .bP
241 If the terminal database has not been initialized,
242 these return an error.
243 .bP
244 The calls with a string parameter (\fBtgoto\fP, \fBtputs\fP)
245 check if the string is null, or cancelled.
246 Those return an error.
247 .bP
248 A call to \fBtgoto\fP using a capability with string parameters is an error.
249 .bP
250 A call to \fBtgoto\fP using a capability with no parameters,
251 or more than two is an error.
252 .SH BUGS
253 If you call \fBtgetstr\fP to fetch \fBca\fP or any other parameterized string,
254 be aware that it will be returned in terminfo notation, not the older and
255 not-quite-compatible termcap notation.
256 This will not cause problems if all
257 you do with it is call \fBtgoto\fP or \fBtparm\fP, which both expand
258 terminfo-style strings as terminfo.
259 (The \fBtgoto\fP function, if configured to support termcap, will check
260 if the string is indeed terminfo-style by looking for "%p" parameters or
261 "$<..>" delays, and invoke a termcap-style parser if the string does not
262 appear to be terminfo).
263 .PP
264 Because terminfo conventions for representing padding in string capabilities
265 differ from termcap's,
266 users can be surprised:
267 .bP
268 \fBtputs("50")\fP in a terminfo system will put out a literal \*(``50\*(''
269 rather than busy-waiting for 50 milliseconds.
270 .bP
271 However, if ncurses is configured to support termcap,
272 it may also have been configured to support the BSD-style padding.
273 .IP
274 In that case, \fBtputs\fP inspects strings passed to it,
275 looking for digits at the beginning of the string.
276 .IP
277 \fBtputs("50")\fP in a termcap system may wait for 50 milliseconds
278 rather than put out a literal \*(``50\*(''
279 .PP
280 Note that termcap has nothing analogous to terminfo's \fBsgr\fP string.
281 One consequence of this is that termcap applications assume \fBme\fP
282 (terminfo \fBsgr0\fP) does not reset the alternate character set.
283 This implementation checks for, and modifies the data shown to the
284 termcap interface to accommodate termcap's limitation in this respect.
285 .SH PORTABILITY
286 .SS Standards
287 These functions are provided for supporting legacy applications,
288 and should not be used in new programs:
289 .bP
290 The XSI Curses standard, Issue 4 describes these functions.
291 However, they
292 are marked TO BE WITHDRAWN and may be removed in future versions.
293 .bP
294 X/Open Curses, Issue 5 (December 2007) marked the termcap interface
295 (along with \fBvwprintw\fP and \fBvwscanw\fP) as withdrawn.
296 .PP
297 Neither the XSI Curses standard nor the SVr4 man pages documented the return
298 values of \fBtgetent\fP correctly, though all three were in fact returned ever
299 since SVr1.
300 In particular, an omission in the XSI Curses documentation has been
301 misinterpreted to mean that \fBtgetent\fP returns \fBOK\fP or \fBERR\fP.
302 Because the purpose of these functions is to provide compatibility with
303 the \fItermcap\fP library, that is a defect in XCurses, Issue 4, Version 2
304 rather than in ncurses.
305 .SS Compatibility with BSD Termcap
306 .PP
307 External variables are provided for support of certain termcap applications.
308 However, termcap applications' use of those variables is poorly documented,
309 e.g., not distinguishing between input and output.
310 In particular, some applications are reported to declare and/or
311 modify \fBospeed\fP.
312 .PP
313 The comment that only the first two characters of the \fBid\fP parameter
314 are used escapes many application developers.
315 The original BSD 4.2 termcap library (and historical relics thereof)
316 did not require a trailing null NUL on the parameter name passed
317 to \fBtgetstr\fP, \fBtgetnum\fP and \fBtgetflag\fP.
318 Some applications assume that the termcap interface does not require
319 the trailing NUL for the parameter name.
320 Taking into account these issues:
321 .bP
322 As a special case,
323 \fBtgetflag\fP matched against a single-character identifier
324 provided that was at the end of the terminal description.
325 You should not rely upon this behavior in portable programs.
326 This implementation disallows matches against single-character capability names.
327 .bP
328 This implementation disallows matches by the termcap interface against
329 extended capability names which are longer than two characters.
330 .PP
331 The BSD termcap function \fBtgetent\fP returns the text of a termcap
332 entry in the buffer passed as an argument.
333 This library (like other terminfo implementations) does not store
334 terminal descriptions as text.
335 It sets the buffer contents to a null-terminated string.
336 .SS Other Compatibility
337 This library includes a termcap.h header,
338 for compatibility with other implementations.
339 But the header is rarely used because the other implementations
340 are not strictly compatible.
341 .PP
342 The original BSD termcap (through 4.3BSD) had no header file which
343 gave function prototypes, because that was a feature of ANSI C.
344 BSD termcap was written several years before C was standardized.
345 However, there were two different termcap.h header files in the BSD
346 sources:
347 .bP
348 One was used internally by the \fBjove\fP editor in 2BSD through 4.4BSD.
349 It defined global symbols for the termcap variables which it used.
350 .bP
351 The other appeared in 4.4BSD Lite Release 2 (mid-1993)
352 as part of \fIlibedit\fP (also known as the \fIeditline\fP library).
353 The CSRG source history shows that this was added in mid-1992.
354 The \fIlibedit\fP header file was used internally,
355 as a convenience for compiling the \fIeditline\fP library.
356 It declared function prototypes, but no global variables.
357 .PP
358 The header file from \fIlibedit\fP was added to NetBSD's termcap
359 library in mid-1994.
360 .PP
361 Meanwhile, GNU termcap was under development, starting in 1990.
362 The first release (termcap 1.0) in 1991 included a termcap.h header.
363 The second release (termcap 1.1) in September 1992 modified the
364 header to use \fBconst\fP for the function prototypes in the header
365 where one would expect the parameters to be read-only.
366 This was a difference versus the original BSD termcap.
367 The prototype for \fBtputs\fP also differed,
368 but in that instance, it was \fIlibedit\fP which differed from BSD termcap.
369 .PP
370 A copy of GNU termcap 1.3 was bundled with \fIbash\fP in mid-1993,
371 to support the \fBreadline\fP(3) library.
372 .PP
373 A termcap.h file was provided in ncurses 1.8.1 (November 1993).
374 That reflected influence by \fBemacs\fP(1) (rather than \fBjove\fP(1))
375 and GNU termcap:
376 .bP
377 it provided declarations for a few global symbols used by \fBemacs\fP
378 .bP
379 it provided function prototypes (using \fBconst\fP).
380 .bP
381 a prototype for \fBtparam\fP (a GNU termcap feature) was provided.
382 .PP
383 Later (in mid-1996) the \fBtparam\fP function was removed from ncurses.
384 As a result, there are differences between any of the four implementations,
385 which must be taken into account by programs which can work with all
386 termcap library interfaces.
387 .SH SEE ALSO
388 \fBcurses\fP(3X),
389 \fBputc\fP(3),
390 \fBterm_variables\fP(3X),
391 \fBterminfo\fP(\*n).
392 .sp
393 https://invisible-island.net/ncurses/tctest.html