3 ****************************************************************************
4 * Copyright 2018-2023,2024 Thomas E. Dickey *
5 * Copyright 1998-2016,2017 Free Software Foundation, Inc. *
7 * Permission is hereby granted, free of charge, to any person obtaining a *
8 * copy of this software and associated documentation files (the *
9 * "Software"), to deal in the Software without restriction, including *
10 * without limitation the rights to use, copy, modify, merge, publish, *
11 * distribute, distribute with modifications, sublicense, and/or sell *
12 * copies of the Software, and to permit persons to whom the Software is *
13 * furnished to do so, subject to the following conditions: *
15 * The above copyright notice and this permission notice shall be included *
16 * in all copies or substantial portions of the Software. *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
21 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
24 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
26 * Except as contained in this notice, the name(s) of the above copyright *
27 * holders shall not be used in advertising or otherwise to promote the *
28 * sale, use or other dealings in this Software without prior written *
30 ****************************************************************************
31 * @Id: term.5,v 1.78 2024/05/11 20:39:53 tom Exp @
33 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
36 <meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
37 <meta name="generator" content="Manpage converted by man2html - see https://invisible-island.net/scripts/readme.html#others_scripts">
38 <TITLE>term 5 2024-05-11 ncurses 6.5 File formats</TITLE>
39 <link rel="author" href="mailto:bug-ncurses@gnu.org">
43 <H1 class="no-header">term 5 2024-05-11 ncurses 6.5 File formats</H1>
45 <STRONG><A HREF="term.5.html">term(5)</A></STRONG> File formats <STRONG><A HREF="term.5.html">term(5)</A></STRONG>
50 </PRE><H2><a name="h2-NAME">NAME</a></H2><PRE>
51 term - compiled <EM>terminfo</EM> terminal description
54 </PRE><H2><a name="h2-DESCRIPTION">DESCRIPTION</a></H2><PRE>
55 <STRONG><A HREF="tic.1m.html">tic(1)</A></STRONG> compiles a <EM>terminfo</EM> terminal type description, and <STRONG><A HREF="curs_terminfo.3x.html">setupterm(3x)</A></STRONG>
56 reads it. A compiled description may be stored in a file or in a
57 database of, potentially, many such descriptions. Further, a compiled
58 description may be in one of two formats: one similar to that used by
59 System V, and a newer, extensible format employed exclusively by
63 </PRE><H3><a name="h3-Storage-Location">Storage Location</a></H3><PRE>
64 Compiled <EM>terminfo</EM> <EM>descriptions</EM> <EM>are</EM> <EM>placed</EM> under the directory
65 <EM>/usr/share/terminfo</EM>. One of two configurations is selected when
66 building the <EM>ncurses</EM> libraries.
68 <STRONG>directory</STRONG> <STRONG>tree</STRONG>
69 A two-level scheme is used to avoid a linear search of a huge Unix
70 system directory: <EM>/usr/share/terminfo/</EM>c<EM>/</EM>name where <EM>name</EM> is the
71 name of the terminal, and <EM>c</EM> is the first character of <EM>name</EM>. Thus,
72 the compiled description of terminal type "act4" is found in the
73 file <EM>/usr/share/terminfo/a/act4</EM>. Synonyms for the same terminal
74 are implemented by multiple links to the same compiled file.
76 <STRONG>hashed</STRONG> <STRONG>database</STRONG>
77 Using the Berkeley database API, two types of records are stored:
78 the <EM>terminfo</EM> data in the same format as that stored in a directory
79 tree with the terminal's primary type name as a key, and records
80 containing only aliases pointing to the primary name.
82 If built to write hashed databases, <EM>ncurses</EM> can still read <EM>term-</EM>
83 <EM>info</EM> databases organized as a directory tree, but cannot write
84 entries into the directory tree. It can write (or rewrite)
85 entries in the hashed database.
87 <EM>ncurses</EM> distinguishes the two cases in the <EM>TERMINFO</EM> and
88 <EM>TERMINFO</EM><STRONG>_</STRONG><EM>DIRS</EM> environment variable by assuming a directory tree
89 for entries that correspond to an existing directory, and a hashed
93 </PRE><H3><a name="h3-Legacy-Storage-Format">Legacy Storage Format</a></H3><PRE>
94 The format has been chosen so that it will be the same on all hardware.
95 A byte of at least eight bits' width is assumed, but no assumptions
96 about bit ordering or sign extension are made.
98 The file is divided into six parts:
102 (b) <EM>terminal</EM> <EM>names</EM>,
104 (c) <EM>Boolean</EM> <EM>flags</EM>,
106 (d) <EM>numbers</EM>,
108 (e) <EM>strings</EM>, and
110 (f) a <EM>string</EM> <EM>table</EM>.
112 The <EM>header</EM> section begins the file. This section contains six short
113 integers in the format described below. These integers are
115 (1) the <EM>magic</EM> <EM>number</EM>
119 in bytes, of the <EM>terminal</EM> <EM>names</EM> section;
121 (3) the number of bytes in the <EM>Boolean</EM> <EM>flags</EM> section;
123 (4) the number of short integers in the <EM>numbers</EM> section;
125 (5) the number of offsets
126 (short integers) in the <EM>strings</EM> section;
129 in bytes, of the <EM>string</EM> <EM>table</EM>.
131 The capabilities in the <EM>Boolean</EM> <EM>flags</EM>, <EM>numbers</EM>, and <EM>strings</EM> sections
132 are in the same order as in the header file <EM>term.h</EM>.
134 Short integers are signed, in the range -32768 to 32767, and stored in
135 little-endian format.
137 Numbers in a terminal description, whether they are entries in the
138 <EM>numbers</EM> or <EM>strings</EM> table, are positive integers. Boolean flags are
139 treated as positive one-byte integers. In each case, those positive
140 integers represent a terminal capability. The terminal compiler <EM>tic</EM>
141 uses negative integers to handle the cases where a capability is not
144 <STRONG>o</STRONG> If a capability is absent from this terminal, <EM>tic</EM> stores a -1 in
145 the corresponding table.
147 The integer value -1 is represented by two bytes 0377, 0377.
148 Absent Boolean values are represented by the byte 0 (false).
150 <STRONG>o</STRONG> If a capability has been canceled from this terminal, <EM>tic</EM> stores a
151 -2 in the corresponding table.
153 The integer value -2 is represented by two bytes 0377, 0376.
154 The Boolean value -2 is represented by the byte 0376.
156 <STRONG>o</STRONG> Other negative values are illegal.
158 The <EM>terminal</EM> <EM>names</EM> section comes after the <EM>header</EM>. It contains the
159 first line of the <EM>terminfo</EM> description, listing the various names for
160 the terminal, separated by the "|" character. The <EM>terminal</EM> <EM>names</EM>
161 section is terminated with an ASCII NUL character.
163 The <EM>Boolean</EM> <EM>flags</EM> section has one byte for each flag. Boolean
164 capabilities are either 1 or 0 (true or false) according to whether the
165 terminal supports the given capability or not.
167 Between the <EM>Boolean</EM> <EM>flags</EM> section and the <EM>number</EM> section, a null byte
168 will be inserted, if necessary, to ensure that the <EM>number</EM> section
169 begins on an even byte This is a relic of the PDP-11's word-addressed
170 architecture, originally designed to avoid traps induced by addressing
171 a word on an odd byte boundary. All short integers are aligned on a
174 The <EM>numbers</EM> section is similar to the <EM>Boolean</EM> <EM>flags</EM> section. Each
175 capability takes up two bytes, and is stored as a little-endian short
178 The <EM>strings</EM> section is also similar. Each capability is stored as a
179 short integer. The capability value is an index into the <EM>string</EM> <EM>table</EM>.
181 The <EM>string</EM> <EM>table</EM> is the last section. It contains all of the values of
182 string capabilities referenced in the <EM>strings</EM> section. Each string is
183 null-terminated. Special characters in ^X or \c notation are stored in
184 their interpreted form, not the printing representation. Padding
185 information <STRONG>$<</STRONG><EM>nn</EM><STRONG>></STRONG> and parameter information <STRONG>%x</STRONG> are stored intact in
189 </PRE><H3><a name="h3-Extended-Storage-Format">Extended Storage Format</a></H3><PRE>
190 The previous section describes the conventional <EM>terminfo</EM> binary format.
191 With some minor variations of the offsets (see PORTABILITY), the same
192 binary format is used in all modern Unix systems. Each system uses a
193 predefined set of Boolean, number or string capabilities.
195 The <EM>ncurses</EM> libraries and applications support extended <EM>terminfo</EM> binary
196 format, allowing users to define capabilities that are loaded at
197 runtime. This extension is made possible by using the fact that the
198 other implementations stop reading the <EM>terminfo</EM> data when they reach
199 the end of the size given in the header. <EM>ncurses</EM> checks the size, and
200 if it exceeds that due to the predefined data, continues to parse
201 according to its own scheme.
203 First, it reads the extended header (5 short integers):
205 (1) count of extended Boolean capabilities
207 (2) count of extended numeric capabilities
209 (3) count of extended string capabilities
211 (4) count of the items in extended string table
213 (5) size of the extended string table in bytes
215 The count- and size-values for the extended string table include the
216 extended capability <EM>names</EM> as well as extended capability <EM>values</EM>.
218 Using the counts and sizes, <EM>ncurses</EM> allocates arrays and reads data for
219 the extended capabilities in the same order as the header information.
221 The extended string table contains values for string capabilities.
222 After the end of these values, it contains the names for each of the
223 extended capabilities in order: Boolean, numeric, and string.
225 By storing terminal descriptions in this way, <EM>ncurses</EM> is able to
226 provide a database useful with legacy applications, as well as
227 providing data for applications that require more information about a
228 terminal type than was anticipated by X/Open Curses. See <STRONG><A HREF="user_caps.5.html">user_caps(5)</A></STRONG>
229 for an overview of the way <EM>ncurses</EM> uses this extended information.
231 Applications that manipulate terminal data can use the definitions
232 described in <STRONG><A HREF="term_variables.3x.html">term_variables(3x)</A></STRONG> associating the long capability names
233 with members of a <EM>TERMTYPE</EM> structure.
236 </PRE><H3><a name="h3-Extended-Number-Format">Extended Number Format</a></H3><PRE>
237 On occasion, 16-bit signed integers are not large enough. <EM>ncurses</EM> 6.1
238 introduced a new format by making a few changes to the legacy format:
240 <STRONG>o</STRONG> a different magic number (octal 01036)
242 <STRONG>o</STRONG> changing the type for the <EM>number</EM> array from signed 16-bit integers
243 to signed 32-bit integers.
245 To maintain compatibility, the library presents the same data
246 structures to direct users of the <EM>TERMTYPE</EM> structure as in previous
247 formats. However, that cannot provide callers with the extended
248 numbers. The library uses a similar but hidden data structure
249 <EM>TERMTYPE2</EM> to provide data for the <EM>terminfo</EM> functions.
252 </PRE><H2><a name="h2-FILES">FILES</a></H2><PRE>
253 <EM>/usr/share/terminfo</EM>
254 compiled terminal description database
257 </PRE><H2><a name="h2-PORTABILITY">PORTABILITY</a></H2><PRE>
259 </PRE><H3><a name="h3-setupterm">setupterm</a></H3><PRE>
260 Note that it is possible for <STRONG>setupterm</STRONG> to expect a different set of
261 capabilities than are actually present in the file. Either the
262 database may have been updated since <STRONG>setupterm</STRONG> was recompiled
263 (resulting in extra unrecognized entries in the file) or the program
264 may have been recompiled more recently than the database was updated
265 (resulting in missing entries). The routine <STRONG>setupterm</STRONG> must be prepared
266 for both possibilities - this is why the numbers and sizes are
267 included. Also, new capabilities must always be added at the end of
268 the lists of Boolean, number, and string capabilities.
271 </PRE><H3><a name="h3-Binary-Format">Binary Format</a></H3><PRE>
272 X/Open Curses does not specify a format for the <EM>terminfo</EM> database.
273 System V <EM>curses</EM> used a directory-tree of binary files, one per terminal
276 Despite the consistent use of little-endian numbers and the otherwise
277 self-describing format, it is not wise to count on portability of
278 binary <EM>terminfo</EM> entries between commercial Unix versions. The problem
279 is that there are at least three versions of <EM>terminfo</EM> (under HP-UX,
280 AIX, and OSF/1) each of which diverged from System V <EM>terminfo</EM> after
281 SVr1, and added extension capabilities to the string table that (in the
282 binary format) collide with System V and X/Open Curses extensions. See
283 <STRONG><A HREF="terminfo.5.html">terminfo(5)</A></STRONG> for detailed discussion of <EM>terminfo</EM> source compatibility
286 This implementation is by default compatible with the binary <EM>terminfo</EM>
287 format used by Solaris <EM>curses</EM>, except in a few less-used details where
288 it was found that the latter did not match X/Open Curses. The format
289 used by the other Unix versions can be matched by building <EM>ncurses</EM> with
290 different configuration options.
293 </PRE><H3><a name="h3-Magic-Codes">Magic Codes</a></H3><PRE>
294 The magic number in a binary <EM>terminfo</EM> file is the first 16 bits (two
295 bytes). Besides making it more reliable for the library to check that
296 a file is <EM>terminfo</EM>, utilities such as <STRONG>file(1)</STRONG> also use that to tell
297 what the file-format is. System V defined more than one magic number,
298 with 0433, 0435 as screen-dumps (see <STRONG><A HREF="scr_dump.5.html">scr_dump(5)</A></STRONG>). This implementation
299 uses 01036 as a continuation of that sequence, but with a different
300 high-order byte to avoid confusion.
302 <STRONG>The</STRONG> <EM>TERMTYPE</EM> <STRONG>Structure</STRONG>
303 Direct access to the <EM>TERMTYPE</EM> structure is provided for legacy
304 applications. Portable applications should use <STRONG><A HREF="curs_terminfo.3x.html">tigetflag(3x)</A></STRONG> and
305 related functions to read terminal capabilities.
308 </PRE><H3><a name="h3-Mixed-case-Terminal-Names">Mixed-case Terminal Names</a></H3><PRE>
309 A small number of terminal descriptions use uppercase characters in
310 their names. If the underlying file system ignores the difference
311 between uppercase and lowercase, <EM>ncurses</EM> represents the "first
312 character" of the terminal name used as the intermediate level of a
313 directory tree in (two-character) hexadecimal form.
316 </PRE><H3><a name="h3-Limits">Limits</a></H3><PRE>
317 <EM>ncurses</EM> stores compiled terminal descriptions in three related formats,
318 described in the subsections
320 <STRONG>o</STRONG> <STRONG>Legacy</STRONG> <STRONG>Storage</STRONG> <STRONG>Format</STRONG>, and
322 <STRONG>o</STRONG> <STRONG>Extended</STRONG> <STRONG>Storage</STRONG> <STRONG>Format</STRONG>, and
324 <STRONG>o</STRONG> <STRONG>Extended</STRONG> <STRONG>Number</STRONG> <STRONG>Format</STRONG>.
326 The legacy storage format and the extended number format differ by the
327 types of numeric capability that they can store (for example, 16-
328 versus 32-bit integers). The extended storage format introduced by
329 <EM>ncurses</EM> 5.0 adds data to either of these formats.
331 Some limitations apply:
333 <STRONG>o</STRONG> total compiled entries cannot exceed 4096 bytes in the legacy
336 <STRONG>o</STRONG> total compiled entries cannot exceed 32768 bytes in the extended
339 <STRONG>o</STRONG> the name field cannot exceed 128 bytes.
341 Compiled entries are limited to 32768 bytes because offsets into the
342 <EM>strings</EM> <EM>table</EM> use two-byte integers. The legacy format could have
343 supported 32768-byte entries, but was limited to a virtual memory
347 </PRE><H2><a name="h2-EXAMPLES">EXAMPLES</a></H2><PRE>
348 Here is a <EM>terminfo</EM> description of the Lear-Siegler ADM-3, a popular
349 though rather stupid early terminal.
354 bel=^G, clear=\032$<1>, cr=^M, cub1=^H, cud1=^J,
355 cuf1=^L, cup=\E=%p1%{32}%+%c%p2%{32}%+%c, cuu1=^K,
358 A hexadecimal dump of its compiled terminal description (in legacy
361 0000 1a 01 10 00 02 00 03 00 82 00 31 00 61 64 6d 33 ........ ..1.adm3
362 0010 61 7c 6c 73 69 20 61 64 6d 33 61 00 00 01 50 00 a|lsi ad m3a...P.
363 0020 ff ff 18 00 ff ff 00 00 02 00 ff ff ff ff 04 00 ........ ........
364 0030 ff ff ff ff ff ff ff ff 0a 00 25 00 27 00 ff ff ........ ..%.'...
365 0040 29 00 ff ff ff ff 2b 00 ff ff 2d 00 ff ff ff ff ).....+. ..-.....
366 0050 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
367 0060 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
368 0070 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
369 0080 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
370 0090 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
371 00a0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
372 00b0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
373 00c0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
374 00d0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
375 00e0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
376 00f0 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
377 0100 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
378 0110 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ........ ........
379 0120 ff ff ff ff ff ff 2f 00 07 00 0d 00 1a 24 3c 31 ....../. .....$<1
380 0130 3e 00 1b 3d 25 70 31 25 7b 33 32 7d 25 2b 25 63 >..=%p1% {32}%+%c
381 0140 25 70 32 25 7b 33 32 7d 25 2b 25 63 00 0a 00 1e %p2%{32} %+%c....
382 0150 00 08 00 0c 00 0b 00 0a 00 ........ .
385 </PRE><H2><a name="h2-AUTHORS">AUTHORS</a></H2><PRE>
387 extended <EM>terminfo</EM> format for <EM>ncurses</EM> 5.0
388 hashed database support for <EM>ncurses</EM> 5.6
389 extended number support for <EM>ncurses</EM> 6.1
392 documented legacy <EM>terminfo</EM> format (that used by <EM>pcurses</EM>).
395 </PRE><H2><a name="h2-SEE-ALSO">SEE ALSO</a></H2><PRE>
396 <STRONG><A HREF="ncurses.3x.html">curses(3x)</A></STRONG>, <STRONG><A HREF="curs_terminfo.3x.html">curs_terminfo(3x)</A></STRONG>, <STRONG><A HREF="terminfo.5.html">terminfo(5)</A></STRONG>, <STRONG><A HREF="user_caps.5.html">user_caps(5)</A></STRONG>
400 ncurses 6.5 2024-05-11 <STRONG><A HREF="term.5.html">term(5)</A></STRONG>
404 <li><a href="#h2-NAME">NAME</a></li>
405 <li><a href="#h2-DESCRIPTION">DESCRIPTION</a>
407 <li><a href="#h3-Storage-Location">Storage Location</a></li>
408 <li><a href="#h3-Legacy-Storage-Format">Legacy Storage Format</a></li>
409 <li><a href="#h3-Extended-Storage-Format">Extended Storage Format</a></li>
410 <li><a href="#h3-Extended-Number-Format">Extended Number Format</a></li>
413 <li><a href="#h2-FILES">FILES</a></li>
414 <li><a href="#h2-PORTABILITY">PORTABILITY</a>
416 <li><a href="#h3-setupterm">setupterm</a></li>
417 <li><a href="#h3-Binary-Format">Binary Format</a></li>
418 <li><a href="#h3-Magic-Codes">Magic Codes</a></li>
419 <li><a href="#h3-Mixed-case-Terminal-Names">Mixed-case Terminal Names</a></li>
420 <li><a href="#h3-Limits">Limits</a></li>
423 <li><a href="#h2-EXAMPLES">EXAMPLES</a></li>
424 <li><a href="#h2-AUTHORS">AUTHORS</a></li>
425 <li><a href="#h2-SEE-ALSO">SEE ALSO</a></li>