tic.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /****************************************************************************
  2. * Copyright 2018-2019,2020 Thomas E. Dickey *
  3. * Copyright 1998-2012,2017 Free Software Foundation, Inc. *
  4. * *
  5. * Permission is hereby granted, free of charge, to any person obtaining a *
  6. * copy of this software and associated documentation files (the *
  7. * "Software"), to deal in the Software without restriction, including *
  8. * without limitation the rights to use, copy, modify, merge, publish, *
  9. * distribute, distribute with modifications, sublicense, and/or sell *
  10. * copies of the Software, and to permit persons to whom the Software is *
  11. * furnished to do so, subject to the following conditions: *
  12. * *
  13. * The above copyright notice and this permission notice shall be included *
  14. * in all copies or substantial portions of the Software. *
  15. * *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
  17. * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
  19. * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
  20. * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
  21. * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
  22. * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
  23. * *
  24. * Except as contained in this notice, the name(s) of the above copyright *
  25. * holders shall not be used in advertising or otherwise to promote the *
  26. * sale, use or other dealings in this Software without prior written *
  27. * authorization. *
  28. ****************************************************************************/
  29. /****************************************************************************
  30. * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
  31. * and: Eric S. Raymond <esr@snark.thyrsus.com> *
  32. * and: Thomas E. Dickey 1996 on *
  33. ****************************************************************************/
  34. /*
  35. * $Id: tic.h,v 1.81 2020/02/02 23:34:34 tom Exp $
  36. * tic.h - Global variables and structures for the terminfo compiler.
  37. */
  38. #ifndef __TIC_H
  39. #define __TIC_H
  40. /* *INDENT-OFF* */
  41. #ifdef __cplusplus
  42. extern "C" {
  43. #endif
  44. #include <ncurses_cfg.h>
  45. #include <curses.h> /* for the _tracef() prototype, ERR/OK, bool defs */
  46. /*
  47. ** The format of SVr2 compiled terminfo files is as follows:
  48. **
  49. ** Header (12 bytes), containing information given below
  50. ** Names Section, containing the names of the terminal
  51. ** Boolean Section, containing the values of all of the
  52. ** boolean capabilities
  53. ** A null byte may be inserted here to make
  54. ** sure that the Number Section begins on an
  55. ** even word boundary.
  56. ** Number Section, containing the values of all of the numeric
  57. ** capabilities, each as a short integer
  58. ** String Section, containing short integer offsets into the
  59. ** String Table, one per string capability
  60. ** String Table, containing the actual characters of the string
  61. ** capabilities.
  62. **
  63. ** In the SVr2 format, "short" means signed 16-bit numbers, which is sometimes
  64. ** inconvenient. The numbers are signed, to provide for absent and canceled
  65. ** values. ncurses6.1 introduced an extension to this compiled format, by
  66. ** making the Number Section a list of signed 32-bit integers.
  67. **
  68. ** NOTE that all short integers in the file are stored using VAX/PDP-style
  69. ** byte-order, i.e., least-significant byte first.
  70. **
  71. ** There is no structure definition here because it would only confuse
  72. ** matters. Terminfo format is a raw byte layout, not a structure
  73. ** dump. If you happen to be on a little-endian machine with 16-bit
  74. ** shorts that requires no padding between short members in a struct,
  75. ** then there is a natural C structure that captures the header, but
  76. ** not very helpfully.
  77. */
  78. #define MAGIC 0432 /* first two bytes of a compiled entry */
  79. #define MAGIC2 01036 /* first two bytes of a compiled 32-bit entry */
  80. #undef BYTE
  81. #define BYTE(p,n) (unsigned char)((p)[n])
  82. #define IS_NEG1(p) ((BYTE(p,0) == 0377) && (BYTE(p,1) == 0377))
  83. #define IS_NEG2(p) ((BYTE(p,0) == 0376) && (BYTE(p,1) == 0377))
  84. #define LOW_MSB(p) (BYTE(p,0) + 256*BYTE(p,1))
  85. #define IS_TIC_MAGIC(p) (LOW_MSB(p) == MAGIC || LOW_MSB(p) == MAGIC2)
  86. #define quick_prefix(s) (!strncmp((s), "b64:", (size_t)4) || !strncmp((s), "hex:", (size_t)4))
  87. /*
  88. * The "maximum" here is misleading; XSI guarantees minimum values, which a
  89. * given implementation may exceed.
  90. */
  91. #define MAX_NAME_SIZE 512 /* maximum legal name field size (XSI:127) */
  92. #define MAX_ENTRY_SIZE1 4096 /* maximum legal entry size (SVr2) */
  93. #define MAX_ENTRY_SIZE2 32768 /* maximum legal entry size (ncurses6.1) */
  94. #if NCURSES_EXT_COLORS && HAVE_INIT_EXTENDED_COLOR
  95. #define MAX_ENTRY_SIZE MAX_ENTRY_SIZE2
  96. #else
  97. #define MAX_ENTRY_SIZE MAX_ENTRY_SIZE1
  98. #endif
  99. /*
  100. * The maximum size of individual name or alias is guaranteed in XSI to be at
  101. * least 14, since that corresponds to the older filename lengths. Newer
  102. * systems allow longer aliases, though not many terminal descriptions are
  103. * written to use them. The MAX_ALIAS symbol is used for warnings.
  104. */
  105. #if HAVE_LONG_FILE_NAMES
  106. #define MAX_ALIAS 32 /* smaller than POSIX minimum for PATH_MAX */
  107. #else
  108. #define MAX_ALIAS 14 /* SVr3 filename length */
  109. #endif
  110. /* location of user's personal info directory */
  111. #define PRIVATE_INFO "%s/.terminfo" /* plug getenv("HOME") into %s */
  112. /*
  113. * Some traces are designed to be used via tic's verbose option (and similar in
  114. * infocmp and toe) rather than the 'trace()' function. So we use the bits
  115. * above the normal trace() parameter as a debug-level.
  116. */
  117. #define MAX_DEBUG_LEVEL 15
  118. #define DEBUG_LEVEL(n) ((n) << TRACE_SHIFT)
  119. #define set_trace_level(n) \
  120. _nc_tracing &= DEBUG_LEVEL(MAX_DEBUG_LEVEL) \
  121. + DEBUG_LEVEL(MAX_DEBUG_LEVEL) - 1, \
  122. _nc_tracing |= DEBUG_LEVEL(n)
  123. #ifdef TRACE
  124. #define DEBUG(n, a) if (_nc_tracing >= DEBUG_LEVEL(n)) _tracef a
  125. #else
  126. #define DEBUG(n, a) /*nothing*/
  127. #endif
  128. /*
  129. * These are the types of tokens returned by the scanner. The first
  130. * three are also used in the hash table of capability names. The scanner
  131. * returns one of these values after loading the specifics into the global
  132. * structure curr_token.
  133. */
  134. #define BOOLEAN 0 /* Boolean capability */
  135. #define NUMBER 1 /* Numeric capability */
  136. #define STRING 2 /* String-valued capability */
  137. #define CANCEL 3 /* Capability to be cancelled in following tc's */
  138. #define NAMES 4 /* The names for a terminal type */
  139. #define UNDEF 5 /* Undefined */
  140. #define NO_PUSHBACK -1 /* used in pushtype to indicate no pushback */
  141. /*
  142. * The global structure in which the specific parts of a
  143. * scanned token are returned.
  144. */
  145. struct token
  146. {
  147. char *tk_name; /* name of capability */
  148. int tk_valnumber; /* value of capability (if a number) */
  149. char *tk_valstring; /* value of capability (if a string) */
  150. };
  151. /*
  152. * Offsets to string capabilities, with the corresponding functionkey codes.
  153. */
  154. struct tinfo_fkeys {
  155. unsigned offset;
  156. chtype code;
  157. };
  158. typedef short HashValue;
  159. /*
  160. * The file comp_captab.c contains an array of these structures, one per
  161. * possible capability. These are indexed by a hash table array of pointers to
  162. * the same structures for use by the parser.
  163. */
  164. struct name_table_entry
  165. {
  166. const char *nte_name; /* name to hash on */
  167. int nte_type; /* BOOLEAN, NUMBER or STRING */
  168. HashValue nte_index; /* index of associated variable in its array */
  169. HashValue nte_link; /* index in table of next hash, or -1 */
  170. };
  171. /*
  172. * Use this structure to hide differences between terminfo and termcap tables.
  173. */
  174. typedef struct {
  175. unsigned table_size;
  176. const HashValue *table_data;
  177. HashValue (*hash_of)(const char *);
  178. int (*compare_names)(const char *, const char *);
  179. } HashData;
  180. struct alias
  181. {
  182. const char *from;
  183. const char *to;
  184. const char *source;
  185. };
  186. #define NOTFOUND ((struct name_table_entry *) 0)
  187. /*
  188. * The file comp_userdefs.c contains an array of these structures, one per
  189. * possible capability. These are indexed by a hash table array of pointers to
  190. * the same structures for use by the parser.
  191. */
  192. struct user_table_entry
  193. {
  194. const char *ute_name; /* name to hash on */
  195. int ute_type; /* mask (BOOLEAN, NUMBER, STRING) */
  196. unsigned ute_argc; /* number of parameters */
  197. unsigned ute_args; /* bit-mask for string parameters */
  198. HashValue ute_index; /* index of associated variable in its array */
  199. HashValue ute_link; /* index in table of next hash, or -1 */
  200. };
  201. /*
  202. * The casts are required for correct sign-propagation with systems such as
  203. * AIX, IRIX64, Solaris which default to unsigned characters. The C standard
  204. * leaves this detail unspecified.
  205. */
  206. /* out-of-band values for representing absent capabilities */
  207. #define ABSENT_BOOLEAN ((signed char)-1) /* 255 */
  208. #define ABSENT_NUMERIC (-1)
  209. #define ABSENT_STRING (char *)0
  210. /* out-of-band values for representing cancels */
  211. #define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */
  212. #define CANCELLED_NUMERIC (-2)
  213. #define CANCELLED_STRING (char *)(-1)
  214. #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
  215. #define VALID_NUMERIC(s) ((s) >= 0)
  216. #define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
  217. /* termcap entries longer than this may break old binaries */
  218. #define MAX_TERMCAP_LENGTH 1023
  219. /* this is a documented limitation of terminfo */
  220. #define MAX_TERMINFO_LENGTH 4096
  221. #ifndef TERMINFO
  222. #define TERMINFO "/usr/share/terminfo"
  223. #endif
  224. #ifdef NCURSES_TERM_ENTRY_H_incl
  225. /*
  226. * These entrypoints are used only by the ncurses utilities such as tic.
  227. */
  228. #ifdef NCURSES_INTERNALS
  229. /* access.c */
  230. extern NCURSES_EXPORT(unsigned) _nc_pathlast (const char *);
  231. extern NCURSES_EXPORT(bool) _nc_is_abs_path (const char *);
  232. extern NCURSES_EXPORT(bool) _nc_is_dir_path (const char *);
  233. extern NCURSES_EXPORT(bool) _nc_is_file_path (const char *);
  234. extern NCURSES_EXPORT(char *) _nc_basename (char *);
  235. extern NCURSES_EXPORT(char *) _nc_rootname (char *);
  236. /* comp_captab.c */
  237. extern NCURSES_EXPORT(const struct name_table_entry *) _nc_get_table (bool);
  238. extern NCURSES_EXPORT(const HashData *) _nc_get_hash_info (bool);
  239. extern NCURSES_EXPORT(const struct alias *) _nc_get_alias_table (bool);
  240. /* comp_hash.c: name lookup */
  241. extern NCURSES_EXPORT(struct name_table_entry const *) _nc_find_type_entry
  242. (const char *, int, bool);
  243. extern NCURSES_EXPORT(struct user_table_entry const *) _nc_find_user_entry
  244. (const char *);
  245. /* comp_scan.c: lexical analysis */
  246. extern NCURSES_EXPORT(int) _nc_get_token (bool);
  247. extern NCURSES_EXPORT(void) _nc_panic_mode (char);
  248. extern NCURSES_EXPORT(void) _nc_push_token (int);
  249. extern NCURSES_EXPORT_VAR(int) _nc_curr_col;
  250. extern NCURSES_EXPORT_VAR(int) _nc_curr_line;
  251. extern NCURSES_EXPORT_VAR(int) _nc_syntax;
  252. extern NCURSES_EXPORT_VAR(int) _nc_strict_bsd;
  253. extern NCURSES_EXPORT_VAR(long) _nc_comment_end;
  254. extern NCURSES_EXPORT_VAR(long) _nc_comment_start;
  255. extern NCURSES_EXPORT_VAR(long) _nc_curr_file_pos;
  256. extern NCURSES_EXPORT_VAR(long) _nc_start_line;
  257. #define SYN_TERMINFO 0
  258. #define SYN_TERMCAP 1
  259. /* comp_error.c: warning & abort messages */
  260. extern NCURSES_EXPORT(const char *) _nc_get_source (void);
  261. extern NCURSES_EXPORT(void) _nc_err_abort (const char *const,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN;
  262. extern NCURSES_EXPORT(void) _nc_get_type (char *name);
  263. extern NCURSES_EXPORT(void) _nc_set_source (const char *const);
  264. extern NCURSES_EXPORT(void) _nc_set_type (const char *const);
  265. extern NCURSES_EXPORT(void) _nc_syserr_abort (const char *const,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN;
  266. extern NCURSES_EXPORT(void) _nc_warning (const char *const,...) GCC_PRINTFLIKE(1,2);
  267. extern NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings;
  268. /* comp_scan.c */
  269. extern NCURSES_EXPORT_VAR(struct token) _nc_curr_token;
  270. /* comp_userdefs.c */
  271. NCURSES_EXPORT(const struct user_table_entry *) _nc_get_userdefs_table (void);
  272. NCURSES_EXPORT(const HashData *) _nc_get_hash_user (void);
  273. /* captoinfo.c: capability conversion */
  274. extern NCURSES_EXPORT(char *) _nc_captoinfo (const char *, const char *, int const);
  275. extern NCURSES_EXPORT(char *) _nc_infotocap (const char *, const char *, int const);
  276. /* home_terminfo.c */
  277. extern NCURSES_EXPORT(char *) _nc_home_terminfo (void);
  278. /* init_keytry.c */
  279. #if BROKEN_LINKER
  280. #define _nc_tinfo_fkeys _nc_tinfo_fkeysf()
  281. extern NCURSES_EXPORT(const struct tinfo_fkeys *) _nc_tinfo_fkeysf (void);
  282. #else
  283. extern NCURSES_EXPORT_VAR(const struct tinfo_fkeys) _nc_tinfo_fkeys[];
  284. #endif
  285. /* lib_tparm.c */
  286. #define NUM_PARM 9
  287. extern NCURSES_EXPORT_VAR(int) _nc_tparm_err;
  288. extern NCURSES_EXPORT(int) _nc_tparm_analyze(const char *, char **, int *);
  289. /* lib_trace.c */
  290. extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing;
  291. extern NCURSES_EXPORT(const char *) _nc_visbuf (const char *);
  292. extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *);
  293. /* lib_tputs.c */
  294. extern NCURSES_EXPORT_VAR(int) _nc_nulls_sent; /* Add one for every null sent */
  295. /* comp_main.c: compiler main */
  296. extern const char * _nc_progname;
  297. /* db_iterator.c */
  298. extern NCURSES_EXPORT(const char *) _nc_next_db(DBDIRS *, int *);
  299. extern NCURSES_EXPORT(const char *) _nc_tic_dir (const char *);
  300. extern NCURSES_EXPORT(void) _nc_first_db(DBDIRS *, int *);
  301. extern NCURSES_EXPORT(void) _nc_last_db(void);
  302. /* write_entry.c */
  303. extern NCURSES_EXPORT(int) _nc_tic_written (void);
  304. #endif /* NCURSES_INTERNALS */
  305. /*
  306. * These entrypoints were used by tack before 1.08.
  307. */
  308. #undef NCURSES_TACK_1_08
  309. #ifdef NCURSES_INTERNALS
  310. #define NCURSES_TACK_1_08 /* nothing */
  311. #else
  312. #define NCURSES_TACK_1_08 GCC_DEPRECATED("upgrade to tack 1.08")
  313. #endif
  314. /* comp_hash.c: name lookup */
  315. extern NCURSES_EXPORT(struct name_table_entry const *) _nc_find_entry
  316. (const char *, const HashValue *) NCURSES_TACK_1_08;
  317. extern NCURSES_EXPORT(const HashValue *) _nc_get_hash_table (bool) NCURSES_TACK_1_08;
  318. /* comp_scan.c: lexical analysis */
  319. extern NCURSES_EXPORT(void) _nc_reset_input (FILE *, char *) NCURSES_TACK_1_08;
  320. /* comp_expand.c: expand string into readable form */
  321. extern NCURSES_EXPORT(char *) _nc_tic_expand (const char *, bool, int) NCURSES_TACK_1_08;
  322. /* comp_scan.c: decode string from readable form */
  323. extern NCURSES_EXPORT(int) _nc_trans_string (char *, char *) NCURSES_TACK_1_08;
  324. #endif /* NCURSES_TERM_ENTRY_H_incl */
  325. #ifdef __cplusplus
  326. }
  327. #endif
  328. /* *INDENT-ON* */
  329. #endif /* __TIC_H */