Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-05-18 08:30:23

0001 /****************************************************************************
0002  * Copyright 2018-2021,2022 Thomas E. Dickey                                *
0003  * Copyright 1998-2012,2017 Free Software Foundation, Inc.                  *
0004  *                                                                          *
0005  * Permission is hereby granted, free of charge, to any person obtaining a  *
0006  * copy of this software and associated documentation files (the            *
0007  * "Software"), to deal in the Software without restriction, including      *
0008  * without limitation the rights to use, copy, modify, merge, publish,      *
0009  * distribute, distribute with modifications, sublicense, and/or sell       *
0010  * copies of the Software, and to permit persons to whom the Software is    *
0011  * furnished to do so, subject to the following conditions:                 *
0012  *                                                                          *
0013  * The above copyright notice and this permission notice shall be included  *
0014  * in all copies or substantial portions of the Software.                   *
0015  *                                                                          *
0016  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
0017  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
0018  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
0019  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
0020  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
0021  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
0022  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
0023  *                                                                          *
0024  * Except as contained in this notice, the name(s) of the above copyright   *
0025  * holders shall not be used in advertising or otherwise to promote the     *
0026  * sale, use or other dealings in this Software without prior written       *
0027  * authorization.                                                           *
0028  ****************************************************************************/
0029 
0030 /****************************************************************************
0031  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
0032  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
0033  *     and: Thomas E. Dickey 1996 on                                        *
0034  ****************************************************************************/
0035 
0036 /*
0037  * $Id: tic.h,v 1.86 2022/09/17 16:01:45 tom Exp $
0038  *  tic.h - Global variables and structures for the terminfo compiler.
0039  */
0040 
0041 #ifndef __TIC_H
0042 #define __TIC_H
0043 /* *INDENT-OFF* */
0044 #ifdef __cplusplus
0045 extern "C" {
0046 #endif
0047 
0048 #include <ncurses_cfg.h>
0049 
0050 #include <ncursesw/curses.h>    /* for the _tracef() prototype, ERR/OK, bool defs */
0051 
0052 /*
0053 ** The format of SVr2 compiled terminfo files is as follows:
0054 **
0055 **      Header (12 bytes), containing information given below
0056 **      Names Section, containing the names of the terminal
0057 **      Boolean Section, containing the values of all of the
0058 **              boolean capabilities
0059 **              A null byte may be inserted here to make
0060 **              sure that the Number Section begins on an
0061 **              even word boundary.
0062 **      Number Section, containing the values of all of the numeric
0063 **              capabilities, each as a short integer
0064 **      String Section, containing short integer offsets into the
0065 **              String Table, one per string capability
0066 **      String Table, containing the actual characters of the string
0067 **              capabilities.
0068 **
0069 ** In the SVr2 format, "short" means signed 16-bit numbers, which is sometimes
0070 ** inconvenient.  The numbers are signed, to provide for absent and canceled
0071 ** values.  ncurses6.1 introduced an extension to this compiled format, by
0072 ** making the Number Section a list of signed 32-bit integers.
0073 **
0074 **  NOTE that all short integers in the file are stored using VAX/PDP-style
0075 **  byte-order, i.e., least-significant byte first.
0076 **
0077 **  There is no structure definition here because it would only confuse
0078 **  matters.  Terminfo format is a raw byte layout, not a structure
0079 **  dump.  If you happen to be on a little-endian machine with 16-bit
0080 **  shorts that requires no padding between short members in a struct,
0081 **  then there is a natural C structure that captures the header, but
0082 **  not very helpfully.
0083 */
0084 
0085 #define MAGIC       0432    /* first two bytes of a compiled entry */
0086 #define MAGIC2      01036   /* first two bytes of a compiled 32-bit entry */
0087 
0088 #undef  BYTE
0089 #define BYTE(p,n)   (unsigned char)((p)[n])
0090 
0091 #define IS_NEG1(p)  ((BYTE(p,0) == 0377) && (BYTE(p,1) == 0377))
0092 #define IS_NEG2(p)  ((BYTE(p,0) == 0376) && (BYTE(p,1) == 0377))
0093 #define LOW_MSB(p)  (BYTE(p,0) + 256*BYTE(p,1))
0094 
0095 #define IS_TIC_MAGIC(p) (LOW_MSB(p) == MAGIC || LOW_MSB(p) == MAGIC2)
0096 
0097 #define quick_prefix(s) (!strncmp((s), "b64:", (size_t)4) || !strncmp((s), "hex:", (size_t)4))
0098 
0099 /*
0100  * The "maximum" here is misleading; XSI guarantees minimum values, which a
0101  * given implementation may exceed.
0102  */
0103 #define MAX_NAME_SIZE   512 /* maximum legal name field size (XSI:127) */
0104 #define MAX_ENTRY_SIZE1 4096    /* maximum legal entry size (SVr2) */
0105 #define MAX_ENTRY_SIZE2 32768   /* maximum legal entry size (ncurses6.1) */
0106 
0107 #if NCURSES_EXT_COLORS && HAVE_INIT_EXTENDED_COLOR
0108 #define MAX_ENTRY_SIZE MAX_ENTRY_SIZE2
0109 #else
0110 #define MAX_ENTRY_SIZE MAX_ENTRY_SIZE1
0111 #endif
0112 
0113 /*
0114  * The maximum size of individual name or alias is guaranteed in XSI to be at
0115  * least 14, since that corresponds to the older filename lengths.  Newer
0116  * systems allow longer aliases, though not many terminal descriptions are
0117  * written to use them.  The MAX_ALIAS symbol is used for warnings.
0118  */
0119 #if HAVE_LONG_FILE_NAMES
0120 #define MAX_ALIAS   32  /* smaller than POSIX minimum for PATH_MAX */
0121 #else
0122 #define MAX_ALIAS   14  /* SVr3 filename length */
0123 #endif
0124 
0125 /* location of user's personal info directory */
0126 #define PRIVATE_INFO    "%s/.terminfo"  /* plug getenv("HOME") into %s */
0127 
0128 /*
0129  * Some traces are designed to be used via tic's verbose option (and similar in
0130  * infocmp and toe) rather than the 'trace()' function.  So we use the bits
0131  * above the normal trace() parameter as a debug-level.
0132  */
0133 
0134 #define MAX_DEBUG_LEVEL 15
0135 #define DEBUG_LEVEL(n)  ((n) << TRACE_SHIFT)
0136 
0137 #define set_trace_level(n) \
0138     _nc_tracing &= TRACE_MAXIMUM, \
0139     _nc_tracing |= DEBUG_LEVEL(n)
0140 
0141 #ifdef TRACE
0142 #define DEBUG(n, a) if (_nc_tracing >= DEBUG_LEVEL(n)) _tracef a
0143 #else
0144 #define DEBUG(n, a) /*nothing*/
0145 #endif
0146 
0147 /*
0148  * These are the types of tokens returned by the scanner.  The first
0149  * three are also used in the hash table of capability names.  The scanner
0150  * returns one of these values after loading the specifics into the global
0151  * structure curr_token.
0152  */
0153 
0154 #define BOOLEAN 0       /* Boolean capability */
0155 #define NUMBER 1        /* Numeric capability */
0156 #define STRING 2        /* String-valued capability */
0157 #define CANCEL 3        /* Capability to be cancelled in following tc's */
0158 #define NAMES  4        /* The names for a terminal type */
0159 #define UNDEF  5        /* Undefined */
0160 
0161 #define NO_PUSHBACK -1  /* used in pushtype to indicate no pushback */
0162 
0163 /*
0164  * The global structure in which the specific parts of a
0165  * scanned token are returned.
0166  */
0167 
0168 struct token
0169 {
0170     char    *tk_name;   /* name of capability */
0171     int tk_valnumber;   /* value of capability (if a number) */
0172     char    *tk_valstring;  /* value of capability (if a string) */
0173 };
0174 
0175 /*
0176  * Offsets to string capabilities, with the corresponding functionkey codes.
0177  */
0178 struct tinfo_fkeys {
0179     unsigned offset;
0180     chtype code;
0181     };
0182 
0183 typedef short HashValue;
0184 
0185 /*
0186  * The file comp_captab.c contains an array of these structures, one per
0187  * possible capability.  These are indexed by a hash table array of pointers to
0188  * the same structures for use by the parser.
0189  */
0190 struct name_table_entry
0191 {
0192     const char *nte_name;   /* name to hash on */
0193     int nte_type;   /* BOOLEAN, NUMBER or STRING */
0194     HashValue nte_index;    /* index of associated variable in its array */
0195     HashValue nte_link; /* index in table of next hash, or -1 */
0196 };
0197 
0198 /*
0199  * Use this structure to hide differences between terminfo and termcap tables.
0200  */
0201 typedef struct {
0202     unsigned table_size;
0203     const HashValue *table_data;
0204     HashValue (*hash_of)(const char *);
0205     int (*compare_names)(const char *, const char *);
0206 } HashData;
0207 
0208 struct alias
0209 {
0210     const char  *from;
0211     const char  *to;
0212     const char  *source;
0213 };
0214 
0215 #define NOTFOUND    ((struct name_table_entry *) 0)
0216 
0217 /*
0218  * The file comp_userdefs.c contains an array of these structures, one per
0219  * possible capability.  These are indexed by a hash table array of pointers to
0220  * the same structures for use by the parser.
0221  */
0222 struct user_table_entry
0223 {
0224     const char *ute_name;   /* name to hash on */
0225     int ute_type;   /* mask (BOOLEAN, NUMBER, STRING) */
0226     unsigned ute_argc;  /* number of parameters */
0227     unsigned ute_args;  /* bit-mask for string parameters */
0228     HashValue ute_index;    /* index of associated variable in its array */
0229     HashValue ute_link; /* index in table of next hash, or -1 */
0230 };
0231 
0232 /*
0233  * The casts are required for correct sign-propagation with systems such as
0234  * AIX, IRIX64, Solaris which default to unsigned characters.  The C standard
0235  * leaves this detail unspecified.
0236  */
0237 
0238 /* out-of-band values for representing absent capabilities */
0239 #define ABSENT_BOOLEAN      ((signed char)-1)   /* 255 */
0240 #define ABSENT_NUMERIC      (-1)
0241 #define ABSENT_STRING       (char *)0
0242 
0243 /* out-of-band values for representing cancels */
0244 #define CANCELLED_BOOLEAN   ((signed char)-2)   /* 254 */
0245 #define CANCELLED_NUMERIC   (-2)
0246 #define CANCELLED_STRING    (char *)(-1)
0247 
0248 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */
0249 #define VALID_NUMERIC(s) ((s) >= 0)
0250 #define VALID_STRING(s)  ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
0251 
0252 /* termcap entries longer than this may break old binaries */
0253 #define MAX_TERMCAP_LENGTH  1023
0254 
0255 /* this is a documented limitation of terminfo */
0256 #define MAX_TERMINFO_LENGTH 4096
0257 
0258 #ifndef TERMINFO
0259 #define TERMINFO "/usr/share/terminfo"
0260 #endif
0261 
0262 #ifdef NCURSES_TERM_ENTRY_H_incl
0263 
0264 /*
0265  * These entrypoints are used only by the ncurses utilities such as tic.
0266  */
0267 #ifdef NCURSES_INTERNALS
0268 /* access.c */
0269 extern NCURSES_EXPORT(unsigned) _nc_pathlast (const char *);
0270 extern NCURSES_EXPORT(bool) _nc_is_abs_path (const char *);
0271 extern NCURSES_EXPORT(bool) _nc_is_dir_path (const char *);
0272 extern NCURSES_EXPORT(bool) _nc_is_file_path (const char *);
0273 extern NCURSES_EXPORT(char *) _nc_basename (char *);
0274 extern NCURSES_EXPORT(char *) _nc_rootname (char *);
0275 
0276 /* comp_captab.c */
0277 extern NCURSES_EXPORT(const struct name_table_entry *) _nc_get_table (bool);
0278 extern NCURSES_EXPORT(const HashData *) _nc_get_hash_info (bool);
0279 extern NCURSES_EXPORT(const struct alias *) _nc_get_alias_table (bool);
0280 
0281 /* comp_hash.c: name lookup */
0282 extern NCURSES_EXPORT(struct name_table_entry const *) _nc_find_type_entry
0283     (const char *, int, bool);
0284 extern NCURSES_EXPORT(struct user_table_entry const *) _nc_find_user_entry
0285     (const char *);
0286 
0287 /* comp_scan.c: lexical analysis */
0288 extern NCURSES_EXPORT(int)  _nc_get_token (bool);
0289 extern NCURSES_EXPORT(void) _nc_panic_mode (char);
0290 extern NCURSES_EXPORT(void) _nc_push_token (int);
0291 extern NCURSES_EXPORT_VAR(int) _nc_curr_col;
0292 extern NCURSES_EXPORT_VAR(int) _nc_curr_line;
0293 extern NCURSES_EXPORT_VAR(int) _nc_syntax;
0294 extern NCURSES_EXPORT_VAR(int) _nc_strict_bsd;
0295 extern NCURSES_EXPORT_VAR(long) _nc_comment_end;
0296 extern NCURSES_EXPORT_VAR(long) _nc_comment_start;
0297 extern NCURSES_EXPORT_VAR(long) _nc_curr_file_pos;
0298 extern NCURSES_EXPORT_VAR(long) _nc_start_line;
0299 #define SYN_TERMINFO    0
0300 #define SYN_TERMCAP 1
0301 
0302 /* comp_error.c: warning & abort messages */
0303 extern NCURSES_EXPORT(const char *) _nc_get_source (void);
0304 extern GCC_NORETURN NCURSES_EXPORT(void) _nc_err_abort (const char *const,...) GCC_PRINTFLIKE(1,2);
0305 extern NCURSES_EXPORT(void) _nc_get_type (char *name);
0306 extern NCURSES_EXPORT(void) _nc_set_source (const char *const);
0307 extern NCURSES_EXPORT(void) _nc_set_type (const char *const);
0308 extern GCC_NORETURN NCURSES_EXPORT(void) _nc_syserr_abort (const char *const,...) GCC_PRINTFLIKE(1,2);
0309 extern NCURSES_EXPORT(void) _nc_warning (const char *const,...) GCC_PRINTFLIKE(1,2);
0310 extern NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings;
0311 
0312 /* comp_scan.c */
0313 extern NCURSES_EXPORT_VAR(struct token) _nc_curr_token;
0314 
0315 /* comp_userdefs.c */
0316 NCURSES_EXPORT(const struct user_table_entry *) _nc_get_userdefs_table (void);
0317 NCURSES_EXPORT(const HashData *) _nc_get_hash_user (void);
0318 
0319 /* captoinfo.c: capability conversion */
0320 extern NCURSES_EXPORT(char *) _nc_captoinfo (const char *, const char *, int const);
0321 extern NCURSES_EXPORT(char *) _nc_infotocap (const char *, const char *, int const);
0322 
0323 /* home_terminfo.c */
0324 extern NCURSES_EXPORT(char *) _nc_home_terminfo (void);
0325 
0326 /* init_keytry.c */
0327 #if BROKEN_LINKER
0328 #define _nc_tinfo_fkeys _nc_tinfo_fkeysf()
0329 extern NCURSES_EXPORT(const struct tinfo_fkeys *) _nc_tinfo_fkeysf (void);
0330 #else
0331 extern NCURSES_EXPORT_VAR(const struct tinfo_fkeys) _nc_tinfo_fkeys[];
0332 #endif
0333 
0334 /* lib_tparm.c */
0335 #define NUM_PARM 9
0336 
0337 extern NCURSES_EXPORT_VAR(int) _nc_tparm_err;
0338 
0339 extern NCURSES_EXPORT(int) _nc_tparm_analyze(TERMINAL *, const char *, char **, int *);
0340 extern NCURSES_EXPORT(void) _nc_reset_tparm(TERMINAL *);
0341 
0342 /* lib_trace.c */
0343 extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing;
0344 extern NCURSES_EXPORT(const char *) _nc_visbuf (const char *);
0345 extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *);
0346 
0347 /* lib_tputs.c */
0348 extern NCURSES_EXPORT_VAR(int) _nc_nulls_sent;  /* Add one for every null sent */
0349 
0350 /* comp_main.c: compiler main */
0351 extern const char * _nc_progname;
0352 
0353 /* db_iterator.c */
0354 extern NCURSES_EXPORT(const char *) _nc_next_db(DBDIRS *, int *);
0355 extern NCURSES_EXPORT(const char *) _nc_tic_dir (const char *);
0356 extern NCURSES_EXPORT(void) _nc_first_db(DBDIRS *, int *);
0357 extern NCURSES_EXPORT(void) _nc_last_db(void);
0358 
0359 /* write_entry.c */
0360 extern NCURSES_EXPORT(int) _nc_tic_written (void);
0361 
0362 #endif /* NCURSES_INTERNALS */
0363 
0364 /*
0365  * These entrypoints were used by tack before 1.08.
0366  */
0367 
0368 #undef  NCURSES_TACK_1_08
0369 #ifdef  NCURSES_INTERNALS
0370 #define NCURSES_TACK_1_08 /* nothing */
0371 #else
0372 #define NCURSES_TACK_1_08 GCC_DEPRECATED("upgrade to tack 1.08")
0373 #endif
0374 
0375 /* comp_hash.c: name lookup */
0376 extern NCURSES_EXPORT(struct name_table_entry const *) _nc_find_entry
0377     (const char *, const HashValue *) NCURSES_TACK_1_08;
0378 extern NCURSES_EXPORT(const HashValue *) _nc_get_hash_table (bool) NCURSES_TACK_1_08;
0379 
0380 /* comp_scan.c: lexical analysis */
0381 extern NCURSES_EXPORT(void) _nc_reset_input (FILE *, char *) NCURSES_TACK_1_08;
0382 
0383 /* comp_expand.c: expand string into readable form */
0384 extern NCURSES_EXPORT(char *) _nc_tic_expand (const char *, bool, int) NCURSES_TACK_1_08;
0385 
0386 /* comp_scan.c: decode string from readable form */
0387 extern NCURSES_EXPORT(int) _nc_trans_string (char *, char *) NCURSES_TACK_1_08;
0388 
0389 #endif /* NCURSES_TERM_ENTRY_H_incl */
0390 
0391 #ifdef __cplusplus
0392 }
0393 #endif
0394 
0395 /* *INDENT-ON* */
0396 #endif /* __TIC_H */