]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_termcap.3x
ncurses 6.4 - patch 20231217
[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.76 2023/12/18 00:22:30 tom Exp $
31 .TH curs_termcap 3X 2023-12-17 "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 \fBchar PC;
66 \fBchar * UP;
67 \fBchar * BC;
68 \fB@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 .I \%ncurses
79 provides the foregoing variables and functions as a compatibility layer
80 for programs that use the \fItermcap\fP library.
81 The API is the same,
82 but behavior is emulated using the \fI\%term\%info\fP database.
83 Thus,
84 it can be used only to query the capabilities of terminal database
85 entries for which a \fI\%term\%info\fP entry has been compiled.
86 .SS Initialization
87 \fB\%tgetent\fP loads the terminal database entry for \fIname\fP;
88 see \fBterm\fP(7).
89 This must be done before calling any of the other functions.
90 It returns:
91 .RS 3
92 .TP 4
93 1
94 on success,
95 .TP 4
96 0
97 if there is no such entry
98 (or if the matching entry describes a generic terminal,
99 having too little information for
100 .I curses
101 applications to run),
102 and
103 .TP 4
104 \-1
105 if the \fI\%term\%info\fP database could not be found.
106 .RE
107 .PP
108 This implementation differs from those of historical \fItermcap\fP
109 libraries.
110 .RS 3
111 .bP
112 .I \%ncurses
113 ignores the buffer pointer \fIbp\fP,
114 as do other \fItermcap\fP implementations conforming to portions of
115 X/Open Curses now withdrawn.
116 The BSD \fItermcap\fP library would store a copy of the terminal type
117 description in the area referenced by this pointer.
118 \fI\%ncurses\fP stores terminal type descriptions in compiled form,
119 which is not the same thing.
120 .bP
121 The meanings of the return values differ.
122 The BSD \fItermcap\fP library does not check whether the terminal type
123 description is marked with the
124 .B gn
125 .RB ( \%generic )
126 capability,
127 nor whether the terminal type description supports an addressable
128 cursor,
129 a property essential for any \fIcurses\fP implementation to operate.
130 .RE
131 .SS "Retrieving Capability Values"
132 \fB\%tgetflag\fP reports the Boolean entry for \fIid\fP,
133 or zero if it is not available.
134 .PP
135 \fB\%tgetnum\fP obtains the numeric entry for \fIid\fP,
136 or \-1 if it is not available.
137 .PP
138 \fB\%tgetstr\fP returns the string entry for \fIid\fP,
139 or
140 .B NULL
141 if it is not available.
142 Use \fB\%tputs\fP to output the string returned.
143 The
144 .I area
145 parameter is used as follows.
146 .RS 3
147 .bP
148 It is assumed to be the address of a pointer to a buffer managed by the
149 calling application.
150 .bP
151 However,
152 \fI\%ncurses\fP checks to ensure that
153 .I area
154 is not
155 .BR NULL ,
156 and also that the resulting buffer pointer is not
157 .BR NULL .
158 If either check fails,
159 .I area
160 is ignored.
161 .bP
162 If the checks succeed,
163 \fI\%ncurses\fP also copies the return value to the buffer pointed to by
164 \fIarea\fP,
165 and the library updates
166 .I area
167 to point past the null character terminating this value.
168 .bP
169 The return value itself is an address in the terminal type description
170 loaded into memory.
171 .RE
172 .SS "Applying String Capabilities"
173 String capabilities can be parameterized;
174 see subsection \*(``Parameterized Strings\*('' in  \fB\%terminfo\fP(5).
175 \fB\%tgoto\fP applies its second and third arguments to the parametric
176 placeholders in the capability stored in the first argument.
177 .bP
178 The capability may contain padding specifications;
179 see subsection \*(``Delays and Padding\*('' of \fB\%terminfo\fP(5).
180 The output of \fB\%tgoto\fP should thus be passed to \fB\%tputs\fP
181 rather than some other output function such as \fI\%printf\fP(3).
182 .bP
183 While \fB\%tgoto\fP is assumed to be used for the two-parameter
184 cursor positioning capability,
185 \fItermcap\fP applications also use it for single-parameter
186 capabilities.
187 .IP
188 Doing so reveals a quirk in \fB\%tgoto\fP:
189 most hardware terminals use cursor addressing with \fIrow\fP first,
190 but the original developers of the \fItermcap\fP interface chose to
191 put the \fIcol\fP (column) parameter first.
192 The \fB\%tgoto\fP function swaps the order of parameters.
193 It does this even for calls requiring only a single parameter.
194 In that case,
195 the first parameter is merely a placeholder.
196 .bP
197 Normally the \fI\%ncurses\fP library is compiled without
198 full \fI\%term\%cap\fP support.
199 In that case,
200 \fB\%tgoto\fP uses an internal version of \fB\%tparm\fP(3X)
201 (a more capable function).
202 .IP
203 Because it uses \fB\%tparm\fP internally,
204 \fB\%tgoto\fP is able to use some \fI\%term\%info\fP features,
205 but not all.
206 In particular,
207 it allows only numeric parameters;
208 \fB\%tparm\fP supports string parameters.
209 .IP
210 However,
211 \fB\%tparm\fP is not a \fItermcap\fP feature,
212 and portable \fItermcap\fP applications should not rely upon its
213 availability.
214 .PP
215 \fB\%tputs\fP is described in \fB\%curs_terminfo\fP(3X).
216 It can retrieve capabilities by either \fItermcap\fP or
217 \fI\%term\%info\fP name.
218 .SS "Global Variables"
219 The variables
220 \fBPC\fP,
221 \fBUP\fP and
222 \fBBC\fP
223 are set by \fB\%tgetent\fP to the \fI\%term\%info\fP entry's data for
224 \fB\%pad_char\fP,
225 \fB\%cursor_up\fP and
226 \fB\%backspace_if_not_bs\fP,
227 respectively.
228 \fBUP\fP is not used by \fI\%ncurses\fP.
229 \fBPC\fP is used by \fB\%delay_output\fP(3X).
230 \fBBC\fP is used by \fB\%tgoto\fP emulation.
231 The variable \fB\%ospeed\fP is set by \fI\%ncurses\fP using a
232 system-specific encoding to indicate the terminal's data rate.
233 .SS "Releasing Memory"
234 The \fItermcap\fP functions provide no means of freeing memory,
235 because legacy \fItermcap\fP implementations used only the buffer
236 areas provided by the caller via \fB\%tgetent\fP and \fB\%tgetstr\fP.
237 Those buffers are unused in \fI\%term\%info\fP.
238 .PP
239 By contrast,
240 \fI\%term\%info\fP allocates memory.
241 It uses \fB\%setupterm\fP(3X) to obtain the data used by \fB\%tgetent\fP
242 and the functions that retrieve capability values.
243 One could use
244 .RS
245 .EX
246 del_curterm(cur_term);
247 .EE
248 .RE
249 to free this memory,
250 but there is an additional complication with \fI\%ncurses\fP.
251 It uses a fixed-size pool of storage locations,
252 one per value of the \fITERM\fP environment variable when
253 \fB\%tgetent\fP is called.
254 The \fBscreen\fP(1) program relies upon this arrangement to improve its
255 performance.
256 .PP
257 An application that uses only the \fItermcap\fP functions,
258 not the higher level
259 .I \%curses
260 API,
261 could release the memory using \fB\%del_curterm\fP(3X),
262 because the pool is freed using other functions;
263 see \fB\%curs_memleaks\fP(3X).
264 .SH "RETURN VALUE"
265 The return values of
266 \fB\%tgetent\fP,
267 \fB\%tgetflag\fP,
268 \fB\%tgetname\fP,
269 and
270 \fB\%tgetstr\fP
271 are documented above.
272 .PP
273 \fB\%tgoto\fP returns
274 .B NULL
275 on error.
276 Error conditions include:
277 .bP
278 uninitialized state
279 (\fB\%tgetent\fP was not called successfully),
280 .bP
281 .I cap
282 being a null pointer,
283 .bP
284 .I cap
285 referring to a canceled capability,
286 .bP
287 .I cap
288 being a capability with string-valued parameters
289 (a \fI\%term\%info\fP-only feature),
290 and
291 .bP
292 .I cap
293 being a capability with more than two parameters.
294 .PP
295 See \fB\%curs_terminfo\fP(3X) regarding \fB\%tputs\fP.
296 .SH NOTES
297 \fI\%ncurses\fP compares only the first two characters of the \fIid\fP
298 parameter of
299 \fB\%tgetflag\fP,
300 \fB\%tgetnum\fP,
301 and
302 \fB\%tgetstr\fP to the capability names in the database.
303 .SH PORTABILITY
304 These functions are no longer standardized
305 (and the variables never were);
306 \fI\%ncurses\fP provides them to support legacy applications.
307 They should not be used in new programs.
308 .SS Standards
309 .bP
310 X/Open Curses, Issue 4, Version 2 (1996),
311 describes these functions.
312 However,
313 they are marked
314 \*(``TO BE WITHDRAWN\*(''.
315 .bP
316 X/Open Curses, Issue 7 (2009) marked the \fItermcap\fP interface
317 (along with \fB\%vwprintw\fP and \fB\%vwscanw\fP) as withdrawn.
318 .PP
319 Neither X/Open Curses nor the SVr4 man pages documented the return
320 values of \fB\%tgetent\fP correctly,
321 though all three were in fact returned ever since SVr1.
322 In particular,
323 an omission in the X/Open Curses specification has been misinterpreted
324 to mean that \fB\%tgetent\fP returns \fBOK\fP or \fBERR\fP.
325 Because the purpose of these functions is to provide compatibility with
326 the \fItermcap\fP library,
327 that is a defect in X/Open Curses, Issue 4, Version 2
328 rather than in \fI\%ncurses\fP.
329 .SS "Compatibility with BSD \fItermcap\fP"
330 Externally visible variables are provided for support of certain
331 \fItermcap\fP applications.
332 However,
333 their correct usage is poorly documented;
334 for example,
335 it is unclear when reading and writing them is meaningful.
336 In particular,
337 some applications are reported to declare and/or modify \fB\%ospeed\fP.
338 .PP
339 The constraint that only the first two characters of the \fIid\fP
340 parameter are used escapes many application developers.
341 The BSD \fItermcap\fP library did not require a trailing null character
342 on the capability identifier passed to \fB\%tgetstr\fP,
343 \fB\%tgetnum\fP,
344 and
345 \fB\%tgetflag\fP.
346 .\" See <https://minnie.tuhs.org/cgi-bin/utree.pl?file=2BSD/src/\
347 .\"   termlib/termcap.c>.
348 Some applications thus assume that the \fItermcap\fP interface does not
349 require the trailing null character for the capability identifier.
350 .bP
351 .I \%ncurses
352 disallows matches by the \fItermcap\fP interface against extended
353 capability names that are longer than two characters;
354 see \fB\%user_caps\fP(5).
355 .PP
356 The BSD \fItermcap\fP function \fB\%tgetent\fP returns the text of a
357 \fItermcap\fP entry in the buffer passed as an argument.
358 This library,
359 like other \fI\%term\%info\fP implementations,
360 does not store terminal type descriptions as text.
361 It sets the buffer contents to a null-terminated string.
362 .SS "Header File"
363 This library includes a \fI\%termcap.h\fP header for compatibility with
364 other implementations,
365 but the header is rarely used because the other implementations are not
366 strictly compatible.
367 .SH HISTORY
368 .\" See https://www.oreilly.com/openbook/opensources/book/kirkmck.html
369 .\" for much BSD release history.
370 Bill Joy originated a forerunner of \fItermcap\fP called
371 \*(``ttycap\*('',
372 dated September 1977,
373 and released in 1BSD
374 (March 1978).
375 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=1BSD/s7/ttycap.c
376 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=1BSD/man7/ttycap.7
377 It used many of the same function names as the later \fItermcap\fP,
378 such as
379 \fB\%tgetent\fP,
380 \fB\%tgetflag\fP,
381 \fB\%tgetnum\fP,
382 and
383 \fB\%tgetstr\fP.
384 .PP
385 A clear descendant,
386 the \fItermlib\fP library,
387 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=2BSD/src/termlib/
388 followed in 2BSD
389 (May 1979),
390 adding \fB\%tgoto\fP and \fB\%tputs\fP.
391 The former applied at that time only to cursor positioning capabilities,
392 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=2BSD/bin/etc/termcap
393 thus the overly specific name.
394 Little changed in 3BSD
395 (late 1979)
396 except the addition of test programs and a \fI\%termlib\fP man page,
397 which documented the API shown in section \*(``SYNOPSIS\*('' above.
398 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=3BSD/usr/src/lib/\
399 .\"   libtermlib/
400 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=3BSD/usr/man/man3/\
401 .\"   termlib.3
402 .PP
403 4BSD
404 (November 1980)
405 renamed \fItermlib\fP to \fItermcap\fP
406 .\" ...except in the source tree...
407 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=4BSD/usr/src/lib/\
408 .\"   libtermlib/makefile
409 and added another test program.
410 The library remained much the same though 4.3BSD
411 (June 1986).
412 4.4BSD-Lite
413 (June 1994)
414 refactored it
415 .\" Observe the `tncktc()`, `tnamatch()`, `tskip()`, and `tdecode()`
416 .\" entry points disappearing from termcap.c.
417 but left the API unchanged.
418 .PP
419 Function prototypes were a feature of the forthcoming ANSI C (1989).
420 Thus the library provided no header file declaring them.
421 Nevertheless,
422 the BSD sources included two different \fI\%termcap.h\fP header files
423 over time.
424 .bP
425 One was used internally by \fBjove\fP(1) from 4.3BSD onward.
426 .\" 2BSD became a branch retaining support for non-virtual memory
427 .\" systems (like the PDP-11) whereas most BSD development focused on
428 .\" the VAX and other VM-enabled systems starting with 3BSD.
429 .\"
430 .\" This man page previously located a termcap.h in 2BSD, but that may
431 .\" be confusion arising from its backport to 2.9BSD (and still present
432 .\" in surviving sources for 2.11BSD, the "end of the line" for that
433 .\" branch's development).
434 .\"
435 .\" Observe the copyright notice in
436 .\"   https://minnie.tuhs.org/cgi-bin/utree.pl?file=4.3BSD/usr/contrib/\
437 .\"     jove/Makefile
438 .\" --much too late for 2BSD (1979).
439 It delcared global symbols for the \fItermcap\fP variables that it used.
440 .bP
441 The other appeared in 4.4BSD-Lite Release 2
442 (June 1995)
443 as part of \fIlibedit\fP
444 (also known as the \fI\%edit\%line\fP library).
445 CSRG source history shows that this was added in mid-1992.
446 The \fIlibedit\fP header file was used internally as a convenience for
447 compiling the \fI\%edit\%line\fP library.
448 It declared function prototypes,
449 but no global variables.
450 This header file was added to NetBSD's \fItermcap\fP library in
451 mid-1994.
452 .PP
453 Meanwhile,
454 GNU \fItermcap\fP began development in 1990.
455 Its first release (1.0) in 1991 included a \fI\%termcap.h\fP header.
456 Its second (1.1) in September 1992 modified the header to use
457 \fIconst\fP for the function prototypes in the header where one would
458 expect the parameters to be read-only.
459 BSD \fItermcap\fP did not.
460 The prototype for \fB\%tputs\fP also differed,
461 but in that instance,
462 it was \fIlibedit\fP that differed from BSD \fItermcap\fP.
463 .PP
464 GNU \fItermcap\fP 1.3 was bundled with \fIbash\fP in mid-1993 to support
465 the \fBreadline\fP(3) library.
466 .PP
467 \fI\%ncurses\fP 1.8.1
468 (November 1993)
469 provided a \fI\%termcap.h\fP file.
470 It reflected influence from GNU \fItermcap\fP and \fBemacs\fP(1)
471 (rather than \fBjove\fP(1)),
472 providing the following interface:
473 .bP
474 global symbols used by \fIemacs\fP,
475 .bP
476 \fIconst\fP-qualified function prototypes,
477 and
478 .bP
479 a prototype for \fBtparam\fP,
480 a GNU \fItermcap\fP feature.
481 .PP
482 Later
483 (in mid-1996)
484 the \fB\%tparam\fP function was removed from \fI\%ncurses\fP.
485 Any two of the four implementations thus differ,
486 and programs that intend to work with all \fItermcap\fP library
487 interfaces must account for that fact.
488 .SH BUGS
489 If you call \fB\%tgetstr\fP to fetch \fB\%ca\fP or any other
490 parameterized string capability,
491 be aware that it is returned in \fI\%term\%info\fP notation,
492 not the older and not-quite-compatible \fItermcap\fP notation.
493 This does not cause problems if all you do with it is call \fB\%tgoto\fP
494 or \fB\%tparm\fP,
495 which both expand \fI\%term\%info\fP-style strings as \fI\%term\%info\fP
496 does.
497 (If
498 .I \%ncurses
499 is configured to support \fItermcap,\fP
500 \fB\%tgoto\fP checks whether the string is \fI\%term\%info\fP-style by
501 looking for \*(``\fB%p\fP\*('' parameters or
502 \*(``\fB<\fP.\|.\|.\fB>\fP\*('' delays,
503 and invokes a \fItermcap\fP-style parser if the string appears not to
504 use \fI\%term\%info\fP syntax.)
505 .PP
506 Because \fI\%term\%info\fP's syntax for padding in string capabilities
507 differs from \fItermcap\fP's,
508 users can be surprised.
509 .IP \(bu 4
510 \fB\%tputs("50")\fP in a \fI\%term\%info\fP system transmits
511 \*(``50\*('' rather than busy-waiting for 50 milliseconds.
512 .IP \(bu 4
513 However,
514 if \fI\%ncurses\fP is configured to support \fItermcap\fP,
515 it may also have been configured to support BSD-style padding.
516 .IP
517 In that case,
518 \fB\%tputs\fP inspects strings passed to it,
519 looking for digits at the beginning of the string.
520 .IP
521 \fB\%tputs("50")\fP in a \fItermcap\fP system may busy-wait for 50
522 milliseconds rather than transmitting \*(``50\*(''.
523 .PP
524 \fItermcap\fP has nothing analogous to \fI\%term\%info\fP's \fBsgr\fP
525 string.
526 One consequence is that \fItermcap\fP applications assume that
527 .RB \*(`` me \*(''
528 (equivalent to \fI\%term\%info\fP's \fBsgr0\fP capability)
529 does not reset the alternate character set.
530 \fI\%ncurses\fP checks for,
531 and modifies the data shared with,
532 the \fItermcap\fP interface to accommodate the latter's limitation in
533 this respect.
534 .SH "SEE ALSO"
535 \fB\%curses\fP(3X),
536 \fB\%curs_terminfo\fP(3X),
537 \fB\%putc\fP(3),
538 \fB\%term_variables\fP(3X),
539 \fB\%terminfo\fP(5)
540 .PP
541 https://invisible\-island.net/ncurses/tctest.html