tic.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /****************************************************************************
  2. * Copyright 2018-2021,2022 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.86 2022/09/17 16:01:45 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 <ncursesw/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 &= TRACE_MAXIMUM, \
  121. _nc_tracing |= DEBUG_LEVEL(n)
  122. #ifdef TRACE
  123. #define DEBUG(n, a) if (_nc_tracing >= DEBUG_LEVEL(n)) _tracef a
  124. #else
  125. #define DEBUG(n, a) /*nothing*/
  126. #endif
  127. /*
  128. * These are the types of tokens returned by the scanner. The first
  129. * three are also used in the hash table of capability names. The scanner
  130. * returns one of these values after loading the specifics into the global
  131. * structure curr_token.
  132. */
  133. #define BOOLEAN 0 /* Boolean capability */
  134. #define NUMBER 1 /* Numeric capability */
  135. #define STRING 2 /* String-valued capability */
  136. #define CANCEL 3 /* Capability to be cancelled in following tc's */
  137. #define NAMES 4 /* The names for a terminal type */
  138. #define UNDEF 5 /* Undefined */
  139. #define NO_PUSHBACK -1 /* used in pushtype to indicate no pushback */
  140. /*
  141. * The global structure in which the specific parts of a
  142. * scanned token are returned.
  143. */
  144. struct token
  145. {
  146. char *tk_name; /* name of capability */
  147. int tk_valnumber; /* value of capability (if a number) */
  148. char *tk_valstring; /* value of capability (if a string) */
  149. };
  150. /*
  151. * Offsets to string capabilities, with the corresponding functionkey codes.
  152. */
  153. struct tinfo_fkeys {
  154. unsigned offset;
  155. chtype code;
  156. };
  157. typedef short HashValue;
  158. /*
  159. * The file comp_captab.c contains an array of these structures, one per
  160. * possible capability. These are indexed by a hash table array of pointers to
  161. * the same structures for use by the parser.
  162. */
  163. struct name_table_entry
  164. {
  165. const char *nte_name; /* name to hash on */
  166. int nte_type; /* BOOLEAN, NUMBER or STRING */
  167. HashValue nte_index; /* index of associated variable in its array */
  168. HashValue nte_link; /* index in table of next hash, or -1 */
  169. };
  170. /*
  171. * Use this structure to hide differences between terminfo and termcap tables.
  172. */
  173. typedef struct {
  174. unsigned table_size;
  175. const HashValue *table_data;
  176. HashValue (*hash_of)(const char *);
  177. int (*compare_names)(const char *, const char *);
  178. } HashData;
  179. struct alias
  180. {
  181. const char *from;
  182. const char *to;
  183. const char *source;
  184. };
  185. #define NOTFOUND ((struct name_table_entry *) 0)
  186. /*
  187. * The file comp_userdefs.c contains an array of these structures, one per
  188. * possible capability. These are indexed by a hash table array of pointers to
  189. * the same structures for use by the parser.
  190. */
  191. struct user_table_entry
  192. {
  193. const char *ute_name; /* name to hash on */
  194. int ute_type; /* mask (BOOLEAN, NUMBER, STRING) */
  195. unsigned ute_argc; /* number of parameters */
  196. unsigned ute_args; /* bit-mask for string parameters */
  197. HashValue ute_index; /* index of associated variable in its array */
  198. HashValue ute_link; /* index in table of next hash, or -1 */
  199. };
  200. /*
  201. * The casts are required for correct sign-propagation with systems such as
  202. * AIX, IRIX64, Solaris which default to unsigned characters. The C standard
  203. * leaves this detail unspecified.
  204. */
  205. /* out-of-band values for representing absent capabilities */
  206. #define ABSENT_BOOLEAN ((signed char)-1) /* 255 */
  207. #define ABSENT_NUMERIC (-1)
  208. #define ABSENT_STRING (char *)0
  209. /* out-of-band values for representing cancels */
  210. #define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */
  211. #define CANCELLED_NUMERIC (-2)
  212. #define CANCELLED_STRING (char *)(-1)
  213. #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
  214. #define VALID_NUMERIC(s) ((s) >= 0)
  215. #define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
  216. /* termcap entries longer than this may break old binaries */
  217. #define MAX_TERMCAP_LENGTH 1023
  218. /* this is a documented limitation of terminfo */
  219. #define MAX_TERMINFO_LENGTH 4096
  220. #ifndef TERMINFO
  221. #define TERMINFO "/usr/share/terminfo"
  222. #endif
  223. #ifdef NCURSES_TERM_ENTRY_H_incl
  224. /*
  225. * These entrypoints are used only by the ncurses utilities such as tic.
  226. */
  227. #ifdef NCURSES_INTERNALS
  228. /* access.c */
  229. extern NCURSES_EXPORT(unsigned) _nc_pathlast (const char *);
  230. extern NCURSES_EXPORT(bool) _nc_is_abs_path (const char *);
  231. extern NCURSES_EXPORT(bool) _nc_is_dir_path (const char *);
  232. extern NCURSES_EXPORT(bool) _nc_is_file_path (const char *);
  233. extern NCURSES_EXPORT(char *) _nc_basename (char *);
  234. extern NCURSES_EXPORT(char *) _nc_rootname (char *);
  235. /* comp_captab.c */
  236. extern NCURSES_EXPORT(const struct name_table_entry *) _nc_get_table (bool);
  237. extern NCURSES_EXPORT(const HashData *) _nc_get_hash_info (bool);
  238. extern NCURSES_EXPORT(const struct alias *) _nc_get_alias_table (bool);
  239. /* comp_hash.c: name lookup */
  240. extern NCURSES_EXPORT(struct name_table_entry const *) _nc_find_type_entry
  241. (const char *, int, bool);
  242. extern NCURSES_EXPORT(struct user_table_entry const *) _nc_find_user_entry
  243. (const char *);
  244. /* comp_scan.c: lexical analysis */
  245. extern NCURSES_EXPORT(int) _nc_get_token (bool);
  246. extern NCURSES_EXPORT(void) _nc_panic_mode (char);
  247. extern NCURSES_EXPORT(void) _nc_push_token (int);
  248. extern NCURSES_EXPORT_VAR(int) _nc_curr_col;
  249. extern NCURSES_EXPORT_VAR(int) _nc_curr_line;
  250. extern NCURSES_EXPORT_VAR(int) _nc_syntax;
  251. extern NCURSES_EXPORT_VAR(int) _nc_strict_bsd;
  252. extern NCURSES_EXPORT_VAR(long) _nc_comment_end;
  253. extern NCURSES_EXPORT_VAR(long) _nc_comment_start;
  254. extern NCURSES_EXPORT_VAR(long) _nc_curr_file_pos;
  255. extern NCURSES_EXPORT_VAR(long) _nc_start_line;
  256. #define SYN_TERMINFO 0
  257. #define SYN_TERMCAP 1
  258. /* comp_error.c: warning & abort messages */
  259. extern NCURSES_EXPORT(const char *) _nc_get_source (void);
  260. extern GCC_NORETURN NCURSES_EXPORT(void) _nc_err_abort (const char *const,...) GCC_PRINTFLIKE(1,2);
  261. extern NCURSES_EXPORT(void) _nc_get_type (char *name);
  262. extern NCURSES_EXPORT(void) _nc_set_source (const char *const);
  263. extern NCURSES_EXPORT(void) _nc_set_type (const char *const);
  264. extern GCC_NORETURN NCURSES_EXPORT(void) _nc_syserr_abort (const char *const,...) GCC_PRINTFLIKE(1,2);
  265. extern NCURSES_EXPORT(void) _nc_warning (const char *const,...) GCC_PRINTFLIKE(1,2);
  266. extern NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings;
  267. /* comp_scan.c */
  268. extern NCURSES_EXPORT_VAR(struct token) _nc_curr_token;
  269. /* comp_userdefs.c */
  270. NCURSES_EXPORT(const struct user_table_entry *) _nc_get_userdefs_table (void);
  271. NCURSES_EXPORT(const HashData *) _nc_get_hash_user (void);
  272. /* captoinfo.c: capability conversion */
  273. extern NCURSES_EXPORT(char *) _nc_captoinfo (const char *, const char *, int const);
  274. extern NCURSES_EXPORT(char *) _nc_infotocap (const char *, const char *, int const);
  275. /* home_terminfo.c */
  276. extern NCURSES_EXPORT(char *) _nc_home_terminfo (void);
  277. /* init_keytry.c */
  278. #if BROKEN_LINKER
  279. #define _nc_tinfo_fkeys _nc_tinfo_fkeysf()
  280. extern NCURSES_EXPORT(const struct tinfo_fkeys *) _nc_tinfo_fkeysf (void);
  281. #else
  282. extern NCURSES_EXPORT_VAR(const struct tinfo_fkeys) _nc_tinfo_fkeys[];
  283. #endif
  284. /* lib_tparm.c */
  285. #define NUM_PARM 9
  286. extern NCURSES_EXPORT_VAR(int) _nc_tparm_err;
  287. extern NCURSES_EXPORT(int) _nc_tparm_analyze(TERMINAL *, const char *, char **, int *);
  288. extern NCURSES_EXPORT(void) _nc_reset_tparm(TERMINAL *);
  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 */