Debian Codegraph @

upstream/debian-trixie/man5/term.5

raw
1 '\" t
2 .\"***************************************************************************
3 .\" Copyright 2018-2023,2024 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.80 2024/06/15 20:23:33 tom Exp $
32 .TH term 5 2024-06-15 "ncurses 6.5" "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 predefined set of Boolean,
277 number or string capabilities.
278 .PP
279 The
280 .I \%ncurses
281 libraries and applications support extended
282 .I \%term\%info
283 binary format,
284 allowing users to define capabilities that are loaded at runtime.
285 This extension is made possible by using the fact that the other
286 implementations stop reading the
287 .I \%term\%info
288 data when they reach the end of the size given in the header.
289 .I \%ncurses
290 checks the size,
291 and if it exceeds that due to the predefined data,
292 continues to parse according to its own scheme.
293 .PP
294 First,
295 it reads the extended header
296 (5 short integers):
297 .RS 5
298 .TP 5
299 (1)
300 count of extended Boolean capabilities
301 .TP 5
302 (2)
303 count of extended numeric capabilities
304 .TP 5
305 (3)
306 count of extended string capabilities
307 .TP 5
308 (4)
309 count of the items in extended string table
310 .TP 5
311 (5)
312 size of the extended string table in bytes
313 .RE
314 .PP
315 The count- and size-values for the extended string table
316 include the extended capability \fInames\fP as well as
317 extended capability \fIvalues\fP.
318 .PP
319 Using the counts and sizes,
320 .I \%ncurses
321 allocates arrays and reads data for the extended capabilities in the
322 same order as the header information.
323 .PP
324 The extended string table contains values for string capabilities.
325 After the end of these values,
326 it contains the names for each of
327 the extended capabilities in order:
328 Boolean,
329 numeric,
330 and string.
331 .PP
332 By storing terminal descriptions in this way,
333 .I \%ncurses
334 is able to provide a database useful with legacy applications,
335 as well as providing data for applications that require more information
336 about a terminal type than was anticipated
337 by X/Open Curses.
338 See \fB\%user_caps\fP(5) for an overview of the way
339 .I \%ncurses
340 uses this extended information.
341 .PP
342 Applications that manipulate terminal data can use the definitions
343 described in \fB\%terminfo_variables\fP(3NCURSES) associating the long capability
344 names with members of a
345 .I \%TERMTYPE
346 structure.
347 .
348 .SS "Extended Number Format"
349 On occasion,
350 16-bit signed integers are not large enough.
351 .I \%ncurses
352 6.1 introduced a new format
353 by making a few changes to the legacy format:
354 .bP
355 a different magic number
356 (octal 01036)
357 .bP
358 changing the type for the \fInumber\fP array from signed 16-bit integers
359 to signed 32-bit integers.
360 .PP
361 To maintain compatibility,
362 the library presents the same data structures
363 to direct users of the
364 .I \%TERMTYPE
365 structure as in previous formats.
366 However,
367 that cannot provide callers with the extended numbers.
368 The library uses a similar but hidden data structure
369 .I \%TERMTYPE2
370 to provide data for the
371 .I \%term\%info
372 functions.
373 .SH FILES
374 .TP
375 .I /etc/terminfo
376 compiled terminal description database
377 .SH PORTABILITY
378 .SS setupterm
379 Note that it is possible for
380 .B setupterm
381 to expect a different set of capabilities
382 than are actually present in the file.
383 Either the database may have been updated since
384 .B setupterm
385 was recompiled
386 (resulting in extra unrecognized entries in the file)
387 or the program may have been recompiled more recently
388 than the database was updated
389 (resulting in missing entries).
390 The routine
391 .B setupterm
392 must be prepared for both possibilities \-
393 this is why the numbers and sizes are included.
394 Also,
395 new capabilities must always be added at the end of the lists
396 of Boolean,
397 number,
398 and string capabilities.
399 .SS "Binary Format"
400 X/Open Curses does not specify a format for the
401 .I \%term\%info
402 database.
403 System\ V
404 .I curses
405 used a directory-tree of binary files,
406 one per terminal description.
407 .PP
408 Despite the consistent use of little-endian numbers and the otherwise
409 self-describing format,
410 it is not wise to count on portability of binary
411 .I \%term\%info
412 entries between commercial Unix versions.
413 The problem is that there are at least three versions of
414 .I \%term\%info
415 (under HP\-UX,
416 AIX,
417 and OSF/1)
418 each of which diverged from System\ V
419 .I \%term\%info
420 after SVr1,
421 and added extension capabilities to the string table that
422 (in the binary format)
423 collide with System\ V and X/Open Curses extensions.
424 See \fB\%terminfo\fP(5) for detailed
425 discussion of
426 .I \%term\%info
427 source compatibility issues.
428 .PP
429 This implementation is by default compatible with the binary
430 .I \%term\%info
431 format used by Solaris
432 .IR curses ,
433 except in a few less-used details
434 where it was found that the latter did not match X/Open Curses.
435 The format used by the other Unix versions
436 can be matched by building
437 .I \%ncurses
438 with different configuration options.
439 .SS "Magic Codes"
440 The magic number in a binary
441 .I \%term\%info
442 file is the first 16 bits
443 (two bytes).
444 Besides making it more reliable for the library to check that a file is
445 .IR \%term\%info ,
446 utilities such as \fIfile\fP(1) also use that to tell what the
447 file-format is.
448 System\ V defined more than one magic number,
449 with 0433,
450 0435 as screen-dumps
451 (see \fB\%scr_dump\fP(5)).
452 This implementation uses 01036 as a continuation of that sequence,
453 but with a different high-order byte to avoid confusion.
454 .SS "The \fITERMTYPE\fP Structure"
455 Direct access to the
456 .I \%TERMTYPE
457 structure is provided for legacy applications.
458 Portable applications should use \fB\%tigetflag\fP(3NCURSES) and related
459 functions to read terminal capabilities.
460 .SS "Mixed-case Terminal Names"
461 A small number of terminal descriptions use uppercase characters in
462 their names.
463 If the underlying file system ignores the difference between
464 uppercase and lowercase,
465 .I \%ncurses
466 represents the \*(``first character\*('' of the terminal name used as
467 the intermediate level of a directory tree in (two-character)
468 hexadecimal form.
469 .SS Limits
470 .I \%ncurses
471 stores compiled terminal descriptions in three related formats,
472 described in the subsections
473 .bP
474 .BR "Legacy Storage Format" ,
475 and
476 .bP
477 .BR "Extended Storage Format" ,
478 and
479 .bP
480 .BR "Extended Number Format" .
481 .PP
482 The legacy storage format and the extended number format differ by
483 the types of numeric capability that they can store
484 (for example,
485 16- versus 32-bit integers).
486 The extended storage format introduced by
487 .I \%ncurses
488 5.0 adds data to either of these formats.
489 .PP
490 Some limitations apply:
491 .bP
492 total compiled entries cannot exceed 4096 bytes in the legacy format.
493 .bP
494 total compiled entries cannot exceed 32768 bytes in the extended format.
495 .bP
496 the name field cannot exceed 128 bytes.
497 .PP
498 Compiled entries are limited to 32768 bytes because offsets into the
499 \fIstrings table\fP use two-byte integers.
500 The legacy format could have supported 32768-byte entries,
501 but was limited to a virtual memory page's 4096 bytes.
502 .SH EXAMPLES
503 Here is a
504 .I \%term\%info
505 description of the Lear-Siegler ADM-3,
506 a popular though rather stupid early terminal.
507 .PP
508 .EX
509 adm3a|lsi adm3a,
510 am,
511 cols#80, lines#24,
512 bel=\*^G, clear=\e032$<1>, cr=\*^M, cub1=\*^H, cud1=\*^J,
513 cuf1=\*^L, cup=\eE=%p1%{32}%+%c%p2%{32}%+%c, cuu1=\*^K,
514 home=\*^\*^, ind=\*^J,
515 .EE
516 .PP
517 A hexadecimal dump of its compiled terminal description
518 (in legacy format)
519 follows.
520 .PP
521 .if t .in +4n
522 .ft \*(CW
523 .TS
524 Lp-1.
525 0000 1a 01 10 00 02 00 03 00 82 00 31 00 61 64 6d 33 ........ ..1.adm3
526 0010 61 7c 6c 73 69 20 61 64 6d 33 61 00 00 01 50 00 a|lsi ad m3a...P.
527 0020 ff ff 18 00 ff ff 00 00 02 00 ff ff ff ff 04 00 ........ ........
528 0030 ff ff ff ff ff ff ff ff 0a 00 25 00 27 00 ff ff ........ ..%.\*'...
529 0040 29 00 ff ff ff ff 2b 00 ff ff 2d 00 ff ff ff ff ).....+. ..\-.....
530 0050 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
531 0060 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
532 0070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
533 0080 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
534 0090 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
535 00a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
536 00b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
537 00c0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
538 00d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
539 00e0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
540 00f0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
541 0100 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
542 0110 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
543 0120 ff ff ff ff ff ff 2f 00 07 00 0d 00 1a 24 3c 31 ....../. .....$<1
544 0130 3e 00 1b 3d 25 70 31 25 7b 33 32 7d 25 2b 25 63 >..=%p1% {32}%+%c
545 0140 25 70 32 25 7b 33 32 7d 25 2b 25 63 00 0a 00 1e %p2%{32} %+%c....
546 0150 00 08 00 0c 00 0b 00 0a 00 ........ .
547 .TE
548 .ft
549 .in
550 .SH AUTHORS
551 Thomas E. Dickey
552 .br
553 extended
554 .I \%term\%info
555 format for
556 .I \%ncurses
557 5.0
558 .br
559 hashed database support for
560 .I \%ncurses
561 5.6
562 .br
563 extended number support for
564 .I \%ncurses
565 6.1
566 .sp
567 Eric S. Raymond
568 .br
569 documented legacy
570 .I \%term\%info
571 format
572 (that used by
573 .IR \%pcurses ).
574 .SH SEE ALSO
575 \fB\%ncurses\fP(3NCURSES),
576 \fB\%terminfo\fP(3NCURSES),
577 \fB\%terminfo\fP(5),
578 \fB\%user_caps\fP(5)