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