jcs's openbsd hax
openbsd
at jcs 389 lines 16 kB view raw
1.\" $OpenBSD: termcap.3,v 1.10 2023/10/17 09:52:08 nicm Exp $ 2.\" 3.\"*************************************************************************** 4.\" Copyright 2018-2022,2023 Thomas E. Dickey * 5.\" Copyright 1998-2017,2018 Free Software Foundation, Inc. * 6.\" * 7.\" Permission is hereby granted, free of charge, to any person obtaining a * 8.\" copy of this software and associated documentation files (the * 9.\" "Software"), to deal in the Software without restriction, including * 10.\" without limitation the rights to use, copy, modify, merge, publish, * 11.\" distribute, distribute with modifications, sublicense, and/or sell * 12.\" copies of the Software, and to permit persons to whom the Software is * 13.\" furnished to do so, subject to the following conditions: * 14.\" * 15.\" The above copyright notice and this permission notice shall be included * 16.\" in all copies or substantial portions of the Software. * 17.\" * 18.\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 19.\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 20.\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 21.\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 22.\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 23.\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 24.\" THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 25.\" * 26.\" Except as contained in this notice, the name(s) of the above copyright * 27.\" holders shall not be used in advertising or otherwise to promote the * 28.\" sale, use or other dealings in this Software without prior written * 29.\" authorization. * 30.\"*************************************************************************** 31.\" 32.\" $Id: termcap.3,v 1.10 2023/10/17 09:52:08 nicm Exp $ 33.TH termcap 3 2023-07-01 "ncurses 6.4" "Library calls" 34.ie \n(.g .ds `` \(lq 35.el .ds `` `` 36.ie \n(.g .ds '' \(rq 37.el .ds '' '' 38.de bP 39.ie n .IP \(bu 4 40.el .IP \(bu 2 41.. 42.na 43.hy 0 44.ds n 5 45.SH NAME 46\fBPC\fP, 47\fBUP\fP, 48\fBBC\fP, 49\fBospeed\fP, 50\fBtgetent\fP, 51\fBtgetflag\fP, 52\fBtgetnum\fP, 53\fBtgetstr\fP, 54\fBtgoto\fP, 55\fBtputs\fP \- \fBcurses\fP emulation of termcap 56.ad 57.hy 58.SH SYNOPSIS 59\fB#include <curses.h>\fP 60.br 61\fB#include <term.h>\fP 62.sp 63\fBextern char PC;\fP 64.br 65\fBextern char * UP;\fP 66.br 67\fBextern char * BC;\fP 68.br 69\fBextern int ospeed;\fP 70.sp 71\fBint tgetent(char *\fIbp\fB, const char *\fIname\fB);\fR 72.br 73\fBint tgetflag(const char *\fIid\fB);\fR 74.br 75\fBint tgetnum(const char *\fIid\fB);\fR 76.br 77\fBchar *tgetstr(const char *\fIid\fB, char **\fIarea\fB);\fR 78.br 79\fBchar *tgoto(const char *\fIcap\fB, int \fIcol\fB, int \fIrow\fB);\fR 80.br 81\fBint tputs(const char *\fIstr\fB, int \fIaffcnt\fB, int (*\fIputc\fB)(int));\fR 82.SH DESCRIPTION 83These routines are included as a conversion aid for programs that use 84the \fItermcap\fP library. 85Their parameters are the same, but the 86routines are emulated using the \fIterminfo\fP database. 87Thus, they 88can only be used to query the capabilities of entries for which a 89terminfo entry has been compiled. 90.SS Initialization 91The \fBtgetent\fP routine loads the entry for \fIname\fP. 92It returns: 93.RS 3 94.TP 3 951 96on success, 97.TP 3 980 99if there is no such entry 100(or that it is a generic type, having too little information for curses 101applications to run), and 102.TP 3 103\-1 104if the terminfo database could not be found. 105.RE 106.PP 107This differs from the \fItermcap\fP library in two ways: 108.RS 3 109.bP 110The emulation ignores the buffer pointer \fIbp\fP. 111The \fItermcap\fP library would store a copy of the terminal 112description in the area referenced by this pointer. 113However, ncurses stores its terminal descriptions in compiled 114binary form, which is not the same thing. 115.bP 116There is a difference in return codes. 117The \fItermcap\fP library does not check if the terminal 118description is marked with the \fIgeneric\fP capability, 119or if the terminal description has cursor-addressing. 120.RE 121.SS Capability Values 122The \fBtgetflag\fP routine gets the boolean entry for \fIid\fP, 123or zero if it is not available. 124.PP 125The \fBtgetnum\fP routine gets the numeric entry for \fIid\fP, 126or \-1 if it is not available. 127.PP 128The \fBtgetstr\fP routine returns the string entry for \fIid\fP, 129or zero if it is not available. 130Use \fBtputs\fP to output the returned string. 131The \fIarea\fP parameter is used as follows: 132.RS 3 133.bP 134It is assumed to be the address of a pointer to a buffer managed by the 135calling application. 136.bP 137However, ncurses checks to ensure that \fBarea\fP is not NULL, 138and also that the resulting buffer pointer is not NULL. 139If either check fails, the \fIarea\fP parameter is ignored. 140.bP 141If the checks succeed, ncurses also copies the return value to 142the buffer pointed to by \fIarea\fP, 143and the \fIarea\fP value will be updated to point past the null ending 144this value. 145.bP 146The return value itself is an address in the terminal description which 147is loaded into memory. 148.RE 149.PP 150Only the first two characters of the \fBid\fP parameter of 151\fBtgetflag\fP, 152\fBtgetnum\fP and 153\fBtgetstr\fP are compared in lookups. 154.SS Formatting Capabilities 155The \fBtgoto\fP routine expands the given capability using the parameters. 156.bP 157Because the capability may have padding characters, 158the output of \fBtgoto\fP should be passed to \fBtputs\fP 159rather than some other output function such as \fBprintf\fP(3). 160.bP 161While \fBtgoto\fP is assumed to be used for the two-parameter 162cursor positioning capability, 163termcap applications also use it for single-parameter capabilities. 164.IP 165Doing this shows a quirk in \fBtgoto\fP: most hardware 166terminals use cursor addressing with \fIrow\fP first, 167but the original developers of the termcap interface chose to 168put the \fIcolumn\fP parameter first. 169The \fBtgoto\fP function swaps the order of parameters. 170It does this also for calls requiring only a single parameter. 171In that case, the first parameter is merely a placeholder. 172.bP 173Normally the ncurses library is compiled with terminfo support. 174In that case, \fBtgoto\fP uses an internal version of 175\fBtparm\fP(3) (a more capable formatter). 176.IP 177With terminfo support, \fBtgoto\fP is able to use some of the terminfo 178features, but not all. 179In particular, it allows only numeric parameters; 180\fBtparm\fP supports string parameters. 181.IP 182However, \fBtparm\fP is not a \fItermcap\fP feature, 183and portable \fItermcap\fP applications should not rely upon its availability. 184.PP 185The \fBtputs\fP routine is described on the \fBterminfo\fP(3) manual 186page. 187It can retrieve capabilities by either termcap or terminfo name. 188.SS Global Variables 189The variables 190\fBPC\fP, 191\fBUP\fP and 192\fBBC\fP 193are set by \fBtgetent\fP to the terminfo entry's data for 194\fBpad_char\fP, 195\fBcursor_up\fP and 196\fBbackspace_if_not_bs\fP, 197respectively. 198\fBUP\fP is not used by ncurses. 199\fBPC\fP is used in the \fBtdelay_output\fP function. 200\fBBC\fP is used in the \fBtgoto\fP emulation. 201The variable \fBospeed\fP is set by ncurses in a system-specific coding 202to reflect the terminal speed. 203.SS Releasing Memory 204The termcap functions provide no means for freeing memory, 205because legacy termcap implementations used only the buffer 206areas provided by the caller via \fBtgetent\fP and \fBtgetstr\fP. 207Those buffers are unused in terminfo. 208.PP 209On the other hand, terminfo allocates memory. 210It uses \fBsetupterm\fP to retrieve the data used by \fBtgetent\fP 211and the functions which return capability values such as \fBtgetstr\fP. 212One could use 213.sp 214 \fBdel_curterm(cur_term);\fP 215.sp 216.PP 217to free this memory, but there is an additional complication with ncurses. 218It uses a fixed-size \fIpool\fP of storage locations, 219one per setting of the \fBTERM\fP variable when \fBtgetent\fP is called. 220The \fBscreen\fP(1) program relies upon this arrangement, 221to improve its performance. 222.PP 223An application which uses only the low-level termcap functions could 224free the memory using \fBdel_curterm\fP, 225because the pool is freed using other functions 226(see \fBcurs_memleaks\fP(3)). 227. 228.SH RETURN VALUE 229Except where explicitly noted, 230routines that return an integer return \fBERR\fP upon failure and \fBOK\fP 231(SVr4 only specifies "an integer value other than \fBERR\fP") upon successful 232completion. 233.PP 234Routines that return pointers return \fBNULL\fP on error. 235.PP 236A few special cases apply: 237.bP 238If the terminal database has not been initialized, 239these return an error. 240.bP 241The calls with a string parameter (\fBtgoto\fP, \fBtputs\fP) 242check if the string is null, or cancelled. 243Those return an error. 244.bP 245A call to \fBtgoto\fP using a capability with string parameters is an error. 246.bP 247A call to \fBtgoto\fP using a capability with more than two parameters 248is an error. 249.SH BUGS 250If you call \fBtgetstr\fP to fetch \fBca\fP or any other parameterized string, 251be aware that it will be returned in terminfo notation, not the older and 252not-quite-compatible termcap notation. 253This will not cause problems if all 254you do with it is call \fBtgoto\fP or \fBtparm\fP, which both expand 255terminfo-style strings as terminfo. 256(The \fBtgoto\fP function, if configured to support termcap, will check 257if the string is indeed terminfo-style by looking for "%p" parameters or 258"$<..>" delays, and invoke a termcap-style parser if the string does not 259appear to be terminfo). 260.PP 261Because terminfo conventions for representing padding in string capabilities 262differ from termcap's, 263users can be surprised: 264.bP 265\fBtputs("50")\fP in a terminfo system will put out a literal \*(``50\*('' 266rather than busy-waiting for 50 milliseconds. 267.bP 268However, if ncurses is configured to support termcap, 269it may also have been configured to support the BSD-style padding. 270.IP 271In that case, \fBtputs\fP inspects strings passed to it, 272looking for digits at the beginning of the string. 273.IP 274\fBtputs("50")\fP in a termcap system may wait for 50 milliseconds 275rather than put out a literal \*(``50\*('' 276.PP 277Note that termcap has nothing analogous to terminfo's \fBsgr\fP string. 278One consequence of this is that termcap applications assume \fBme\fP 279(terminfo \fBsgr0\fP) does not reset the alternate character set. 280This implementation checks for, and modifies the data shown to the 281termcap interface to accommodate termcap's limitation in this respect. 282.SH PORTABILITY 283.SS Standards 284These functions are provided for supporting legacy applications, 285and should not be used in new programs: 286.bP 287The XSI Curses standard, Issue 4 describes these functions. 288However, they 289are marked TO BE WITHDRAWN and may be removed in future versions. 290.bP 291X/Open Curses, Issue 5 (December 2007) marked the termcap interface 292(along with \fBvwprintw\fP and \fBvwscanw\fP) as withdrawn. 293.PP 294Neither the XSI Curses standard nor the SVr4 man pages documented the return 295values of \fBtgetent\fP correctly, though all three were in fact returned ever 296since SVr1. 297In particular, an omission in the XSI Curses documentation has been 298misinterpreted to mean that \fBtgetent\fP returns \fBOK\fP or \fBERR\fP. 299Because the purpose of these functions is to provide compatibility with 300the \fItermcap\fP library, that is a defect in XCurses, Issue 4, Version 2 301rather than in ncurses. 302.SS Compatibility with BSD Termcap 303External variables are provided for support of certain termcap applications. 304However, termcap applications' use of those variables is poorly documented, 305e.g., not distinguishing between input and output. 306In particular, some applications are reported to declare and/or 307modify \fBospeed\fP. 308.PP 309The comment that only the first two characters of the \fBid\fP parameter 310are used escapes many application developers. 311The original BSD 4.2 termcap library (and historical relics thereof) 312did not require a trailing null NUL on the parameter name passed 313to \fBtgetstr\fP, \fBtgetnum\fP and \fBtgetflag\fP. 314Some applications assume that the termcap interface does not require 315the trailing NUL for the parameter name. 316Taking into account these issues: 317.bP 318As a special case, 319\fBtgetflag\fP matched against a single-character identifier 320provided that was at the end of the terminal description. 321You should not rely upon this behavior in portable programs. 322This implementation disallows matches against single-character capability names. 323.bP 324This implementation disallows matches by the termcap interface against 325extended capability names which are longer than two characters. 326.PP 327The BSD termcap function \fBtgetent\fP returns the text of a termcap 328entry in the buffer passed as an argument. 329This library (like other terminfo implementations) does not store 330terminal descriptions as text. 331It sets the buffer contents to a null-terminated string. 332.SS Other Compatibility 333This library includes a termcap.h header, 334for compatibility with other implementations. 335But the header is rarely used because the other implementations 336are not strictly compatible. 337.PP 338The original BSD termcap (through 4.3BSD) had no header file which 339gave function prototypes, because that was a feature of ANSI C. 340BSD termcap was written several years before C was standardized. 341However, there were two different termcap.h header files in the BSD 342sources: 343.bP 344One was used internally by the \fBjove\fP editor in 2BSD through 4.4BSD. 345It defined global symbols for the termcap variables which it used. 346.bP 347The other appeared in 4.4BSD Lite Release 2 (mid-1993) 348as part of \fIlibedit\fP (also known as the \fIeditline\fP library). 349The CSRG source history shows that this was added in mid-1992. 350The \fIlibedit\fP header file was used internally, 351as a convenience for compiling the \fIeditline\fP library. 352It declared function prototypes, but no global variables. 353.PP 354The header file from \fIlibedit\fP was added to NetBSD's termcap 355library in mid-1994. 356.PP 357Meanwhile, GNU termcap was under development, starting in 1990. 358The first release (termcap 1.0) in 1991 included a termcap.h header. 359The second release (termcap 1.1) in September 1992 modified the 360header to use \fBconst\fP for the function prototypes in the header 361where one would expect the parameters to be read-only. 362This was a difference versus the original BSD termcap. 363The prototype for \fBtputs\fP also differed, 364but in that instance, it was \fIlibedit\fP which differed from BSD termcap. 365.PP 366A copy of GNU termcap 1.3 was bundled with \fIbash\fP in mid-1993, 367to support the \fBreadline\fP(3) library. 368.PP 369A termcap.h file was provided in ncurses 1.8.1 (November 1993). 370That reflected influence by \fBemacs\fP(1) (rather than \fBjove\fP(1)) 371and GNU termcap: 372.bP 373it provided declarations for a few global symbols used by \fBemacs\fP 374.bP 375it provided function prototypes (using \fBconst\fP). 376.bP 377a prototype for \fBtparam\fP (a GNU termcap feature) was provided. 378.PP 379Later (in mid-1996) the \fBtparam\fP function was removed from ncurses. 380As a result, there are differences between any of the four implementations, 381which must be taken into account by programs which can work with all 382termcap library interfaces. 383.SH SEE ALSO 384\fBcurses\fP(3), 385\fBputc\fP(3), 386\fBterm_variables\fP(3), 387\fBterminfo\fP(\*n). 388.sp 389https://invisible-island.net/ncurses/tctest.html