Debian Codegraph @

upstream/debian-unstable/man5/term.5

raw
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright 2018-2024,2025 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.85 2025/08/16 19:11:47 tom Exp $
32 .TH term 5 2025-08-16 "ncurses 6.6" "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 .SH NAME
59 term \-
60 compiled \fI\%term\%info\fP terminal description
61 .\"SH SYNOPSIS
62 .SH DESCRIPTION
63 \fB\%tic\fP(1) compiles a
64 .I \%term\%info
65 terminal type description,
66 and \fB\%setupterm\fP(3NCURSES) reads it.
67 A compiled description may be stored in a file or in a database of,
68 potentially,
69 many such descriptions.
70 Further,
71 a compiled description may be in one of two formats:
72 one similar to that used by System\ V,
73 and a newer,
74 extensible format employed exclusively by
75 .IR \%ncurses .
76 .SS "Storage Location"
77 Compiled
78 .I \%term\%info descriptions are placed
79 under the directory
80 .IR \%/etc/terminfo .
81 One of two configurations is selected
82 when building the
83 .I \%ncurses
84 libraries.
85 .TP 5
86 .B directory tree
87 A two-level scheme is used to avoid a linear search
88 of a huge Unix system directory:
89 .IR \%/etc/terminfo/ c / name
90 where
91 .I name
92 is the name of the terminal,
93 and
94 .I c
95 is the first character of
96 .IR name .
97 Thus,
98 the compiled description of terminal type \*(``act4\*(''
99 is found in the file
100 .IR \%/etc/terminfo/a/act4 .
101 Synonyms for the same terminal are implemented by multiple
102 links to the same compiled file.
103 .TP 5
104 .B hashed database
105 Using the Berkeley database API,
106 two types of records are stored:
107 the
108 .I \%term\%info
109 data in the same format as that stored in a directory tree with
110 the terminal's primary type name as a key,
111 and records containing only aliases pointing to the primary name.
112 .IP
113 If built to write hashed databases,
114 .I \%ncurses
115 can still read
116 .I \%term\%info
117 databases organized as a
118 directory tree,
119 but cannot write entries into the directory tree.
120 It can write
121 (or rewrite)
122 entries in the hashed database.
123 .IP
124 .I \%ncurses
125 distinguishes the two cases in the
126 .I \%TERMINFO
127 and
128 .I \%TERMINFO_DIRS
129 environment variable by assuming a directory tree for entries that
130 correspond to an existing directory,
131 and a hashed database otherwise.
132 .SS "Legacy Storage Format"
133 The format has been chosen so that it will be the same on all hardware.
134 A byte of at least eight bits' width is assumed,
135 but no assumptions about bit ordering
136 or sign extension are made.
137 .PP
138 The file is divided into six parts:
139 .RS 5
140 .IP (a) 4
141 .IR header ,
142 .IP (b)
143 .IR "terminal names" ,
144 .IP (c)
145 .IR "Boolean flags" ,
146 .IP (d)
147 .IR numbers ,
148 .IP (e)
149 .IR strings ,
150 and
151 .IP (f)
152 a
153 .IR "string table" .
154 .RE
155 .PP
156 The \fIheader\fP section begins the file.
157 This section contains six short integers in the format
158 described below.
159 These integers are
160 .RS 5
161 .TP 5
162 (1) the \fImagic number\fP
163 (octal 0432);
164 .TP 5
165 (2) the size,
166 in bytes,
167 of the \fIterminal names\fP section;
168 .TP 5
169 (3) the number of bytes in the \fIBoolean flags\fP section;
170 .TP 5
171 (4) the number of short integers in the \fInumbers\fP section;
172 .TP 5
173 (5) the number of offsets
174 (short integers)
175 in the \fIstrings\fP section;
176 .TP 5
177 (6) the size,
178 in bytes,
179 of the \fIstring table\fP.
180 .RE
181 .PP
182 The capabilities in the
183 \fIBoolean flags\fP,
184 \fInumbers\fP,
185 and
186 \fIstrings\fP
187 sections are in the same order as in the header file
188 .IR term.h .
189 .PP
190 Short integers are signed,
191 in the range \-32768 to 32767,
192 and stored in little-endian format.
193 .PP
194 Numbers in a terminal description,
195 whether they are entries in the \fInumbers\fP or \fIstrings\fP table,
196 are positive integers.
197 Boolean flags are treated as positive one-byte integers.
198 In each case,
199 those positive integers represent a terminal capability.
200 The terminal compiler
201 .I \%tic
202 uses negative integers to handle the cases where a capability is not
203 available:
204 .bP
205 If a capability is absent from this terminal,
206 .I \%tic
207 stores a \-1 in the corresponding table.
208 .IP
209 The integer value \-1 is represented by two bytes 0377,
210 0377.
211 .br
212 Absent Boolean values are represented by the byte 0 (false).
213 .bP
214 If a capability has been canceled from this terminal,
215 .I \%tic
216 stores a \-2 in the corresponding table.
217 .IP
218 The integer value \-2 is represented by two bytes 0377,
219 0376.
220 .br
221 The Boolean value \-2 is represented by the byte 0376.
222 .br
223 .bP
224 Other negative values are illegal.
225 .PP
226 The \fIterminal names\fP section comes after the \fIheader\fP.
227 It contains the first line of the
228 .I \%term\%info
229 description,
230 listing the various names for the terminal,
231 separated by the \*(``|\*('' character.
232 The \fIterminal names\fP section is terminated
233 with an \s-1ASCII NUL\s+1 character.
234 .PP
235 The \fIBoolean flags\fP section has one byte for each flag.
236 Boolean capabilities are either 1 or 0
237 (true or false)
238 according to whether the terminal supports the given capability or not.
239 .PP
240 Between the \fIBoolean flags\fP section and the \fInumber\fP section,
241 a null byte will be inserted,
242 if necessary,
243 to ensure that the \fInumber\fP section begins on an even byte
244 This is a relic of the PDP\-11's word-addressed architecture,
245 originally designed to avoid traps induced
246 by addressing a word on an odd byte boundary.
247 All short integers are aligned on a short word boundary.
248 .PP
249 The \fInumbers\fP section is similar to the \fIBoolean flags\fP section.
250 Each capability takes up two bytes,
251 and is stored as a little-endian short integer.
252 .PP
253 The \fIstrings\fP section is also similar.
254 Each capability is stored as a short integer.
255 The capability value is an index into the \fIstring table\fP.
256 .PP
257 The \fIstring table\fP is the last section.
258 It contains all of the values of string capabilities referenced in
259 the \fIstrings\fP section.
260 Each string is null-terminated.
261 Special characters in \*^X or \ec notation are stored in their
262 interpreted form,
263 not the printing representation.
264 Padding information
265 .BI $< nn >
266 and parameter information
267 .B %x
268 are stored intact in uninterpreted form.
269 .SS "Extended Storage Format"
270 The previous section describes the conventional
271 .I \%term\%info
272 binary format.
273 With some minor variations of the offsets
274 (see PORTABILITY),
275 the same binary format is used in all modern Unix systems.
276 Each system uses a standard set of Boolean,
277 numeric,
278 or string capabilities.
279 .PP
280 The
281 .I \%ncurses
282 libraries and applications support extended
283 .I \%term\%info
284 binary format,
285 allowing users to define capabilities that are loaded at runtime.
286 This extension is made possible by using the fact that the other
287 implementations stop reading the
288 .I \%term\%info
289 data when they reach the end of the size given in the header.
290 .I \%ncurses
291 checks the size,
292 and if it exceeds that specified in the header,
293 continues to parse according to its own scheme.
294 .PP
295 First,
296 it reads the extended header
297 (5 short integers):
298 .RS 5
299 .TP 5
300 (1)
301 count of extended Boolean capabilities
302 .TP 5
303 (2)
304 count of extended numeric capabilities
305 .TP 5
306 (3)
307 count of extended string capabilities
308 .TP 5
309 (4)
310 count of the items in extended string table
311 .TP 5
312 (5)
313 size of the extended string table in bytes
314 .RE
315 .PP
316 The count- and size-values for the extended string table
317 include the extended capability \fInames\fP as well as
318 extended capability \fIvalues\fP.
319 .PP
320 Using the counts and sizes,
321 .I \%ncurses
322 allocates arrays and reads data for the extended capabilities in the
323 same order as the header information.
324 .PP
325 The extended string table contains values for string capabilities.
326 After the end of these values,
327 it contains the names for each of
328 the extended capabilities in order:
329 Boolean,
330 numeric,
331 and string.
332 .PP
333 By storing terminal descriptions in this way,
334 .I \%ncurses
335 is able to provide a database useful with legacy applications,
336 as well as providing data for applications that require more information
337 about a terminal type than was anticipated
338 by X/Open Curses.
339 See \fB\%user_caps\fP(5) for an overview of the way
340 .I \%ncurses
341 uses this extended information.
342 .PP
343 Applications that manipulate terminal data can use the definitions
344 described in \fB\%terminfo_variables\fP(3NCURSES) associating the long capability
345 names with members of a
346 .I \%TERMTYPE
347 structure.
348 .
349 .SS "Extended Number Format"
350 On occasion,
351 16-bit signed integers are not large enough.
352 .I \%ncurses
353 6.1 introduced a new format
354 by making a few changes to the legacy format:
355 .bP
356 a different magic number
357 (octal 01036)
358 .bP
359 changing the type for the \fInumber\fP array from signed 16-bit integers
360 to signed 32-bit integers.
361 .PP
362 To maintain compatibility,
363 the library presents the same data structures
364 to direct users of the
365 .I \%TERMTYPE
366 structure as in previous formats.
367 However,
368 that cannot provide callers with the extended numbers.
369 The library uses a similar but hidden data structure
370 .I \%TERMTYPE2
371 to provide data for the
372 .I \%term\%info
373 functions.
374 .SH FILES
375 .TP
376 .I /etc/terminfo
377 compiled terminal description database
378 .SH PORTABILITY
379 .SS setupterm
380 Note that it is possible for
381 .B setupterm
382 to expect a different set of capabilities
383 than are actually present in the file.
384 Either the database may have been updated since
385 .B setupterm
386 was recompiled
387 (resulting in extra unrecognized entries in the file)
388 or the program may have been recompiled more recently
389 than the database was updated
390 (resulting in missing entries).
391 The routine
392 .B setupterm
393 must be prepared for both possibilities \-
394 this is why the numbers and sizes are included.
395 Also,
396 new capabilities must always be added at the end of the lists
397 of Boolean,
398 number,
399 and string capabilities.
400 .SS "Binary Format"
401 X/Open Curses does not specify a format for the
402 .I \%term\%info
403 database.
404 System\ V
405 .I curses
406 used a directory-tree of binary files,
407 one per terminal description.
408 .PP
409 Despite the consistent use of little-endian numbers and the otherwise
410 self-describing format,
411 it is not wise to count on portability of binary
412 .I \%term\%info
413 entries between commercial Unix versions.
414 The problem is that there are at least three versions of
415 .I \%term\%info
416 (under HP\-UX,
417 AIX,
418 and OSF/1)
419 each of which diverged from System\ V
420 .I \%term\%info
421 after SVr1,
422 and added extension capabilities to the string table that
423 (in the binary format)
424 collide with System\ V and X/Open Curses extensions.
425 See \fB\%terminfo\fP(5) for detailed
426 discussion of
427 .I \%term\%info
428 source compatibility issues.
429 .PP
430 This implementation is by default compatible with the binary
431 .I \%term\%info
432 format used by Solaris
433 .IR curses ,
434 except in a few less-used details
435 where it was found that the latter did not match X/Open Curses.
436 The format used by the other Unix versions
437 can be matched by building
438 .I \%ncurses
439 with different configuration options.
440 .SS "Magic Codes"
441 The magic number in a binary
442 .I \%term\%info
443 file is the first 16 bits
444 (two bytes).
445 Besides making it more reliable for the library to check that a file is
446 .IR \%term\%info ,
447 utilities such as \fIfile\fP(1) also use that to tell what the
448 file-format is.
449 System\ V defined more than one magic number,
450 with 0433,
451 0435 as screen-dumps
452 (see \fB\%scr_dump\fP(5)).
453 This implementation uses 01036 as a continuation of that sequence,
454 but with a different high-order byte to avoid confusion.
455 .SS "The \fITERMTYPE\fP Structure"
456 Direct access to the
457 .I \%TERMTYPE
458 structure is provided for legacy applications.
459 Portable applications should use \fB\%tigetflag\fP(3NCURSES) and related
460 functions to read terminal capabilities.
461 .SS "Mixed-case Terminal Names"
462 A small number of terminal descriptions use uppercase characters in
463 their names.
464 If the underlying file system ignores the difference between
465 uppercase and lowercase,
466 .I \%ncurses
467 represents the \*(``first character\*('' of the terminal name used as
468 the intermediate level of a directory tree in (two-character)
469 hexadecimal form.
470 .SS Limits
471 .I \%ncurses
472 stores compiled terminal descriptions in three related formats,
473 described in the subsections
474 .bP
475 .BR "Legacy Storage Format" ,
476 and
477 .bP
478 .BR "Extended Storage Format" ,
479 and
480 .bP
481 .BR "Extended Number Format" .
482 .PP
483 The legacy storage format and the extended number format differ by
484 the types of numeric capability that they can store
485 (for example,
486 16- versus 32-bit integers).
487 The extended storage format introduced by
488 .I \%ncurses
489 5.0 adds data to either of these formats.
490 .PP
491 Some limitations apply:
492 .bP
493 total compiled entries cannot exceed 4096 bytes in the legacy format.
494 .bP
495 total compiled entries cannot exceed 32768 bytes in the extended format.
496 .bP
497 the name field cannot exceed 128 bytes.
498 .PP
499 Compiled entries are limited to 32768 bytes because offsets into the
500 \fIstrings table\fP use two-byte integers.
501 The legacy format could have supported 32768-byte entries,
502 but was limited to a virtual memory page's 4096 bytes.
503 .SH EXAMPLES
504 Here is a
505 .I \%term\%info
506 description of the Lear-Siegler ADM-3,
507 a popular though rather stupid early terminal.
508 .PP
509 .EX
510 .nf
511 adm3a|lsi adm3a,
512 am,
513 cols#80, lines#24,
514 bel=\*^G, clear=\e032$<1>, cr=\*^M, cub1=\*^H, cud1=\*^J,
515 cuf1=\*^L, cup=\eE=%p1%{32}%+%c%p2%{32}%+%c, cuu1=\*^K,
516 home=\*^\*^, ind=\*^J,
517 .fi
518 .EE
519 .PP
520 A hexadecimal dump of its compiled terminal description
521 (in legacy format)
522 follows.
523 .PP
524 .if t .in +4n
525 .ft \*(CW
526 .TS
527 Lp-1.
528 0000 1a 01 10 00 02 00 03 00 82 00 31 00 61 64 6d 33 ........ ..1.adm3
529 0010 61 7c 6c 73 69 20 61 64 6d 33 61 00 00 01 50 00 a|lsi ad m3a...P.
530 0020 ff ff 18 00 ff ff 00 00 02 00 ff ff ff ff 04 00 ........ ........
531 0030 ff ff ff ff ff ff ff ff 0a 00 25 00 27 00 ff ff ........ ..%.\*'...
532 0040 29 00 ff ff ff ff 2b 00 ff ff 2d 00 ff ff ff ff ).....+. ..\-.....
533 0050 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
534 0060 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
535 0070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
536 0080 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
537 0090 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
538 00a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
539 00b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
540 00c0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
541 00d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
542 00e0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
543 00f0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
544 0100 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
545 0110 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
546 0120 ff ff ff ff ff ff 2f 00 07 00 0d 00 1a 24 3c 31 ....../. .....$<1
547 0130 3e 00 1b 3d 25 70 31 25 7b 33 32 7d 25 2b 25 63 >..=%p1% {32}%+%c
548 0140 25 70 32 25 7b 33 32 7d 25 2b 25 63 00 0a 00 1e %p2%{32} %+%c....
549 0150 00 08 00 0c 00 0b 00 0a 00 ........ .
550 .TE
551 .ft
552 .in
553 .SH AUTHORS
554 Thomas E. Dickey
555 .br
556 extended
557 .I \%term\%info
558 format for
559 .I \%ncurses
560 5.0
561 .br
562 hashed database support for
563 .I \%ncurses
564 5.6
565 .br
566 extended number support for
567 .I \%ncurses
568 6.1
569 .sp
570 Eric S. Raymond
571 .br
572 documented legacy
573 .I \%term\%info
574 format
575 (that used by
576 .IR \%pcurses ).
577 .SH SEE ALSO
578 \fB\%ncurses\fP(3NCURSES),
579 \fB\%terminfo\fP(3NCURSES),
580 \fB\%terminfo\fP(5),
581 \fB\%user_caps\fP(5)