1 .\"***************************************************************************
2 .\" Copyright 2018-2022,2023 Thomas E. Dickey *
3 .\" Copyright 1998-2017,2018 Free Software Foundation, Inc. *
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: *
13 .\" The above copyright notice and this permission notice shall be included *
14 .\" in all copies or substantial portions of the Software. *
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. *
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 *
28 .\"***************************************************************************
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"
59 \fIcurses\fR emulation of \fItermcap\fR
62 \fB#include <curses.h>
68 \fB@NCURSES_OSPEED@ ospeed;
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));
79 provides the foregoing variables and functions as a compatibility layer
80 for programs that use the \fItermcap\fP library.
82 but behavior is emulated using the \fI\%term\%info\fP database.
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.
87 \fB\%tgetent\fP loads the terminal database entry for \fIname\fP;
89 This must be done before calling any of the other functions.
92 .TP 5 \" "-1" + 2n + adjust for PDF
97 if there is no such entry
98 (or if the matching entry describes a generic terminal,
99 having too little information for
101 applications to run),
105 if the \fI\%term\%info\fP database could not be found.
108 This implementation differs from those of historical \fItermcap\fP
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.
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
127 nor whether the terminal type description supports an addressable
129 a property essential for any \fIcurses\fP implementation to operate.
131 .SS "Retrieving Capability Values"
132 \fB\%tgetflag\fP reports the Boolean entry for \fIid\fP,
133 or zero if it is not available.
135 \fB\%tgetnum\fP obtains the numeric entry for \fIid\fP,
136 or \-1 if it is not available.
138 \fB\%tgetstr\fP returns the string entry for \fIid\fP,
141 if it is not available.
142 Use \fB\%tputs\fP to output the string returned.
145 parameter is used as follows.
148 It is assumed to be the address of a pointer to a buffer managed by the
152 \fI\%ncurses\fP checks to ensure that
156 and also that the resulting buffer pointer is not
158 If either check fails,
162 If the checks succeed,
163 \fI\%ncurses\fP also copies the return value to the buffer pointed to by
165 and the library updates
167 to point past the null character terminating this value.
169 The return value itself is an address in the terminal type description
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.
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).
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
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.
195 the first parameter is merely a placeholder.
197 Normally the \fI\%ncurses\fP library is compiled without
198 full \fI\%termcap\fP support.
200 \fB\%tgoto\fP uses an internal version of \fB\%tparm\fP(3X)
201 (a more capable function).
203 Because it uses \fB\%tparm\fP internally,
204 \fB\%tgoto\fP is able to use some \fI\%term\%info\fP features,
207 it allows only numeric parameters;
208 \fB\%tparm\fP supports string parameters.
211 \fB\%tparm\fP is not a \fItermcap\fP feature,
212 and portable \fItermcap\fP applications should not rely upon its
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"
223 are set by \fB\%tgetent\fP to the \fI\%term\%info\fP entry's data for
225 \fB\%cursor_up\fP and
226 \fB\%backspace_if_not_bs\fP,
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.
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.
246 del_curterm(cur_term);
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
256 An application that uses only the \fItermcap\fP functions,
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).
270 are documented above.
272 \fB\%tgoto\fP returns
275 Error conditions include:
278 (\fB\%tgetent\fP was not called successfully),
281 being a null pointer,
284 referring to a canceled capability,
287 being a capability with string-valued parameters
288 (a \fI\%term\%info\fP-only feature),
292 being a capability with more than two parameters.
294 See \fB\%curs_terminfo\fP(3X) regarding \fB\%tputs\fP.
296 \fI\%ncurses\fP compares only the first two characters of the \fIid\fP
301 \fB\%tgetstr\fP to the capability names in the database.
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.
309 X/Open Curses, Issue 4, Version 2 (1996),
310 describes these functions,
312 \*(``TO BE WITHDRAWN\*(''.
314 X/Open Curses, Issue 7 (2009) marks the \fItermcap\fP interface
315 (along with \fB\%vwprintw\fP and \fB\%vwscanw\fP) as withdrawn.
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.
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.
331 their correct usage is poorly documented;
333 it is unclear when reading and writing them is meaningful.
335 some applications are reported to declare and/or modify \fB\%ospeed\fP.
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,
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.
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).
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.
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.
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
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
370 dated September 1977,
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,
384 the \fItermlib\fP library,
385 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=2BSD/src/termlib/
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
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/\
398 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=3BSD/usr/man/man3/\
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
413 .\" Observe the `tncktc()`, `tnamatch()`, `tskip()`, and `tdecode()`
414 .\" entry points disappearing from termcap.c.
415 leaving the API unchanged.
417 Function prototypes were a feature of ANSI C (1989).
418 Thus the library itself provided no header file declaring them.
420 the BSD sources included two different \fI\%termcap.h\fP header files
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.
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).
433 .\" Observe the copyright notice in
434 .\" https://minnie.tuhs.org/cgi-bin/utree.pl?file=4.3BSD/usr/contrib/\
436 .\" --much too late for 2BSD (1979).
437 It delcared global symbols for the \fItermcap\fP variables that it used.
439 The other appeared in 4.4BSD-Lite Release 2
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
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.
462 GNU \fItermcap\fP 1.3 was bundled with \fIbash\fP(1) in mid-1993 to
463 support the \fI\%readline\fP(3) library.
465 \fI\%ncurses\fP 1.8.1
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:
472 global symbols used by \fIemacs\fP,
474 \fIconst\fP-qualified function prototypes,
477 a prototype for \fBtparam\fP,
478 a GNU \fItermcap\fP feature.
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.
487 If you call \fB\%tgetstr\fP to fetch
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
495 which both expand \fI\%term\%info\fP-style strings as \fI\%term\%info\fP
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.)
506 Because \fI\%term\%info\fP's syntax for padding in string capabilities
507 differs from \fItermcap\fP's,
508 users can be surprised.
510 \fB\%tputs("50")\fP in a \fI\%term\%info\fP system transmits
511 \*(``50\*('' rather than busy-waiting for 50 milliseconds.
514 if \fI\%ncurses\fP is configured to support \fItermcap\fP,
515 it may also have been configured to support BSD-style padding.
518 \fB\%tputs\fP inspects strings passed to it,
519 looking for digits at the beginning of the string.
521 \fB\%tputs("50")\fP in a \fItermcap\fP system may busy-wait for 50
522 milliseconds rather than transmitting \*(``50\*(''.
524 \fItermcap\fP has nothing analogous to \fI\%term\%info\fP's
528 One consequence is that \fItermcap\fP applications assume that
530 (equivalent to \fI\%term\%info\fP's
531 .B \%exit_attribute_mode
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
541 \fB\%curs_terminfo\fP(3X),
543 \fB\%term_variables\fP(3X),
546 https://invisible\-island.net/ncurses/tctest.html