]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/term.5
ncurses 6.2 - patch 20200308
[ncurses.git] / man / term.5
1 .\"***************************************************************************
2 .\" Copyright 2018-2019,2020 Thomas E. Dickey                                *
3 .\" Copyright 1998-2016,2017 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: term.5,v 1.33 2020/02/02 23:34:34 tom Exp $
31 .TH term 5
32 .ie \n(.g .ds `` \(lq
33 .el       .ds `` ``
34 .ie \n(.g .ds '' \(rq
35 .el       .ds '' ''
36 .de NS
37 .ie n  .sp
38 .el    .sp .5
39 .ie n  .in +4
40 .el    .in +2
41 .nf
42 .ft C                   \" Courier
43 ..
44 .de NE
45 .fi
46 .ft R
47 .ie n  .in -4
48 .el    .in -2
49 ..
50 .de bP
51 .ie n  .IP \(bu 4
52 .el    .IP \(bu 2
53 ..
54 .ds n 5
55 .ds d @TERMINFO@
56 .SH NAME
57 term \- format of compiled term file.
58 .SH SYNOPSIS
59 .B term
60 .SH DESCRIPTION
61 .SS STORAGE LOCATION
62 Compiled terminfo descriptions are placed under the directory \fB\*d\fP.
63 Two configurations are supported (when building the \fBncurses\fP libraries):
64 .TP 5
65 .B directory tree
66 A two-level scheme is used to avoid a linear search
67 of a huge \s-1UNIX\s+1 system directory: \fB\*d/c/name\fP where
68 .I name
69 is the name of the terminal, and
70 .I c
71 is the first character of
72 .IR name .
73 Thus,
74 .I act4
75 can be found in the file \fB\*d/a/act4\fP.
76 Synonyms for the same terminal are implemented by multiple
77 links to the same compiled file.
78 .TP 5
79 .B hashed database
80 Using Berkeley database, two types of records are stored:
81 the terminfo data in the same format as stored in a directory tree with
82 the terminfo's primary name as a key,
83 and records containing only aliases pointing to the primary name.
84 .IP
85 If built to write hashed databases,
86 \fBncurses\fP can still read terminfo databases organized as a directory tree,
87 but cannot write entries into the directory tree.
88 It can write (or rewrite) entries in the hashed database.
89 .IP
90 \fBncurses\fP distinguishes the two cases in the TERMINFO and TERMINFO_DIRS
91 environment variable by assuming a directory tree for entries that
92 correspond to an existing directory,
93 and hashed database otherwise.
94 .SS LEGACY STORAGE FORMAT
95 The format has been chosen so that it will be the same on all hardware.
96 An 8 or more bit byte is assumed, but no assumptions about byte ordering
97 or sign extension are made.
98 .PP
99 The compiled file is created with the \fB@TIC@\fP program,
100 and read by the routine \fBsetupterm\fP(3X).
101 The file is divided into six parts:
102 the header,
103 terminal names,
104 boolean flags,
105 numbers,
106 strings,
107 and
108 string table.
109 .PP
110 The header section begins the file.
111 This section contains six short integers in the format
112 described below.
113 These integers are
114 .RS 5
115 .TP 5
116 (1) the magic number (octal 0432);
117 .TP 5
118 (2) the size, in bytes, of the names section;
119 .TP 5
120 (3) the number of bytes in the boolean section;
121 .TP 5
122 (4) the number of short integers in the numbers section;
123 .TP 5
124 (5) the number of offsets (short integers) in the strings section;
125 .TP 5
126 (6) the size, in bytes, of the string table.
127 .RE
128 .PP
129 Short integers are stored in two 8-bit bytes.
130 The first byte contains the least significant 8 bits of the value,
131 and the second byte contains the most significant 8 bits.
132 (Thus, the value represented is 256*second+first.)
133 The value \-1 is represented by the two bytes 0377, 0377; other negative
134 values are illegal.
135 This value generally
136 means that the corresponding capability is missing from this terminal.
137 Note that this format corresponds to the hardware of the \s-1VAX\s+1
138 and \s-1PDP\s+1-11 (that is, little-endian machines).
139 Machines where this does not correspond to the hardware must read the
140 integers as two bytes and compute the little-endian value.
141 .PP
142 The terminal names section comes next.
143 It contains the first line of the terminfo description,
144 listing the various names for the terminal,
145 separated by the \*(``|\*('' character.
146 The section is terminated with an \s-1ASCII NUL\s+1 character.
147 .PP
148 The boolean flags have one byte for each flag.
149 This byte is either 0 or 1 as the flag is present or absent.
150 The capabilities are in the same order as the file <term.h>.
151 .PP
152 Between the boolean section and the number section,
153 a null byte will be inserted, if necessary,
154 to ensure that the number section begins on an even byte (this is a
155 relic of the PDP\-11's word-addressed architecture, originally
156 designed in to avoid IOT traps induced by addressing a word on an
157 odd byte boundary).
158 All short integers are aligned on a short word boundary.
159 .PP
160 The numbers section is similar to the flags section.
161 Each capability takes up two bytes,
162 and is stored as a little-endian short integer.
163 If the value represented is \-1, the capability is taken to be missing.
164 .PP
165 The strings section is also similar.
166 Each capability is stored as a short integer, in the format above.
167 A value of \-1 means the capability is missing.
168 Otherwise, the value is taken as an offset from the beginning
169 of the string table.
170 Special characters in ^X or \ec notation are stored in their
171 interpreted form, not the printing representation.
172 Padding information $<nn> and parameter information %x are
173 stored intact in uninterpreted form.
174 .PP
175 The final section is the string table.
176 It contains all the values of string capabilities referenced in
177 the string section.
178 Each string is null terminated.
179 .SS EXTENDED STORAGE FORMAT
180 The previous section describes the conventional terminfo binary format.
181 With some minor variations of the offsets (see PORTABILITY),
182 the same binary format is used in all modern UNIX systems.
183 Each system uses a predefined set of boolean, number or string capabilities.
184 .PP
185 The \fBncurses\fP libraries and applications support
186 extended terminfo binary format,
187 allowing users to define capabilities which are loaded at runtime.
188 This
189 extension is made possible by using the fact that the other implementations
190 stop reading the terminfo data when they have reached the end of the size given
191 in the header.
192 \fBncurses\fP checks the size,
193 and if it exceeds that due to the predefined data,
194 continues to parse according to its own scheme.
195 .PP
196 First, it reads the extended header (5 short integers):
197 .RS 5
198 .TP 5
199 (1)
200 count of extended boolean capabilities
201 .TP 5
202 (2)
203 count of extended numeric capabilities
204 .TP 5
205 (3)
206 count of extended string capabilities
207 .TP 5
208 (4)
209 count of the items in extended string table
210 .TP 5
211 (5)
212 size of the extended string table in bytes
213 .RE
214 .PP
215 The count- and size-values for the extended string table
216 include the extended capability \fInames\fP as well as
217 extended capability \fIvalues\fP.
218 .PP
219 Using the counts and sizes, \fBncurses\fP allocates arrays and reads data
220 for the extended capabilities in the same order as the header information.
221 .PP
222 The extended string table contains values for string capabilities.
223 After the end of these values, it contains the names for each of
224 the extended capabilities in order, e.g., booleans, then numbers and
225 finally strings.
226 .PP
227 Applications which manipulate terminal data can use the definitions
228 described in \fBterm_variables\fP(3X) which associate the long capability
229 names with members of a \fBTERMTYPE\fP structure.
230 .
231 .SS EXTENDED NUMBER FORMAT
232 .PP
233 On occasion, 16-bit signed integers are not large enough.
234 With \fBncurses\fP 6.1, a new format was introduced by making a few changes
235 to the legacy format:
236 .bP
237 a different magic number (octal 01036)
238 .bP
239 changing the type for the \fInumber\fP array from signed 16-bit integers
240 to signed 32-bit integers.
241 .PP
242 To maintain compatibility, the library presents the same data structures
243 to direct users of the \fBTERMTYPE\fP structure as in previous formats.
244 However, that cannot provide callers with the extended numbers.
245 The library uses a similar but hidden data structure \fBTERMTYPE2\fP
246 to provide data for the terminfo functions.
247 .SH PORTABILITY
248 .SS setupterm
249 .PP
250 Note that it is possible for
251 .B setupterm
252 to expect a different set of capabilities
253 than are actually present in the file.
254 Either the database may have been updated since
255 .B setupterm
256 has been recompiled
257 (resulting in extra unrecognized entries in the file)
258 or the program may have been recompiled more recently
259 than the database was updated
260 (resulting in missing entries).
261 The routine
262 .B setupterm
263 must be prepared for both possibilities \-
264 this is why the numbers and sizes are included.
265 Also, new capabilities must always be added at the end of the lists
266 of boolean, number, and string capabilities.
267 .SS Binary format
268 .PP
269 X/Open Curses does not specify a format for the terminfo database.
270 UNIX System V curses used a directory-tree of binary files,
271 one per terminal description.
272 .PP
273 Despite the consistent use of little-endian for numbers and the otherwise
274 self-describing format, it is not wise to count on portability of binary
275 terminfo entries between commercial UNIX versions.
276 The problem is that there
277 are at least three versions of terminfo (under HP\-UX, AIX, and OSF/1) which
278 diverged from System V terminfo after SVr1, and have added extension
279 capabilities to the string table that (in the binary format) collide with
280 System V and XSI Curses extensions.
281 See \fBterminfo\fR(\*n) for detailed
282 discussion of terminfo source compatibility issues.
283 .PP
284 This implementation is by default compatible with the binary
285 terminfo format used by Solaris curses,
286 except in a few less-used details
287 where it was found that the latter did not match X/Open Curses.
288 The format used by the other Unix versions
289 can be matched by building ncurses
290 with different configuration options.
291 .SS Magic codes
292 .PP
293 The magic number in a binary terminfo file is the first 16-bits (two bytes).
294 Besides making it more reliable for the library to check that a file
295 is terminfo,
296 utilities such as \fBfile\fP also use that to tell what the file-format is.
297 System V defined more than one magic number,
298 with 0433, 0435 as screen-dumps (see \fBscr_dump\fP(5)).
299 This implementation uses 01036 as a continuation of that sequence,
300 but with a different high-order byte to avoid confusion.
301 .SS The TERMTYPE structure
302 .PP
303 Direct access to the \fBTERMTYPE\fP structure is provided for legacy
304 applications.
305 Portable applications should use the \fBtigetflag\fP and related functions
306 described in \fBcurs_terminfo\fP(3X) for reading terminal capabilities.
307 .SS Mixed-case terminal names
308 .PP
309 A small number of terminal descriptions use uppercase characters in
310 their names.
311 If the underlying filesystem ignores the difference between
312 uppercase and lowercase,
313 \fBncurses\fP represents the \*(``first character\*(''
314 of the terminal name used as
315 the intermediate level of a directory tree in (two-character) hexadecimal form.
316 .SH EXAMPLE
317 As an example, here is a description for the Lear-Siegler
318 ADM\-3, a popular though rather stupid early terminal:
319 .NS
320 adm3a|lsi adm3a,
321         am,
322         cols#80, lines#24,
323         bel=^G, clear=\032$<1>, cr=^M, cub1=^H, cud1=^J,
324         cuf1=^L, cup=\\E=%p1%{32}%+%c%p2%{32}%+%c, cuu1=^K,
325         home=^^, ind=^J,
326 .NS
327 .PP
328 and a hexadecimal dump of the compiled terminal description:
329 .NS
330 .ft CW
331 \s-20000  1a 01 10 00 02 00 03 00  82 00 31 00 61 64 6d 33  ........ ..1.adm3
332 0010  61 7c 6c 73 69 20 61 64  6d 33 61 00 00 01 50 00  a|lsi ad m3a...P.
333 0020  ff ff 18 00 ff ff 00 00  02 00 ff ff ff ff 04 00  ........ ........
334 0030  ff ff ff ff ff ff ff ff  0a 00 25 00 27 00 ff ff  ........ ..%.'...
335 0040  29 00 ff ff ff ff 2b 00  ff ff 2d 00 ff ff ff ff  ).....+. ..-.....
336 0050  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
337 0060  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
338 0070  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
339 0080  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
340 0090  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
341 00a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
342 00b0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
343 00c0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
344 00d0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
345 00e0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
346 00f0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
347 0100  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
348 0110  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
349 0120  ff ff ff ff ff ff 2f 00  07 00 0d 00 1a 24 3c 31  ....../. .....$<1
350 0130  3e 00 1b 3d 25 70 31 25  7b 33 32 7d 25 2b 25 63  >..=%p1% {32}%+%c
351 0140  25 70 32 25 7b 33 32 7d  25 2b 25 63 00 0a 00 1e  %p2%{32} %+%c....
352 0150  00 08 00 0c 00 0b 00 0a  00                       ........ .\s+2
353 .ft R
354 .NE
355 .sp
356 .SH LIMITS
357 Some limitations:
358 .bP
359 total compiled entries cannot exceed 4096 bytes in the legacy format.
360 .bP
361 total compiled entries cannot exceed 32768 bytes in the extended format.
362 .bP
363 the name field cannot exceed 128 bytes.
364 .SH FILES
365 \*d/*/* compiled terminal capability data base
366 .SH SEE ALSO
367 \fBcurses\fR(3X), \fBterminfo\fR(\*n).
368 .SH AUTHORS
369 Thomas E. Dickey
370 .br
371 extended terminfo format for ncurses 5.0
372 .br
373 hashed database support for ncurses 5.6
374 .br
375 extended number support for ncurses 6.1
376 .sp
377 Eric S. Raymond
378 .br
379 documented legacy terminfo format, e.g., from pcurses.