]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/curs_termcap.3x
ncurses 6.0 - patch 20171230
[ncurses.git] / man / curs_termcap.3x
1 .\"***************************************************************************
2 .\" Copyright (c) 1998-2016,2017 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.34 2017/11/18 23:47:37 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(char *id);\fR
67 .br
68 \fBint tgetnum(char *id);\fR
69 .br
70 \fBchar *tgetstr(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 .PP
171 The \fBtputs\fR routine is described on the \fBcurs_terminfo\fR(3X) manual
172 page.  It can retrieve capabilities by either termcap or terminfo name.
173 .SS GLOBAL VARIABLES
174 .PP
175 The variables
176 \fBPC\fR,
177 \fBUP\fR and
178 \fBBC\fR
179 are set by \fBtgetent\fR to the terminfo entry's data for
180 \fBpad_char\fR,
181 \fBcursor_up\fR and
182 \fBbackspace_if_not_bs\fR,
183 respectively.
184 \fBUP\fR is not used by ncurses.
185 \fBPC\fR is used in the \fBtdelay_output\fR function.
186 \fBBC\fR is used in the \fBtgoto\fR emulation.
187 The variable \fBospeed\fR is set by ncurses in a system-specific coding
188 to reflect the terminal speed.
189 .
190 .SH RETURN VALUE
191 Except where explicitly noted,
192 routines that return an integer return \fBERR\fR upon failure and \fBOK\fR
193 (SVr4 only specifies "an integer value other than \fBERR\fR") upon successful
194 completion.
195 .PP
196 Routines that return pointers return \fBNULL\fR on error.
197 .SH BUGS
198 If you call \fBtgetstr\fR to fetch \fBca\fR or any other parameterized string,
199 be aware that it will be returned in terminfo notation, not the older and
200 not-quite-compatible termcap notation.  This will not cause problems if all
201 you do with it is call \fBtgoto\fR or \fBtparm\fR, which both expand
202 terminfo-style strings as terminfo.
203 (The \fBtgoto\fR function, if configured to support termcap, will check
204 if the string is indeed terminfo-style by looking for "%p" parameters or
205 "$<..>" delays, and invoke a termcap-style parser if the string does not
206 appear to be terminfo).
207 .PP
208 Because terminfo conventions for representing padding in string capabilities
209 differ from termcap's, \fBtputs("50");\fR will put out a literal "50" rather
210 than busy-waiting for 50 milliseconds.  Cope with it.
211 .PP
212 Note that termcap has nothing analogous to terminfo's \fBsgr\fR string.
213 One consequence of this is that termcap applications assume \fRme\fR
214 (terminfo \fBsgr0\fR) does not reset the alternate character set.
215 This implementation checks for, and modifies the data shown to the
216 termcap interface to accommodate termcap's limitation in this respect.
217 .SH PORTABILITY
218 The XSI Curses standard, Issue 4 describes these functions.  However, they
219 are marked TO BE WITHDRAWN and may be removed in future versions.
220 .PP
221 Neither the XSI Curses standard nor the SVr4 man pages documented the return
222 values of \fBtgetent\fR correctly, though all three were in fact returned ever
223 since SVr1.
224 In particular, an omission in the XSI Curses documentation has been
225 misinterpreted to mean that \fBtgetent\fR returns \fBOK\fR or \fBERR\fR.
226 Because the purpose of these functions is to provide compatibility with
227 the \fItermcap\fR library, that is a defect in XCurses, Issue 4, Version 2
228 rather than in ncurses.
229 .PP
230 External variables are provided for support of certain termcap applications.
231 However, termcap applications' use of those variables is poorly documented,
232 e.g., not distinguishing between input and output.
233 In particular, some applications are reported to declare and/or
234 modify \fBospeed\fR.
235 .PP
236 The comment that only the first two characters of the \fBid\fR parameter
237 are used escapes many application developers.
238 The original BSD 4.2 termcap library (and historical relics thereof)
239 did not require a trailing null NUL on the parameter name passed
240 to \fBtgetstr\fP, \fBtgetnum\fP and \fBtgetflag\fP.
241 Some applications assume that the termcap interface does not require
242 the trailing NUL for the parameter name.
243 Taking into account these issues:
244 .bP
245 As a special case,
246 \fBtgetflag\fP matched against a single-character identifier
247 provided that was at the end of the terminal description.
248 You should not rely upon this behavior in portable programs.
249 This implementation disallows matches against single-character capability names.
250 .bP
251 This implementation disallows matches by the termcap interface against
252 extended capability names which are longer than two characters.
253 .SH SEE ALSO
254 \fBcurses\fR(3X),
255 \fBterminfo\fR(\*n),
256 \fBterm_variables\fR(3X),
257 \fBputc\fR(3).
258 .sp
259 http://invisible-island.net/ncurses/tctest.html