]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_termcap.3x
ncurses 6.4 - patch 20231223
[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.80 2023/12/23 20:19:05 tom Exp $
31 .TH curs_termcap 3X 2023-12-23 "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 5 \" "-1" + 2n + adjust for PDF
93 1
94 on success,
95 .TP
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
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 includes the
124 .B \%generic
125 .RB ( gn )
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 its 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\%termcap\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 code.
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 terminal name parameter given to \fB\%tgetent\fP.
253 The \fIscreen\fP(1) program relies upon this arrangement to improve its
254 performance.
255 .PP
256 An application that uses only the \fItermcap\fP functions,
257 not the higher level
258 .I \%curses
259 API,
260 could release the memory using \fB\%del_curterm\fP(3X),
261 because the pool is freed using other functions;
262 see \fB\%curs_memleaks\fP(3X).
263 .SH "RETURN VALUE"
264 The return values of
265 \fB\%tgetent\fP,
266 \fB\%tgetflag\fP,
267 \fB\%tgetname\fP,
268 and
269 \fB\%tgetstr\fP
270 are documented above.
271 .PP
272 \fB\%tgoto\fP returns
273 .B NULL
274 on error.
275 Error conditions include:
276 .bP
277 uninitialized state
278 (\fB\%tgetent\fP was not called successfully),
279 .bP
280 .I cap
281 being a null pointer,
282 .bP
283 .I cap
284 referring to a canceled capability,
285 .bP
286 .I cap
287 being a capability with string-valued parameters
288 (a \fI\%term\%info\fP-only feature),
289 and
290 .bP
291 .I cap
292 being a capability with more than two parameters.
293 .PP
294 See \fB\%curs_terminfo\fP(3X) regarding \fB\%tputs\fP.
295 .SH NOTES
296 \fI\%ncurses\fP compares only the first two characters of the \fIid\fP
297 parameter of
298 \fB\%tgetflag\fP,
299 \fB\%tgetnum\fP,
300 and
301 \fB\%tgetstr\fP to the capability names in the database.
302 .SH PORTABILITY
303 These functions are no longer standardized
304 (and the variables never were);
305 \fI\%ncurses\fP provides them to support legacy applications.
306 They should not be used in new programs.
307 .SS Standards
308 .bP
309 X/Open Curses, Issue 4, Version 2 (1996),
310 describes these functions,
311 marking them as
312 \*(``TO BE WITHDRAWN\*(''.
313 .bP
314 X/Open Curses, Issue 7 (2009) marks the \fItermcap\fP interface
315 (along with \fB\%vwprintw\fP and \fB\%vwscanw\fP) as withdrawn.
316 .PP
317 Neither X/Open Curses nor the SVr4 man pages documented the return
318 values of \fB\%tgetent\fP correctly,
319 though all three shown here were in fact returned ever since SVr1.
320 In particular,
321 an omission in the X/Open Curses specification has been misinterpreted
322 to mean that \fB\%tgetent\fP returns \fBOK\fP or \fBERR\fP.
323 Because the purpose of these functions is to provide compatibility with
324 the \fItermcap\fP library,
325 that is a defect in X/Open Curses, Issue 4, Version 2
326 rather than in \fI\%ncurses\fP.
327 .SS "Compatibility with BSD \fItermcap\fP"
328 Externally visible variables are provided for support of certain
329 \fItermcap\fP applications.
330 However,
331 their correct usage is poorly documented;
332 for example,
333 it is unclear when reading and writing them is meaningful.
334 In particular,
335 some applications are reported to declare and/or modify \fB\%ospeed\fP.
336 .PP
337 The constraint that only the first two characters of the \fIid\fP
338 parameter are used escapes many application developers.
339 The BSD \fItermcap\fP library did not require a trailing null character
340 on the capability identifier passed to \fB\%tgetstr\fP,
341 \fB\%tgetnum\fP,
342 and
343 \fB\%tgetflag\fP.
344 .\" See <https://minnie.tuhs.org/cgi-bin/utree.pl?file=2BSD/src/\
345 .\"   termlib/termcap.c>.
346 Some applications thus assume that the \fItermcap\fP interface does not
347 require the trailing null character for the capability identifier.
348 .bP
349 .I \%ncurses
350 disallows matches by the \fItermcap\fP interface against extended
351 capability names that are longer than two characters;
352 see \fB\%user_caps\fP(5).
353 .PP
354 The BSD \fItermcap\fP function \fB\%tgetent\fP returns the text of a
355 \fItermcap\fP entry in the buffer passed as an argument.
356 This library,
357 like other \fI\%term\%info\fP implementations,
358 does not store terminal type descriptions as text.
359 It sets the buffer contents to a null-terminated string.
360 .SS "Header File"
361 This library includes a \fI\%termcap.h\fP header for compatibility with
362 other implementations,
363 but the header is rarely used because the other implementations are not
364 strictly compatible.
365 .SH HISTORY
366 .\" See https://www.oreilly.com/openbook/opensources/book/kirkmck.html
367 .\" for much BSD release history.
368 Bill Joy originated a forerunner of \fItermcap\fP called
369 \*(``ttycap\*('',
370 dated September 1977,
371 and released in 1BSD
372 (March 1978).
373 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=1BSD/s7/ttycap.c
374 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=1BSD/man7/ttycap.7
375 It used many of the same function names as the later \fItermcap\fP,
376 such as
377 \fB\%tgetent\fP,
378 \fB\%tgetflag\fP,
379 \fB\%tgetnum\fP,
380 and
381 \fB\%tgetstr\fP.
382 .PP
383 A clear descendant,
384 the \fItermlib\fP library,
385 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=2BSD/src/termlib/
386 followed in 2BSD
387 (May 1979),
388 adding \fB\%tgoto\fP and \fB\%tputs\fP.
389 The former applied at that time only to cursor positioning capabilities,
390 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=2BSD/bin/etc/termcap
391 thus the overly specific name.
392 Little changed in 3BSD
393 (late 1979)
394 except the addition of test programs and a \fI\%termlib\fP man page,
395 which documented the API shown in section \*(``SYNOPSIS\*('' above.
396 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=3BSD/usr/src/lib/\
397 .\"   libtermlib/
398 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=3BSD/usr/man/man3/\
399 .\"   termlib.3
400 .PP
401 4BSD
402 (November 1980)
403 renamed \fItermlib\fP to \fItermcap\fP
404 .\" ...except in the source tree...
405 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=4BSD/usr/src/lib/\
406 .\"   libtermlib/makefile
407 and added another test program.
408 The library remained much the same though 4.3BSD
409 (June 1986).
410 4.4BSD-Lite
411 (June 1994)
412 refactored it,
413 .\" Observe the `tncktc()`, `tnamatch()`, `tskip()`, and `tdecode()`
414 .\" entry points disappearing from termcap.c.
415 leaving the API unchanged.
416 .PP
417 Function prototypes were a feature of ANSI C (1989).
418 Thus the library itself provided no header file declaring them.
419 Nevertheless,
420 the BSD sources included two different \fI\%termcap.h\fP header files
421 over time.
422 .bP
423 One was used internally by \fBjove\fP(1) from 4.3BSD onward.
424 .\" 2BSD became a branch retaining support for non-virtual memory
425 .\" systems (such as the PDP-11) whereas most BSD development focused on
426 .\" the VAX and other VM-enabled systems starting with 3BSD.
427 .\"
428 .\" This man page previously located a termcap.h in 2BSD, but that may
429 .\" be confusion arising from its backport to 2.9BSD (and still present
430 .\" in surviving sources for 2.11BSD, the "end of the line" for that
431 .\" branch's development).
432 .\"
433 .\" Observe the copyright notice in
434 .\"   https://minnie.tuhs.org/cgi-bin/utree.pl?file=4.3BSD/usr/contrib/\
435 .\"     jove/Makefile
436 .\" --much too late for 2BSD (1979).
437 It delcared global symbols for the \fItermcap\fP variables that it used.
438 .bP
439 The other appeared in 4.4BSD-Lite Release 2
440 (June 1995)
441 as part of \fIlibedit\fP
442 (also known as the \fI\%edit\%line\fP library).
443 CSRG source history shows that this was added in mid-1992.
444 The \fIlibedit\fP header file was used internally as a convenience for
445 compiling the \fI\%edit\%line\fP library.
446 It declared function prototypes,
447 but no global variables.
448 This header file was added to NetBSD's \fItermcap\fP library in
449 mid-1994.
450 .PP
451 Meanwhile,
452 GNU \fItermcap\fP began development in 1990.
453 Its first release (1.0) in 1991 included a \fI\%termcap.h\fP header.
454 Its second (1.1) in September 1992 modified the header to use
455 \fIconst\fP for the function prototypes in the header where one would
456 expect the parameters to be read-only.
457 BSD \fItermcap\fP did not.
458 The prototype for \fB\%tputs\fP also differed,
459 but in that instance,
460 it was \fIlibedit\fP that differed from BSD \fItermcap\fP.
461 .PP
462 GNU \fItermcap\fP 1.3 was bundled with \fIbash\fP(1) in mid-1993 to
463 support the \fI\%readline\fP(3) library.
464 .PP
465 \fI\%ncurses\fP 1.8.1
466 (November 1993)
467 provided a \fI\%termcap.h\fP file.
468 It reflected influence from GNU \fItermcap\fP and \fBemacs\fP(1)
469 (rather than \fBjove\fP(1)),
470 providing the following interface:
471 .bP
472 global symbols used by \fIemacs\fP,
473 .bP
474 \fIconst\fP-qualified function prototypes,
475 and
476 .bP
477 a prototype for \fBtparam\fP,
478 a GNU \fItermcap\fP feature.
479 .PP
480 Later
481 (in mid-1996)
482 the \fB\%tparam\fP function was removed from \fI\%ncurses\fP.
483 Any two of the four implementations thus differ,
484 and programs that intend to work with all \fItermcap\fP library
485 interfaces must account for that fact.
486 .SH BUGS
487 If you call \fB\%tgetstr\fP to fetch
488 .B \%column_address
489 .RB ( ch )
490 or any other 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
525 .B \%set_attributes
526 .RB ( sgr )
527 capability.
528 One consequence is that \fItermcap\fP applications assume that
529 .RB \*(`` me \*(''
530 (equivalent to \fI\%term\%info\fP's
531 .B \%exit_attribute_mode
532 .RB ( sgr0 )
533 capability)
534 does not reset the alternate character set.
535 \fI\%ncurses\fP checks for,
536 and modifies the data shared with,
537 the \fItermcap\fP interface to accommodate the latter's limitation in
538 this respect.
539 .SH "SEE ALSO"
540 \fB\%curses\fP(3X),
541 \fB\%curs_terminfo\fP(3X),
542 \fB\%putc\fP(3),
543 \fB\%term_variables\fP(3X),
544 \fB\%terminfo\fP(5)
545 .PP
546 https://invisible\-island.net/ncurses/tctest.html