]> ncurses.scripts.mit.edu Git - ncurses.git/blob - man/term.5
000a9da40f11b6af1045e81956ff16703223ebea
[ncurses.git] / man / term.5
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright 2018-2021,2023 Thomas E. Dickey                                *
4 .\" Copyright 1998-2016,2017 Free Software Foundation, Inc.                  *
5 .\"                                                                          *
6 .\" Permission is hereby granted, free of charge, to any person obtaining a  *
7 .\" copy of this software and associated documentation files (the            *
8 .\" "Software"), to deal in the Software without restriction, including      *
9 .\" without limitation the rights to use, copy, modify, merge, publish,      *
10 .\" distribute, distribute with modifications, sublicense, and/or sell       *
11 .\" copies of the Software, and to permit persons to whom the Software is    *
12 .\" furnished to do so, subject to the following conditions:                 *
13 .\"                                                                          *
14 .\" The above copyright notice and this permission notice shall be included  *
15 .\" in all copies or substantial portions of the Software.                   *
16 .\"                                                                          *
17 .\" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18 .\" OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19 .\" MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20 .\" IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21 .\" DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22 .\" OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23 .\" THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24 .\"                                                                          *
25 .\" Except as contained in this notice, the name(s) of the above copyright   *
26 .\" holders shall not be used in advertising or otherwise to promote the     *
27 .\" sale, use or other dealings in this Software without prior written       *
28 .\" authorization.                                                           *
29 .\"***************************************************************************
30 .\"
31 .\" $Id: term.5,v 1.67 2023/12/02 20:49:04 tom Exp $
32 .TH term 5 2023-12-02 "ncurses 6.4" "File formats"
33 .ie \n(.g \{\
34 .ds `` \(lq
35 .ds '' \(rq
36 .ds '  \(aq
37 .ds ^  \(ha
38 .\}
39 .el \{\
40 .ie t .ds `` ``
41 .el   .ds `` ""
42 .ie t .ds '' ''
43 .el   .ds '' ""
44 .ds       '  '
45 .ds       ^  ^
46 .\}
47 .ie n .ds CW R
48 .el   \{
49 .ie \n(.g .ds CW CR
50 .el       .ds CW CW
51 .\}
52 .
53 .de bP
54 .ie n  .IP \(bu 4
55 .el    .IP \(bu 2
56 ..
57 .
58 .ds d @TERMINFO@
59 .SH NAME
60 term \-
61 compiled \fIterminfo\fR terminal description
62 .SH SYNOPSIS
63 .B term
64 .SH DESCRIPTION
65 .SS STORAGE LOCATION
66 Compiled terminfo descriptions are placed under the directory \fB\*d\fP.
67 Two configurations are supported (when building the \fBncurses\fP libraries):
68 .TP 5
69 .B directory tree
70 A two-level scheme is used to avoid a linear search
71 of a huge Unix system directory: \fB\*d/c/name\fP where
72 .I name
73 is the name of the terminal, and
74 .I c
75 is the first character of
76 .IR name .
77 Thus,
78 .I act4
79 can be found in the file \fB\*d/a/act4\fP.
80 Synonyms for the same terminal are implemented by multiple
81 links to the same compiled file.
82 .TP 5
83 .B hashed database
84 Using Berkeley database, two types of records are stored:
85 the terminfo data in the same format as stored in a directory tree with
86 the terminfo's primary name as a key,
87 and records containing only aliases pointing to the primary name.
88 .IP
89 If built to write hashed databases,
90 \fBncurses\fP can still read terminfo databases organized as a directory tree,
91 but cannot write entries into the directory tree.
92 It can write (or rewrite) entries in the hashed database.
93 .IP
94 \fBncurses\fP distinguishes the two cases in the \fI\%TERMINFO\fP and
95 \fI\%TERMINFO_DIRS\fP environment variable by assuming a directory tree
96 for entries that correspond to an existing directory,
97 and hashed database otherwise.
98 .SS LEGACY STORAGE FORMAT
99 The format has been chosen so that it will be the same on all hardware.
100 An 8 or more bit byte is assumed, but no assumptions about byte ordering
101 or sign extension are made.
102 .PP
103 The compiled file is created with the \fB@TIC@\fP program,
104 and read by the routine \fBsetupterm\fP(3X).
105 The file is divided into six parts:
106 .RS 5
107 .TP 3
108 a) \fIheader\fP,
109 .TP 3
110 b) \fIterminal names\fP,
111 .TP 3
112 c) \fIboolean flags\fP,
113 .TP 3
114 d) \fInumbers\fP,
115 .TP 3
116 e) \fIstrings\fP, and
117 .TP 3
118 f) \fIstring table\fP.
119 .RE
120 .PP
121 The \fIheader\fP section begins the file.
122 This section contains six short integers in the format
123 described below.
124 These integers are
125 .RS 5
126 .TP 5
127 (1) the \fImagic number\fP (octal 0432);
128 .TP 5
129 (2) the size, in bytes, of the \fIterminal names\fP section;
130 .TP 5
131 (3) the number of bytes in the \fIboolean flags\fP section;
132 .TP 5
133 (4) the number of short integers in the \fInumbers\fP section;
134 .TP 5
135 (5) the number of offsets (short integers) in the \fIstrings\fP section;
136 .TP 5
137 (6) the size, in bytes, of the \fIstring table\fP.
138 .RE
139 .PP
140 The capabilities in the
141 \fIboolean flags\fP,
142 \fInumbers\fP, and
143 \fIstrings\fP
144 sections are in the same order as the file <term.h>.
145 .PP
146 Short integers are signed, in the range \-32768 to 32767.
147 They are stored as two 8-bit bytes.
148 The first byte contains the least significant 8 bits of the value,
149 and the second byte contains the most significant 8 bits.
150 (Thus, the value represented is 256*second+first.)
151 This format corresponds to the hardware of the \s-1VAX\s+1
152 and \s-1PDP\s+1-11 (that is, little-endian machines).
153 Machines where this does not correspond to the hardware must read the
154 integers as two bytes and compute the little-endian value.
155 .PP
156 Numbers in a terminal description,
157 whether they are entries in the \fInumbers\fP or \fIstrings\fP table,
158 are positive integers.
159 Boolean flags are treated as positive one-byte integers.
160 In each case, those positive integers represent a terminal capability.
161 The terminal compiler @TIC@ uses negative integers to handle the cases where
162 a capability is not available:
163 .bP
164 If a capability is absent from this terminal,
165 @TIC@ stores a \-1 in the corresponding table.
166 .IP
167 The integer value \-1 is represented by two bytes 0377, 0377.
168 .br
169 Absent boolean values are represented by the byte 0 (false).
170 .bP
171 If a capability has been canceled from this terminal,
172 @TIC@ stores a \-2 in the corresponding table.
173 .IP
174 The integer value \-2 is represented by two bytes 0377, 0376.
175 .br
176 The boolean value \-2 is represented by the byte 0376.
177 .br
178 .bP
179 Other negative values are illegal.
180 .PP
181 The \fIterminal names\fP section comes after the \fIheader\fP.
182 It contains the first line of the terminfo description,
183 listing the various names for the terminal,
184 separated by the \*(``|\*('' character.
185 The \fIterminal names\fP section is terminated
186 with an \s-1ASCII NUL\s+1 character.
187 .PP
188 The \fIboolean flags\fP section has one byte for each flag.
189 Boolean capabilities are either 1 or 0 (true or false)
190 according to whether the terminal supports the given capability or not.
191 .PP
192 Between the \fIboolean flags\fP section and the \fInumber\fP section,
193 a null byte will be inserted, if necessary,
194 to ensure that the \fInumber\fP section begins on an even byte
195 This is a relic of the PDP\-11's word-addressed architecture,
196 originally designed to avoid traps induced
197 by addressing a word on an odd byte boundary.
198 All short integers are aligned on a short word boundary.
199 .PP
200 The \fInumbers\fP section is similar to the \fIboolean flags\fP section.
201 Each capability takes up two bytes,
202 and is stored as a little-endian short integer.
203 .PP
204 The \fIstrings\fP section is also similar.
205 Each capability is stored as a short integer.
206 The capability value is an index into the \fIstring table\fP.
207 .PP
208 The \fIstring table\fP is the last section.
209 It contains all of the values of string capabilities referenced in
210 the \fIstrings\fP section.
211 Each string is null-terminated.
212 Special characters in \*^X or \ec notation are stored in their
213 interpreted form, not the printing representation.
214 Padding information $<nn> and parameter information %x are
215 stored intact in uninterpreted form.
216 .SS EXTENDED STORAGE FORMAT
217 The previous section describes the conventional terminfo binary format.
218 With some minor variations of the offsets (see PORTABILITY),
219 the same binary format is used in all modern Unix systems.
220 Each system uses a predefined set of boolean, number or string capabilities.
221 .PP
222 The \fBncurses\fP libraries and applications support
223 extended terminfo binary format,
224 allowing users to define capabilities which are loaded at runtime.
225 This
226 extension is made possible by using the fact that the other implementations
227 stop reading the terminfo data when they have reached the end of the size given
228 in the header.
229 \fBncurses\fP checks the size,
230 and if it exceeds that due to the predefined data,
231 continues to parse according to its own scheme.
232 .PP
233 First, it reads the extended header (5 short integers):
234 .RS 5
235 .TP 5
236 (1)
237 count of extended boolean capabilities
238 .TP 5
239 (2)
240 count of extended numeric capabilities
241 .TP 5
242 (3)
243 count of extended string capabilities
244 .TP 5
245 (4)
246 count of the items in extended string table
247 .TP 5
248 (5)
249 size of the extended string table in bytes
250 .RE
251 .PP
252 The count- and size-values for the extended string table
253 include the extended capability \fInames\fP as well as
254 extended capability \fIvalues\fP.
255 .PP
256 Using the counts and sizes, \fBncurses\fP allocates arrays and reads data
257 for the extended capabilities in the same order as the header information.
258 .PP
259 The extended string table contains values for string capabilities.
260 After the end of these values, it contains the names for each of
261 the extended capabilities in order, e.g., booleans, then numbers and
262 finally strings.
263 .PP
264 By storing terminal descriptions in this way,
265 \fBncurses\fP is able to provide a database useful with legacy applications,
266 as well as providing data for applications which need more than the
267 predefined capabilities.
268 See \fBuser_caps\fP(5) for an overview
269 of the way \fBncurses\fP uses this extended information.
270 .PP
271 Applications which manipulate terminal data can use the definitions
272 described in \fBterm_variables\fP(3X) which associate the long capability
273 names with members of a \fBTERMTYPE\fP structure.
274 .
275 .SS EXTENDED NUMBER FORMAT
276 On occasion, 16-bit signed integers are not large enough.
277 With \fBncurses\fP 6.1, a new format was introduced by making a few changes
278 to the legacy format:
279 .bP
280 a different magic number (octal 01036)
281 .bP
282 changing the type for the \fInumber\fP array from signed 16-bit integers
283 to signed 32-bit integers.
284 .PP
285 To maintain compatibility, the library presents the same data structures
286 to direct users of the \fBTERMTYPE\fP structure as in previous formats.
287 However, that cannot provide callers with the extended numbers.
288 The library uses a similar but hidden data structure \fBTERMTYPE2\fP
289 to provide data for the terminfo functions.
290 .SH FILES
291 .TP
292 .I \*d
293 compiled terminal description database
294 .SH PORTABILITY
295 .SS setupterm
296 Note that it is possible for
297 .B setupterm
298 to expect a different set of capabilities
299 than are actually present in the file.
300 Either the database may have been updated since
301 .B setupterm
302 was recompiled
303 (resulting in extra unrecognized entries in the file)
304 or the program may have been recompiled more recently
305 than the database was updated
306 (resulting in missing entries).
307 The routine
308 .B setupterm
309 must be prepared for both possibilities \-
310 this is why the numbers and sizes are included.
311 Also, new capabilities must always be added at the end of the lists
312 of boolean, number, and string capabilities.
313 .SS Binary format
314 X/Open Curses does not specify a format for the terminfo database.
315 System V curses used a directory-tree of binary files,
316 one per terminal description.
317 .PP
318 Despite the consistent use of little-endian for numbers and the otherwise
319 self-describing format, it is not wise to count on portability of binary
320 terminfo entries between commercial Unix versions.
321 The problem is that there
322 are at least three versions of terminfo (under HP\-UX, AIX, and OSF/1) which
323 diverged from System V terminfo after SVr1, and have added extension
324 capabilities to the string table that (in the binary format) collide with
325 System V and XSI Curses extensions.
326 See \fBterminfo\fP(5) for detailed
327 discussion of terminfo source compatibility issues.
328 .PP
329 This implementation is by default compatible with the binary
330 terminfo format used by Solaris curses,
331 except in a few less-used details
332 where it was found that the latter did not match X/Open Curses.
333 The format used by the other Unix versions
334 can be matched by building ncurses
335 with different configuration options.
336 .SS Magic codes
337 The magic number in a binary terminfo file is the first 16-bits (two bytes).
338 Besides making it more reliable for the library to check that a file
339 is terminfo,
340 utilities such as \fBfile\fP(1) also use that to tell what the file-format is.
341 System V defined more than one magic number,
342 with 0433, 0435 as screen-dumps (see \fBscr_dump\fP(5)).
343 This implementation uses 01036 as a continuation of that sequence,
344 but with a different high-order byte to avoid confusion.
345 .SS The TERMTYPE structure
346 Direct access to the \fBTERMTYPE\fP structure is provided for legacy
347 applications.
348 Portable applications should use the \fBtigetflag\fP and related functions
349 described in \fBcurs_terminfo\fP(3X) for reading terminal capabilities.
350 .SS Mixed-case terminal names
351 A small number of terminal descriptions use uppercase characters in
352 their names.
353 If the underlying filesystem ignores the difference between
354 uppercase and lowercase,
355 \fBncurses\fP represents the \*(``first character\*(''
356 of the terminal name used as
357 the intermediate level of a directory tree in (two-character) hexadecimal form.
358 .SS Limits
359 \fBncurses\fP stores compiled terminal descriptions
360 in three related formats,
361 described in the sections
362 .bP
363 \fBLEGACY STORAGE FORMAT\fP, and
364 .bP
365 \fBEXTENDED STORAGE FORMAT\fP, and
366 .bP
367 \fBEXTENDED NUMBER FORMAT\fP.
368 .PP
369 The legacy storage format and the extended number format differ by
370 the types of numeric capability which they can store
371 (i.e., 16-bit versus 32-bit integers).
372 The extended storage format introduced by ncurses 5.0 adds data to
373 either of these formats.
374 .PP
375 Some limitations apply:
376 .bP
377 total compiled entries cannot exceed 4096 bytes in the legacy format.
378 .bP
379 total compiled entries cannot exceed 32768 bytes in the extended format.
380 .bP
381 the name field cannot exceed 128 bytes.
382 .PP
383 Compiled entries are limited to 32768 bytes because offsets into the
384 \fIstrings table\fP use two-byte integers.
385 The legacy format could have supported 32768-byte entries,
386 but was limited to a virtual memory page's 4096 bytes.
387 .SH EXAMPLES
388 As an example, here is a description for the Lear-Siegler
389 ADM\-3, a popular though rather stupid early terminal:
390 .PP
391 .RS 4
392 .EX
393 adm3a|lsi adm3a,
394         am,
395         cols#80, lines#24,
396         bel=\*^G, clear=\e032$<1>, cr=\*^M, cub1=\*^H, cud1=\*^J,
397         cuf1=\*^L, cup=\eE=%p1%{32}%+%c%p2%{32}%+%c, cuu1=\*^K,
398         home=\*^\*^, ind=\*^J,
399 .EE
400 .RE
401 .PP
402 and a hexadecimal dump of the compiled terminal description:
403 .PP
404 .ie n .in -2n
405 .el   .in +4n
406 .TS
407 lp-1f(\*(CW).
408 0000  1a 01 10 00 02 00 03 00  82 00 31 00 61 64 6d 33  ........ ..1.adm3
409 0010  61 7c 6c 73 69 20 61 64  6d 33 61 00 00 01 50 00  a|lsi ad m3a...P.
410 0020  ff ff 18 00 ff ff 00 00  02 00 ff ff ff ff 04 00  ........ ........
411 0030  ff ff ff ff ff ff ff ff  0a 00 25 00 27 00 ff ff  ........ ..%.\*'...
412 0040  29 00 ff ff ff ff 2b 00  ff ff 2d 00 ff ff ff ff  ).....+. ..\-.....
413 0050  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
414 0060  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
415 0070  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
416 0080  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
417 0090  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
418 00a0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
419 00b0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
420 00c0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
421 00d0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
422 00e0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
423 00f0  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
424 0100  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
425 0110  ff ff ff ff ff ff ff ff  ff ff ff ff ff ff ff ff  ........ ........
426 0120  ff ff ff ff ff ff 2f 00  07 00 0d 00 1a 24 3c 31  ....../. .....$<1
427 0130  3e 00 1b 3d 25 70 31 25  7b 33 32 7d 25 2b 25 63  >..=%p1% {32}%+%c
428 0140  25 70 32 25 7b 33 32 7d  25 2b 25 63 00 0a 00 1e  %p2%{32} %+%c....
429 0150  00 08 00 0c 00 0b 00 0a  00                       ........ .
430 .TE
431 .in
432 .SH AUTHORS
433 Thomas E. Dickey
434 .br
435 extended terminfo format for ncurses 5.0
436 .br
437 hashed database support for ncurses 5.6
438 .br
439 extended number support for ncurses 6.1
440 .sp
441 Eric S. Raymond
442 .br
443 documented legacy terminfo format, e.g., from \fIpcurses\fP.
444 .SH SEE ALSO
445 \fB\%curses\fP(3X),
446 \fB\%curs_terminfo\fP(3X),
447 \fB\%terminfo\fP(5),
448 \fB\%user_caps\fP(5)