| Main index | Section 5 | 日本語 | Options |
| directory tree | |
| A two-level scheme is used to avoid a linear search of a huge Unix system directory: /usr/share/misc/terminfo/c/name where name is the name of the terminal, and c is the first character of name. Thus, act4 can be found in the file /usr/share/misc/terminfo/a/act4. Synonyms for the same terminal are implemented by multiple links to the same compiled file. | |
| hashed database | |
| Using Berkeley database, two types of records are stored: the terminfo data in the same format as stored in a directory tree with the terminfo's primary name as a key, and records containing only aliases pointing to the primary name. | |
| If built to write hashed databases, ncurses can still read terminfo databases organized as a directory tree, but cannot write entries into the directory tree. It can write (or rewrite) entries in the hashed database. | |
| ncurses distinguishes the two cases in the TERMINFO and TERMINFO_DIRS environment variable by assuming a directory tree for entries that correspond to an existing directory, and hashed database otherwise. | |
The compiled file is created with the tic program, and read by the routine setupterm(3X). The file is divided into six parts:
a) header,
b) terminal names,
c) Boolean flags,
d) numbers,
e) strings, and
f) string table.
The header section begins the file. This section contains six short integers in the format described below. These integers are
(1) the magic number (octal 0432);
(2) the size, in bytes, of the terminal names section;
(3) the number of bytes in the Boolean flags section;
(4) the number of short integers in the numbers section;
(5) the number of offsets (short integers) in the strings section;
(6) the size, in bytes, of the string table.
The capabilities in the Boolean flags, numbers, and strings sections are in the same order as the file <term.h>.
Short integers are signed, in the range -32768 to 32767. They are stored as two 8-bit bytes. The first byte contains the least significant 8 bits of the value, and the second byte contains the most significant 8 bits. (Thus, the value represented is 256*second+first.) This format corresponds to the hardware of the VAX and PDP-11 (that is, little-endian machines). Machines where this does not correspond to the hardware must read the integers as two bytes and compute the little-endian value.
Numbers in a terminal description, whether they are entries in the numbers or strings table, are positive integers. Boolean flags are treated as positive one-byte integers. In each case, those positive integers represent a terminal capability. The terminal compiler tic uses negative integers to handle the cases where a capability is not available:
| &#187; | If a capability is absent from this terminal, tic stores a -1 in the corresponding table. |
|
The integer value -1 is represented by two bytes 0377, 0377.
Absent Boolean values are represented by the byte 0 (false). | |
| &#187; | If a capability has been canceled from this terminal, tic stores a -2 in the corresponding table. |
|
The integer value -2 is represented by two bytes 0377, 0376.
The Boolean value -2 is represented by the byte 0376. | |
| &#187; | Other negative values are illegal. |
The Boolean flags section has one byte for each flag. Boolean capabilities are either 1 or 0 (true or false) according to whether the terminal supports the given capability or not.
Between the Boolean flags section and the number section, a null byte will be inserted, if necessary, to ensure that the number section begins on an even byte This is a relic of the PDP-11's word-addressed architecture, originally designed to avoid traps induced by addressing a word on an odd byte boundary. All short integers are aligned on a short word boundary.
The numbers section is similar to the Boolean flags section. Each capability takes up two bytes, and is stored as a little-endian short integer.
The strings section is also similar. Each capability is stored as a short integer. The capability value is an index into the string table.
The string table is the last section. It contains all of the values of string capabilities referenced in the strings section. Each string is null-terminated. Special characters in ^X or \c notation are stored in their interpreted form, not the printing representation. Padding information $<nn> and parameter information %x are stored intact in uninterpreted form.
The ncurses libraries and applications support extended terminfo binary format, allowing users to define capabilities which are loaded at runtime. This extension is made possible by using the fact that the other implementations stop reading the terminfo data when they have reached the end of the size given in the header. ncurses checks the size, and if it exceeds that due to the predefined data, continues to parse according to its own scheme.
First, it reads the extended header (5 short integers):
(1) count of extended Boolean capabilities (2) count of extended numeric capabilities (3) count of extended string capabilities (4) count of the items in extended string table (5) size of the extended string table in bytes
The count- and size-values for the extended string table include the extended capability names as well as extended capability values.
Using the counts and sizes, ncurses allocates arrays and reads data for the extended capabilities in the same order as the header information.
The extended string table contains values for string capabilities. After the end of these values, it contains the names for each of the extended capabilities in order, e.g., Booleans, then numbers and finally strings.
By storing terminal descriptions in this way, ncurses is able to provide a database useful with legacy applications, as well as providing data for applications which need more than the predefined capabilities. See user_caps(5) for an overview of the way ncurses uses this extended information.
Applications which manipulate terminal data can use the definitions described in term_variables(3X) which associate the long capability names with members of a TERMTYPE structure.
| &#187; | a different magic number (octal 01036) |
| &#187; | changing the type for the number array from signed 16-bit integers to signed 32-bit integers. |
| /usr/share/misc/terminfo | compiled terminal description database |
Despite the consistent use of little-endian for numbers and the otherwise self-describing format, it is not wise to count on portability of binary terminfo entries between commercial Unix versions. The problem is that there are at least three versions of terminfo (under HP-UX, AIX, and OSF/1) which diverged from System V terminfo after SVr1, and have added extension capabilities to the string table that (in the binary format) collide with System V and X/Open Curses extensions. See terminfo(5) for detailed discussion of terminfo source compatibility issues.
This implementation is by default compatible with the binary terminfo format used by Solaris curses, except in a few less-used details where it was found that the latter did not match X/Open Curses. The format used by the other Unix versions can be matched by building ncurses with different configuration options.
| &#187; | LEGACY STORAGE FORMAT, and |
| &#187; | EXTENDED STORAGE FORMAT, and |
| &#187; | EXTENDED NUMBER FORMAT. |
Some limitations apply:
| &#187; | total compiled entries cannot exceed 4096 bytes in the legacy format. |
| &#187; | total compiled entries cannot exceed 32768 bytes in the extended format. |
| &#187; | the name field cannot exceed 128 bytes. |
adm3a|lsi adm3a,
am,
cols#80, lines#24,
bel=^G, clear=\032$<1>, cr=^M, cub1=^H, cud1=^J,
cuf1=^L, cup=\E=%p1%{32}%+%c%p2%{32}%+%c, cuu1=^K,
home=^^, ind=^J,
and a hexadecimal dump of the compiled terminal description:
Eric S. Raymond
documented legacy terminfo format, e.g., from pcurses.
| 2024-04-20 | term (5) | ncurses 6.5 |
| Main index | Section 5 | 日本語 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
| “ | Do you laugh when the waiter drops a tray full of dishes? Unix weenies do. They're the first ones to laugh at hapless users, trying to figure out an error message that doesn't have anything to do with what they just typed. | ” |
| — The Unix Haters' handbook | ||