]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_termcap.3x
ncurses 6.2 - patch 20200627
[ncurses.git] / man / curs_termcap.3x
1 .\"***************************************************************************
2 .\" Copyright 2018-2019,2020 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.44 2020/05/17 01:20:13 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 \- direct \fBcurses\fR interface to the terminfo capability database
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 *bp, const char *name);\fR
70 .br
71 \fBint tgetflag(const char *id);\fR
72 .br
73 \fBint tgetnum(const char *id);\fR
74 .br
75 \fBchar *tgetstr(const char *id, char **area);\fR
76 .br
77 \fBchar *tgoto(const char *cap, int col, int row);\fR
78 .br
79 \fBint tputs(const char *str, int affcnt, int (*putc)(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 and 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, \fBtputs("50");\fR will put out a literal \*(``50\*('' rather
222 than busy-waiting for 50 milliseconds.
223 Cope with it.
224 .PP
225 Note that termcap has nothing analogous to terminfo's \fBsgr\fR string.
226 One consequence of this is that termcap applications assume \fRme\fR
227 (terminfo \fBsgr0\fR) does not reset the alternate character set.
228 This implementation checks for, and modifies the data shown to the
229 termcap interface to accommodate termcap's limitation in this respect.
230 .SH PORTABILITY
231 .SS Standards
232 These functions are provided for supporting legacy applications,
233 and should not be used in new programs:
234 .bP
235 The XSI Curses standard, Issue 4 describes these functions.
236 However, they
237 are marked TO BE WITHDRAWN and may be removed in future versions.
238 .bP
239 X/Open Curses, Issue 5 (December 2007) marked the termcap interface
240 (along with \fBvwprintw\fP and \fBvwscanw\fP) as withdrawn.
241 .PP
242 Neither the XSI Curses standard nor the SVr4 man pages documented the return
243 values of \fBtgetent\fR correctly, though all three were in fact returned ever
244 since SVr1.
245 In particular, an omission in the XSI Curses documentation has been
246 misinterpreted to mean that \fBtgetent\fR returns \fBOK\fR or \fBERR\fR.
247 Because the purpose of these functions is to provide compatibility with
248 the \fItermcap\fR library, that is a defect in XCurses, Issue 4, Version 2
249 rather than in ncurses.
250 .SS Compatibility with BSD Termcap
251 .PP
252 External variables are provided for support of certain termcap applications.
253 However, termcap applications' use of those variables is poorly documented,
254 e.g., not distinguishing between input and output.
255 In particular, some applications are reported to declare and/or
256 modify \fBospeed\fR.
257 .PP
258 The comment that only the first two characters of the \fBid\fR parameter
259 are used escapes many application developers.
260 The original BSD 4.2 termcap library (and historical relics thereof)
261 did not require a trailing null NUL on the parameter name passed
262 to \fBtgetstr\fP, \fBtgetnum\fP and \fBtgetflag\fP.
263 Some applications assume that the termcap interface does not require
264 the trailing NUL for the parameter name.
265 Taking into account these issues:
266 .bP
267 As a special case,
268 \fBtgetflag\fP matched against a single-character identifier
269 provided that was at the end of the terminal description.
270 You should not rely upon this behavior in portable programs.
271 This implementation disallows matches against single-character capability names.
272 .bP
273 This implementation disallows matches by the termcap interface against
274 extended capability names which are longer than two characters.
275 .PP
276 The BSD termcap function \fBtgetent\fP returns the text of a termcap
277 entry in the buffer passed as an argument.
278 This library (like other terminfo implementations) does not store
279 terminal descriptions as text.
280 It sets the buffer contents to a null-terminated string.
281 .SS Other Compatibility
282 This library includes a termcap.h header,
283 for compatibility with other implementations.
284 But the header is rarely used because the other implementations
285 are not strictly compatible.
286 .PP
287 The original BSD termcap (through 4.3BSD) had no header file which
288 gave function prototypes, because that was a feature of ANSI C.
289 BSD termcap was written several years before C was standardized.
290 However, there were two different termcap.h header files in the BSD
291 sources:
292 .bP
293 One was used internally by the \fIjove\fP editor in 2BSD through 4.4BSD.
294 It defined global symbols for the termcap variables which it used.
295 .bP
296 The other appeared in 4.4BSD Lite Release 2 (mid-1993)
297 as part of \fIlibedit\fP (also known as the \fIeditline\fP library).
298 The CSRG source history shows that this was added in mid-1992.
299 The \fIlibedit\fP header file was used internally,
300 as a convenience for compiling the \fIeditline\fP library.
301 It declared function prototypes, but no global variables.
302 .PP
303 The header file from \fIlibedit\fP was added to NetBSD's termcap
304 library in mid-1994.
305 .PP
306 Meanwhile, GNU termcap was under development, starting in 1990.
307 The first release (termcap 1.0) in 1991 included a termcap.h header.
308 The second release (termcap 1.1) in September 1992 modified the
309 header to use \fBconst\fP for the function prototypes in the header
310 where one would expect the parameters to be read-only.
311 This was a difference versus the original BSD termcap.
312 The prototype for \fBtputs\fP also differed,
313 but in that instance, it was \fIlibedit\fP which differed from BSD termcap.
314 .PP
315 A copy of GNU termcap 1.3 was bundled with \fIbash\fP in mid-1993,
316 to support the \fIreadline\fP library.
317 .PP
318 A termcap.h file was provided in ncurses 1.8.1 (November 1993).
319 That reflected influence by \fIemacs\fP (rather than \fIjove\fP)
320 and GNU termcap:
321 .bP
322 it provided declarations for a few global symbols used by \fIemacs\fP
323 .bP
324 it provided function prototypes (using \fBconst\fP).
325 .bP
326 a prototype for \fBtparam\fP (a GNU termcap feature) was provided.
327 .PP
328 Later (in mid-1996) the \fBtparam\fP function was removed from ncurses.
329 As a result, there are differences between any of the four implementations,
330 which must be taken into account by programs which can work with all
331 termcap library interfaces.
332 .SH SEE ALSO
333 \fBcurses\fR(3X),
334 \fBterminfo\fR(\*n),
335 \fBterm_variables\fR(3X),
336 \fBputc\fR(3).
337 .sp
338 https://invisible-island.net/ncurses/tctest.html