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