]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_termcap.3x
ncurses 6.2 - patch 20210626
[ncurses.git] / man / curs_termcap.3x
1 .\"***************************************************************************
2 .\" Copyright 2018-2020,2021 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.49 2021/04/03 21:17:09 tom Exp $
31 .TH curs_termcap 3X ""
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 .na
41 .hy 0
42 .ds n 5
43 .SH NAME
44 \fBPC\fR,
45 \fBUP\fR,
46 \fBBC\fR,
47 \fBospeed\fR,
48 \fBtgetent\fR,
49 \fBtgetflag\fR,
50 \fBtgetnum\fR,
51 \fBtgetstr\fR,
52 \fBtgoto\fR,
53 \fBtputs\fR \- \fBcurses\fR emulation of termcap
54 .ad
55 .hy
56 .SH SYNOPSIS
57 \fB#include <curses.h>\fR
58 .br
59 \fB#include <term.h>\fR
60 .sp
61 \fBextern char PC;\fR
62 .br
63 \fBextern char * UP;\fR
64 .br
65 \fBextern char * BC;\fR
66 .br
67 \fBextern @NCURSES_OSPEED@ ospeed;\fR
68 .sp
69 \fBint tgetent(char *\fP\fIbp\fP\fB, const char *\fP\fIname\fP\fB);\fR
70 .br
71 \fBint tgetflag(const char *\fP\fIid\fP\fB);\fR
72 .br
73 \fBint tgetnum(const char *\fP\fIid\fP\fB);\fR
74 .br
75 \fBchar *tgetstr(const char *\fP\fIid\fP\fB, char **\fP\fIarea\fP\fB);\fR
76 .br
77 \fBchar *tgoto(const char *\fP\fIcap\fP\fB, int \fP\fIcol\fP\fB, int \fP\fIrow\fP\fB);\fR
78 .br
79 \fBint tputs(const char *\fP\fIstr\fP\fB, int \fP\fIaffcnt\fP\fB, int (*\fP\fIputc\fP\fB)(int));\fR
80 .br
81 .SH DESCRIPTION
82 These routines are included as a conversion aid for programs that use
83 the \fItermcap\fR library.
84 Their parameters are the same, but the
85 routines are emulated using the \fIterminfo\fR database.
86 Thus, they
87 can only be used to query the capabilities of entries for which a
88 terminfo entry has been compiled.
89 .SS INITIALIZATION
90 .PP
91 The \fBtgetent\fR routine loads the entry for \fIname\fR.
92 It returns:
93 .RS 3
94 .TP 3
95 1
96 on success,
97 .TP 3
98 0
99 if there is no such entry
100 (or that it is a generic type, having too little information for curses
101 applications to run), and
102 .TP 3
103 \-1
104 if the terminfo database could not be found.
105 .RE
106 .PP
107 This differs from the \fItermcap\fP library in two ways:
108 .RS 3
109 .bP
110 The emulation ignores the buffer pointer \fIbp\fR.
111 The \fItermcap\fP library would store a copy of the terminal
112 description in the area referenced by this pointer.
113 However, ncurses stores its terminal descriptions in compiled
114 binary form, which is not the same thing.
115 .bP
116 There is a difference in return codes.
117 The \fItermcap\fP library does not check if the terminal
118 description is marked with the \fIgeneric\fP capability,
119 or if the terminal description has cursor-addressing.
120 .RE
121 .SS CAPABILITY VALUES
122 .PP
123 The \fBtgetflag\fR routine gets the boolean entry for \fIid\fR,
124 or zero if it is not available.
125 .PP
126 The \fBtgetnum\fR routine gets the numeric entry for \fIid\fR,
127 or \-1 if it is not available.
128 .PP
129 The \fBtgetstr\fR routine returns the string entry for \fIid\fR,
130 or zero if it is not available.
131 Use \fBtputs\fR to output the returned string.
132 The \fIarea\fP parameter is used as follows:
133 .RS 3
134 .bP
135 It is assumed to be the address of a pointer to a buffer managed by the
136 calling application.
137 .bP
138 However, ncurses checks to ensure that \fBarea\fP is not NULL,
139 and also that the resulting buffer pointer is not NULL.
140 If either check fails, the \fIarea\fP parameter is ignored.
141 .bP
142 If the checks succeed, ncurses also copies the return value to
143 the buffer pointed to by \fIarea\fR,
144 and the \fIarea\fR value will be updated to point past the null ending
145 this value.
146 .bP
147 The return value itself is an address in the terminal description which
148 is loaded into memory.
149 .RE
150 .PP
151 Only the first two characters of the \fBid\fR parameter of
152 \fBtgetflag\fR,
153 \fBtgetnum\fR and
154 \fBtgetstr\fR are compared in lookups.
155 .SS FORMATTING CAPABILITIES
156 .PP
157 The \fBtgoto\fR routine expands the given capability using the parameters.
158 .bP
159 Because the capability may have padding characters,
160 the output of \fBtgoto\fP should be passed to \fBtputs\fR
161 rather than some other output function such as \fBprintf\fP.
162 .bP
163 While \fBtgoto\fP is assumed to be used for the two-parameter
164 cursor positioning capability,
165 termcap applications also use it for single-parameter capabilities.
166 .IP
167 Doing this shows a quirk in \fBtgoto\fP: most hardware
168 terminals use cursor addressing with \fIrow\fP first,
169 but the original developers of the termcap interface chose to
170 put the \fIcolumn\fP parameter first.
171 The \fBtgoto\fP function swaps the order of parameters.
172 It does this also for calls requiring only a single parameter.
173 In that case, the first parameter is merely a placeholder.
174 .bP
175 Normally the ncurses library is compiled with terminfo support.
176 In that case, \fBtgoto\fP uses \fBtparm\fP(3X) (a more capable formatter).
177 .IP
178 However, \fBtparm\fP is not a \fItermcap\fP feature,
179 and portable \fItermcap\fP applications should not rely upon its availability.
180 .PP
181 The \fBtputs\fR routine is described on the \fBcurs_terminfo\fR(3X) manual
182 page.
183 It can retrieve capabilities by either termcap or terminfo name.
184 .SS GLOBAL VARIABLES
185 .PP
186 The variables
187 \fBPC\fR,
188 \fBUP\fR and
189 \fBBC\fR
190 are set by \fBtgetent\fR to the terminfo entry's data for
191 \fBpad_char\fR,
192 \fBcursor_up\fR and
193 \fBbackspace_if_not_bs\fR,
194 respectively.
195 \fBUP\fR is not used by ncurses.
196 \fBPC\fR is used in the \fBtdelay_output\fR function.
197 \fBBC\fR is used in the \fBtgoto\fR emulation.
198 The variable \fBospeed\fR is set by ncurses in a system-specific coding
199 to reflect the terminal speed.
200 .
201 .SH RETURN VALUE
202 Except where explicitly noted,
203 routines that return an integer return \fBERR\fR upon failure and \fBOK\fR
204 (SVr4 only specifies "an integer value other than \fBERR\fR") upon successful
205 completion.
206 .PP
207 Routines that return pointers return \fBNULL\fR on error.
208 .SH BUGS
209 If you call \fBtgetstr\fR to fetch \fBca\fR or any other parameterized string,
210 be aware that it will be returned in terminfo notation, not the older and
211 not-quite-compatible termcap notation.
212 This will not cause problems if all
213 you do with it is call \fBtgoto\fR or \fBtparm\fR, which both expand
214 terminfo-style strings as terminfo.
215 (The \fBtgoto\fR function, if configured to support termcap, will check
216 if the string is indeed terminfo-style by looking for "%p" parameters or
217 "$<..>" delays, and invoke a termcap-style parser if the string does not
218 appear to be terminfo).
219 .PP
220 Because terminfo conventions for representing padding in string capabilities
221 differ from termcap's,
222 users can be surprised:
223 .bP
224 \fBtputs("50")\fR in a terminfo system will put out a literal \*(``50\*(''
225 rather than busy-waiting for 50 milliseconds.
226 .bP
227 However, if ncurses is configured to support termcap,
228 it may also have been configured to support the BSD-style padding.
229 .IP
230 In that case, \fBtputs\fP inspects strings passed to it,
231 looking for digits at the beginning of the string.
232 .IP
233 \fBtputs("50")\fR in a termcap system may wait for 50 milliseconds
234 rather than put out a literal \*(``50\*(''
235 .PP
236 Note that termcap has nothing analogous to terminfo's \fBsgr\fR string.
237 One consequence of this is that termcap applications assume \fBme\fR
238 (terminfo \fBsgr0\fR) does not reset the alternate character set.
239 This implementation checks for, and modifies the data shown to the
240 termcap interface to accommodate termcap's limitation in this respect.
241 .SH PORTABILITY
242 .SS Standards
243 These functions are provided for supporting legacy applications,
244 and should not be used in new programs:
245 .bP
246 The XSI Curses standard, Issue 4 describes these functions.
247 However, they
248 are marked TO BE WITHDRAWN and may be removed in future versions.
249 .bP
250 X/Open Curses, Issue 5 (December 2007) marked the termcap interface
251 (along with \fBvwprintw\fP and \fBvwscanw\fP) as withdrawn.
252 .PP
253 Neither the XSI Curses standard nor the SVr4 man pages documented the return
254 values of \fBtgetent\fR correctly, though all three were in fact returned ever
255 since SVr1.
256 In particular, an omission in the XSI Curses documentation has been
257 misinterpreted to mean that \fBtgetent\fR returns \fBOK\fR or \fBERR\fR.
258 Because the purpose of these functions is to provide compatibility with
259 the \fItermcap\fR library, that is a defect in XCurses, Issue 4, Version 2
260 rather than in ncurses.
261 .SS Compatibility with BSD Termcap
262 .PP
263 External variables are provided for support of certain termcap applications.
264 However, termcap applications' use of those variables is poorly documented,
265 e.g., not distinguishing between input and output.
266 In particular, some applications are reported to declare and/or
267 modify \fBospeed\fR.
268 .PP
269 The comment that only the first two characters of the \fBid\fR parameter
270 are used escapes many application developers.
271 The original BSD 4.2 termcap library (and historical relics thereof)
272 did not require a trailing null NUL on the parameter name passed
273 to \fBtgetstr\fP, \fBtgetnum\fP and \fBtgetflag\fP.
274 Some applications assume that the termcap interface does not require
275 the trailing NUL for the parameter name.
276 Taking into account these issues:
277 .bP
278 As a special case,
279 \fBtgetflag\fP matched against a single-character identifier
280 provided that was at the end of the terminal description.
281 You should not rely upon this behavior in portable programs.
282 This implementation disallows matches against single-character capability names.
283 .bP
284 This implementation disallows matches by the termcap interface against
285 extended capability names which are longer than two characters.
286 .PP
287 The BSD termcap function \fBtgetent\fP returns the text of a termcap
288 entry in the buffer passed as an argument.
289 This library (like other terminfo implementations) does not store
290 terminal descriptions as text.
291 It sets the buffer contents to a null-terminated string.
292 .SS Other Compatibility
293 This library includes a termcap.h header,
294 for compatibility with other implementations.
295 But the header is rarely used because the other implementations
296 are not strictly compatible.
297 .PP
298 The original BSD termcap (through 4.3BSD) had no header file which
299 gave function prototypes, because that was a feature of ANSI C.
300 BSD termcap was written several years before C was standardized.
301 However, there were two different termcap.h header files in the BSD
302 sources:
303 .bP
304 One was used internally by the \fIjove\fP editor in 2BSD through 4.4BSD.
305 It defined global symbols for the termcap variables which it used.
306 .bP
307 The other appeared in 4.4BSD Lite Release 2 (mid-1993)
308 as part of \fIlibedit\fP (also known as the \fIeditline\fP library).
309 The CSRG source history shows that this was added in mid-1992.
310 The \fIlibedit\fP header file was used internally,
311 as a convenience for compiling the \fIeditline\fP library.
312 It declared function prototypes, but no global variables.
313 .PP
314 The header file from \fIlibedit\fP was added to NetBSD's termcap
315 library in mid-1994.
316 .PP
317 Meanwhile, GNU termcap was under development, starting in 1990.
318 The first release (termcap 1.0) in 1991 included a termcap.h header.
319 The second release (termcap 1.1) in September 1992 modified the
320 header to use \fBconst\fP for the function prototypes in the header
321 where one would expect the parameters to be read-only.
322 This was a difference versus the original BSD termcap.
323 The prototype for \fBtputs\fP also differed,
324 but in that instance, it was \fIlibedit\fP which differed from BSD termcap.
325 .PP
326 A copy of GNU termcap 1.3 was bundled with \fIbash\fP in mid-1993,
327 to support the \fIreadline\fP library.
328 .PP
329 A termcap.h file was provided in ncurses 1.8.1 (November 1993).
330 That reflected influence by \fIemacs\fP (rather than \fIjove\fP)
331 and GNU termcap:
332 .bP
333 it provided declarations for a few global symbols used by \fIemacs\fP
334 .bP
335 it provided function prototypes (using \fBconst\fP).
336 .bP
337 a prototype for \fBtparam\fP (a GNU termcap feature) was provided.
338 .PP
339 Later (in mid-1996) the \fBtparam\fP function was removed from ncurses.
340 As a result, there are differences between any of the four implementations,
341 which must be taken into account by programs which can work with all
342 termcap library interfaces.
343 .SH SEE ALSO
344 \fBcurses\fR(3X),
345 \fBputc\fR(3),
346 \fBterm_variables\fR(3X),
347 \fBterminfo\fR(\*n).
348 .sp
349 https://invisible-island.net/ncurses/tctest.html