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