tic.h 12 KB

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