]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_termcap.3x
ncurses 6.1 - patch 20191019
[ncurses.git] / man / curs_termcap.3x
1 .\"***************************************************************************
2 .\" Copyright (c) 1998-2018,2019 Free Software Foundation, Inc.              *
3 .\"                                                                          *
4 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
5 .\" copy of this software and associated documentation files (the            *
6 .\" "Software"), to deal in the Software without restriction, including      *
7 .\" without limitation the rights to use, copy, modify, merge, publish,      *
8 .\" distribute, distribute with modifications, sublicense, and/or sell       *
9 .\" copies of the Software, and to permit persons to whom the Software is    *
10 .\" furnished to do so, subject to the following conditions:                 *
11 .\"                                                                          *
12 .\" The above copyright notice and this permission notice shall be included  *
13 .\" in all copies or substantial portions of the Software.                   *
14 .\"                                                                          *
15 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22 .\"                                                                          *
23 .\" Except as contained in this notice, the name(s) of the above copyright   *
24 .\" holders shall not be used in advertising or otherwise to promote the     *
25 .\" sale, use or other dealings in this Software without prior written       *
26 .\" authorization.                                                           *
27 .\"***************************************************************************
28 .\"
29 .\" $Id: curs_termcap.3x,v 1.41 2019/03/23 21:51:12 tom Exp $
30 .TH curs_termcap 3X ""
31 .de bP
32 .ie n  .IP \(bu 4
33 .el    .IP \(bu 2
34 ..
35 .na
36 .hy 0
37 .ds n 5
38 .SH NAME
39 \fBPC\fR,
40 \fBUP\fR,
41 \fBBC\fR,
42 \fBospeed\fR,
43 \fBtgetent\fR,
44 \fBtgetflag\fR,
45 \fBtgetnum\fR,
46 \fBtgetstr\fR,
47 \fBtgoto\fR,
48 \fBtputs\fR \- direct \fBcurses\fR interface to the terminfo capability database
49 .ad
50 .hy
51 .SH SYNOPSIS
52 \fB#include <curses.h>\fR
53 .br
54 \fB#include <term.h>\fR
55 .sp
56 \fBextern char PC;\fR
57 .br
58 \fBextern char * UP;\fR
59 .br
60 \fBextern char * BC;\fR
61 .br
62 \fBextern @NCURSES_OSPEED@ ospeed;\fR
63 .sp
64 \fBint tgetent(char *bp, const char *name);\fR
65 .br
66 \fBint tgetflag(const char *id);\fR
67 .br
68 \fBint tgetnum(const char *id);\fR
69 .br
70 \fBchar *tgetstr(const char *id, char **area);\fR
71 .br
72 \fBchar *tgoto(const char *cap, int col, int row);\fR
73 .br
74 \fBint tputs(const char *str, int affcnt, int (*putc)(int));\fR
75 .br
76 .SH DESCRIPTION
77 These routines are included as a conversion aid for programs that use
78 the \fItermcap\fR library.
79 Their parameters are the same and the
80 routines are emulated using the \fIterminfo\fR database.
81 Thus, they
82 can only be used to query the capabilities of entries for which a
83 terminfo entry has been compiled.
84 .SS INITIALIZATION
85 .PP
86 The \fBtgetent\fR routine loads the entry for \fIname\fR.
87 It returns:
88 .RS 3
89 .TP 3
90 1
91 on success,
92 .TP 3
93 0
94 if there is no such entry
95 (or that it is a generic type, having too little information for curses
96 applications to run), and
97 .TP 3
98 \-1
99 if the terminfo database could not be found.
100 .RE
101 .PP
102 This differs from the \fItermcap\fP library in two ways:
103 .RS 3
104 .bP
105 The emulation ignores the buffer pointer \fIbp\fR.
106 The \fItermcap\fP library would store a copy of the terminal
107 description in the area referenced by this pointer.
108 However, ncurses stores its terminal descriptions in compiled
109 binary form, which is not the same thing.
110 .bP
111 There is a difference in return codes.
112 The \fItermcap\fP library does not check if the terminal
113 description is marked with the \fIgeneric\fP capability,
114 or if the terminal description has cursor-addressing.
115 .RE
116 .SS CAPABILITY VALUES
117 .PP
118 The \fBtgetflag\fR routine gets the boolean entry for \fIid\fR,
119 or zero if it is not available.
120 .PP
121 The \fBtgetnum\fR routine gets the numeric entry for \fIid\fR,
122 or \-1 if it is not available.
123 .PP
124 The \fBtgetstr\fR routine returns the string entry for \fIid\fR,
125 or zero if it is not available.
126 Use \fBtputs\fR to output the returned string.
127 The \fIarea\fP parameter is used as follows:
128 .RS 3
129 .bP
130 It is assumed to be the address of a pointer to a buffer managed by the
131 calling application.
132 .bP
133 However, ncurses checks to ensure that \fBarea\fP is not NULL,
134 and also that the resulting buffer pointer is not NULL.
135 If either check fails, the \fIarea\fP parameter is ignored.
136 .bP
137 If the checks succeed, ncurses also copies the return value to
138 the buffer pointed to by \fIarea\fR,
139 and the \fIarea\fR value will be updated to point past the null ending
140 this value.
141 .bP
142 The return value itself is an address in the terminal description which
143 is loaded into memory.
144 .RE
145 .PP
146 Only the first two characters of the \fBid\fR parameter of
147 \fBtgetflag\fR,
148 \fBtgetnum\fR and
149 \fBtgetstr\fR are compared in lookups.
150 .SS FORMATTING CAPABILITIES
151 .PP
152 The \fBtgoto\fR routine expands the given capability using the parameters.
153 .bP
154 Because the capability may have padding characters,
155 the output of \fBtgoto\fP should be passed to \fBtputs\fR
156 rather than some other output function such as \fBprintf\fP.
157 .bP
158 While \fBtgoto\fP is assumed to be used for the two-parameter
159 cursor positioning capability,
160 termcap applications also use it for single-parameter capabilities.
161 .IP
162 Doing this shows a quirk in \fBtgoto\fP: most hardware
163 terminals use cursor addressing with \fIrow\fP first,
164 but the original developers of the termcap interface chose to
165 put the \fIcolumn\fP parameter first.
166 The \fBtgoto\fP function swaps the order of parameters.
167 It does this also for calls requiring only a single parameter.
168 In that case, the first parameter is merely a placeholder.
169 .bP
170 Normally the ncurses library is compiled with terminfo support.
171 In that case, \fBtgoto\fP uses \fBtparm\fP(3X) (a more capable formatter).
172 .IP
173 However, \fBtparm\fP is not a \fItermcap\fP feature,
174 and portable \fItermcap\fP applications should not rely upon its availability.
175 .PP
176 The \fBtputs\fR routine is described on the \fBcurs_terminfo\fR(3X) manual
177 page.
178 It can retrieve capabilities by either termcap or terminfo name.
179 .SS GLOBAL VARIABLES
180 .PP
181 The variables
182 \fBPC\fR,
183 \fBUP\fR and
184 \fBBC\fR
185 are set by \fBtgetent\fR to the terminfo entry's data for
186 \fBpad_char\fR,
187 \fBcursor_up\fR and
188 \fBbackspace_if_not_bs\fR,
189 respectively.
190 \fBUP\fR is not used by ncurses.
191 \fBPC\fR is used in the \fBtdelay_output\fR function.
192 \fBBC\fR is used in the \fBtgoto\fR emulation.
193 The variable \fBospeed\fR is set by ncurses in a system-specific coding
194 to reflect the terminal speed.
195 .
196 .SH RETURN VALUE
197 Except where explicitly noted,
198 routines that return an integer return \fBERR\fR upon failure and \fBOK\fR
199 (SVr4 only specifies "an integer value other than \fBERR\fR") upon successful
200 completion.
201 .PP
202 Routines that return pointers return \fBNULL\fR on error.
203 .SH BUGS
204 If you call \fBtgetstr\fR to fetch \fBca\fR or any other parameterized string,
205 be aware that it will be returned in terminfo notation, not the older and
206 not-quite-compatible termcap notation.
207 This will not cause problems if all
208 you do with it is call \fBtgoto\fR or \fBtparm\fR, which both expand
209 terminfo-style strings as terminfo.
210 (The \fBtgoto\fR function, if configured to support termcap, will check
211 if the string is indeed terminfo-style by looking for "%p" parameters or
212 "$<..>" delays, and invoke a termcap-style parser if the string does not
213 appear to be terminfo).
214 .PP
215 Because terminfo conventions for representing padding in string capabilities
216 differ from termcap's, \fBtputs("50");\fR will put out a literal "50" rather
217 than busy-waiting for 50 milliseconds.
218 Cope with it.
219 .PP
220 Note that termcap has nothing analogous to terminfo's \fBsgr\fR string.
221 One consequence of this is that termcap applications assume \fRme\fR
222 (terminfo \fBsgr0\fR) does not reset the alternate character set.
223 This implementation checks for, and modifies the data shown to the
224 termcap interface to accommodate termcap's limitation in this respect.
225 .SH PORTABILITY
226 These functions are provided for supporting legacy applications,
227 and should not be used in new programs:
228 .bP
229 The XSI Curses standard, Issue 4 describes these functions.
230 However, they
231 are marked TO BE WITHDRAWN and may be removed in future versions.
232 .bP
233 X/Open Curses, Issue 5 (December 2007) marked the termcap interface
234 (along with \fBvwprintw\fP and \fBvwscanw\fP) as withdrawn.
235 .PP
236 Neither the XSI Curses standard nor the SVr4 man pages documented the return
237 values of \fBtgetent\fR correctly, though all three were in fact returned ever
238 since SVr1.
239 In particular, an omission in the XSI Curses documentation has been
240 misinterpreted to mean that \fBtgetent\fR returns \fBOK\fR or \fBERR\fR.
241 Because the purpose of these functions is to provide compatibility with
242 the \fItermcap\fR library, that is a defect in XCurses, Issue 4, Version 2
243 rather than in ncurses.
244 .PP
245 External variables are provided for support of certain termcap applications.
246 However, termcap applications' use of those variables is poorly documented,
247 e.g., not distinguishing between input and output.
248 In particular, some applications are reported to declare and/or
249 modify \fBospeed\fR.
250 .PP
251 The comment that only the first two characters of the \fBid\fR parameter
252 are used escapes many application developers.
253 The original BSD 4.2 termcap library (and historical relics thereof)
254 did not require a trailing null NUL on the parameter name passed
255 to \fBtgetstr\fP, \fBtgetnum\fP and \fBtgetflag\fP.
256 Some applications assume that the termcap interface does not require
257 the trailing NUL for the parameter name.
258 Taking into account these issues:
259 .bP
260 As a special case,
261 \fBtgetflag\fP matched against a single-character identifier
262 provided that was at the end of the terminal description.
263 You should not rely upon this behavior in portable programs.
264 This implementation disallows matches against single-character capability names.
265 .bP
266 This implementation disallows matches by the termcap interface against
267 extended capability names which are longer than two characters.
268 .SH SEE ALSO
269 \fBcurses\fR(3X),
270 \fBterminfo\fR(\*n),
271 \fBterm_variables\fR(3X),
272 \fBputc\fR(3).
273 .sp
274 https://invisible-island.net/ncurses/tctest.html