150276Speter/**************************************************************************** 2174993Srafan * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * 350276Speter * * 450276Speter * Permission is hereby granted, free of charge, to any person obtaining a * 550276Speter * copy of this software and associated documentation files (the * 650276Speter * "Software"), to deal in the Software without restriction, including * 750276Speter * without limitation the rights to use, copy, modify, merge, publish, * 850276Speter * distribute, distribute with modifications, sublicense, and/or sell * 950276Speter * copies of the Software, and to permit persons to whom the Software is * 1050276Speter * furnished to do so, subject to the following conditions: * 1150276Speter * * 1250276Speter * The above copyright notice and this permission notice shall be included * 1350276Speter * in all copies or substantial portions of the Software. * 1450276Speter * * 1550276Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 1650276Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 1750276Speter * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 1850276Speter * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 1950276Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 2050276Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 2150276Speter * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 2250276Speter * * 2350276Speter * Except as contained in this notice, the name(s) of the above copyright * 2450276Speter * holders shall not be used in advertising or otherwise to promote the * 2550276Speter * sale, use or other dealings in this Software without prior written * 2650276Speter * authorization. * 2750276Speter ****************************************************************************/ 2850276Speter 2950276Speter/**************************************************************************** 3050276Speter * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * 3150276Speter * and: Eric S. Raymond <esr@snark.thyrsus.com> * 32166124Srafan * and: Thomas E. Dickey 1996 on * 3350276Speter ****************************************************************************/ 3450276Speter 3550276Speter/* 36174993Srafan * $Id: tic.h,v 1.62 2007/08/11 16:12:43 tom Exp $ 3750276Speter * tic.h - Global variables and structures for the terminfo 3850276Speter * compiler. 3950276Speter */ 4050276Speter 4150276Speter#ifndef __TIC_H 4250276Speter#define __TIC_H 4350276Speter 4450276Speter#ifdef __cplusplus 4550276Speterextern "C" { 4650276Speter#endif 4750276Speter 4850276Speter#include <curses.h> /* for the _tracef() prototype, ERR/OK, bool defs */ 4950276Speter 5050276Speter/* 5150276Speter** The format of compiled terminfo files is as follows: 5250276Speter** 5350276Speter** Header (12 bytes), containing information given below 5450276Speter** Names Section, containing the names of the terminal 5550276Speter** Boolean Section, containing the values of all of the 5650276Speter** boolean capabilities 5750276Speter** A null byte may be inserted here to make 5850276Speter** sure that the Number Section begins on an 5950276Speter** even word boundary. 6050276Speter** Number Section, containing the values of all of the numeric 6150276Speter** capabilities, each as a short integer 6250276Speter** String Section, containing short integer offsets into the 6350276Speter** String Table, one per string capability 6450276Speter** String Table, containing the actual characters of the string 6550276Speter** capabilities. 6650276Speter** 6750276Speter** NOTE that all short integers in the file are stored using VAX/PDP-style 6850276Speter** byte-order, i.e., least-significant byte first. 6950276Speter** 7050276Speter** There is no structure definition here because it would only confuse 7150276Speter** matters. Terminfo format is a raw byte layout, not a structure 7250276Speter** dump. If you happen to be on a little-endian machine with 16-bit 7350276Speter** shorts that requires no padding between short members in a struct, 7450276Speter** then there is a natural C structure that captures the header, but 7550276Speter** not very helpfully. 7650276Speter*/ 7750276Speter 7850276Speter#define MAGIC 0432 /* first two bytes of a compiled entry */ 7950276Speter 80166124Srafan#undef BYTE 81166124Srafan#define BYTE(p,n) (unsigned char)((p)[n]) 82166124Srafan 83166124Srafan#define IS_NEG1(p) ((BYTE(p,0) == 0377) && (BYTE(p,1) == 0377)) 84166124Srafan#define IS_NEG2(p) ((BYTE(p,0) == 0376) && (BYTE(p,1) == 0377)) 85166124Srafan#define LOW_MSB(p) (BYTE(p,0) + 256*BYTE(p,1)) 86166124Srafan 87166124Srafan#define IS_TIC_MAGIC(p) (LOW_MSB(p) == MAGIC) 88166124Srafan 8950276Speter/* 9050276Speter * The "maximum" here is misleading; XSI guarantees minimum values, which a 9150276Speter * given implementation may exceed. 9250276Speter */ 9350276Speter#define MAX_NAME_SIZE 512 /* maximum legal name field size (XSI:127) */ 9450276Speter#define MAX_ENTRY_SIZE 4096 /* maximum legal entry size */ 9550276Speter 96166124Srafan/* 97166124Srafan * The maximum size of individual name or alias is guaranteed in XSI to be at 98166124Srafan * least 14, since that corresponds to the older filename lengths. Newer 99166124Srafan * systems allow longer aliases, though not many terminal descriptions are 100166124Srafan * written to use them. The MAX_ALIAS symbol is used for warnings. 10150276Speter */ 10250276Speter#if HAVE_LONG_FILE_NAMES 103166124Srafan#define MAX_ALIAS 32 /* smaller than POSIX minimum for PATH_MAX */ 10450276Speter#else 10550276Speter#define MAX_ALIAS 14 /* SVr3 filename length */ 10650276Speter#endif 10750276Speter 10850276Speter/* location of user's personal info directory */ 10950276Speter#define PRIVATE_INFO "%s/.terminfo" /* plug getenv("HOME") into %s */ 11050276Speter 11162449Speter/* 11262449Speter * Some traces are designed to be used via tic's verbose option (and similar in 11362449Speter * infocmp and toe) rather than the 'trace()' function. So we use the bits 11462449Speter * above the normal trace() parameter as a debug-level. 11562449Speter */ 11662449Speter 11762449Speter#define MAX_DEBUG_LEVEL 15 118166124Srafan#define DEBUG_LEVEL(n) ((n) << TRACE_SHIFT) 11962449Speter 12062449Speter#define set_trace_level(n) \ 121166124Srafan _nc_tracing &= DEBUG_LEVEL(MAX_DEBUG_LEVEL), \ 12262449Speter _nc_tracing |= DEBUG_LEVEL(n) 12362449Speter 12450276Speter#ifdef TRACE 12562449Speter#define DEBUG(n, a) if (_nc_tracing >= DEBUG_LEVEL(n)) _tracef a 12650276Speter#else 12750276Speter#define DEBUG(n, a) /*nothing*/ 12850276Speter#endif 12950276Speter 13076726Speterextern NCURSES_EXPORT_VAR(unsigned) _nc_tracing; 13176726Speterextern NCURSES_EXPORT(void) _nc_tracef (char *, ...) GCC_PRINTFLIKE(1,2); 13276726Speterextern NCURSES_EXPORT(const char *) _nc_visbuf (const char *); 13398503Speterextern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *); 13450276Speter 13550276Speter/* 13650276Speter * These are the types of tokens returned by the scanner. The first 13750276Speter * three are also used in the hash table of capability names. The scanner 13850276Speter * returns one of these values after loading the specifics into the global 13950276Speter * structure curr_token. 14050276Speter */ 14150276Speter 14250276Speter#define BOOLEAN 0 /* Boolean capability */ 14350276Speter#define NUMBER 1 /* Numeric capability */ 14450276Speter#define STRING 2 /* String-valued capability */ 14550276Speter#define CANCEL 3 /* Capability to be cancelled in following tc's */ 14650276Speter#define NAMES 4 /* The names for a terminal type */ 14750276Speter#define UNDEF 5 /* Undefined */ 14850276Speter 14950276Speter#define NO_PUSHBACK -1 /* used in pushtype to indicate no pushback */ 15050276Speter 15150276Speter /* 15250276Speter * The global structure in which the specific parts of a 15350276Speter * scanned token are returned. 15450276Speter * 15550276Speter */ 15650276Speter 15750276Speterstruct token 15850276Speter{ 15950276Speter char *tk_name; /* name of capability */ 16050276Speter int tk_valnumber; /* value of capability (if a number) */ 16150276Speter char *tk_valstring; /* value of capability (if a string) */ 16250276Speter}; 16350276Speter 16476726Speterextern NCURSES_EXPORT_VAR(struct token) _nc_curr_token; 16550276Speter 16650276Speter /* 16750276Speter * Offsets to string capabilities, with the corresponding functionkey 16850276Speter * codes. 16950276Speter */ 17050276Speterstruct tinfo_fkeys { 17150276Speter unsigned offset; 17250276Speter chtype code; 17350276Speter }; 17450276Speter 17562449Speter#if BROKEN_LINKER 17656639Speter 17756639Speter#define _nc_tinfo_fkeys _nc_tinfo_fkeysf() 178174993Srafanextern NCURSES_EXPORT(const struct tinfo_fkeys *) _nc_tinfo_fkeysf (void); 17956639Speter 18056639Speter#else 18156639Speter 182174993Srafanextern NCURSES_EXPORT_VAR(const struct tinfo_fkeys) _nc_tinfo_fkeys[]; 18350276Speter 18456639Speter#endif 18556639Speter 18650276Speter /* 18750276Speter * The file comp_captab.c contains an array of these structures, one 18850276Speter * per possible capability. These are indexed by a hash table array of 18950276Speter * pointers to the same structures for use by the parser. 19050276Speter */ 19150276Speter 19250276Speterstruct name_table_entry 19350276Speter{ 19450276Speter const char *nte_name; /* name to hash on */ 19550276Speter int nte_type; /* BOOLEAN, NUMBER or STRING */ 19650276Speter short nte_index; /* index of associated variable in its array */ 19750276Speter short nte_link; /* index in table of next hash, or -1 */ 19850276Speter}; 19950276Speter 20050276Speterstruct alias 20150276Speter{ 20250276Speter const char *from; 20350276Speter const char *to; 20450276Speter const char *source; 20550276Speter}; 20650276Speter 20776726Speterextern NCURSES_EXPORT(const struct name_table_entry *) _nc_get_table (bool); 208174993Srafanextern NCURSES_EXPORT(const short *) _nc_get_hash_table (bool); 209174993Srafanextern NCURSES_EXPORT(const struct alias *) _nc_get_alias_table (bool); 21076726Speter 21150276Speter#define NOTFOUND ((struct name_table_entry *) 0) 21250276Speter 21350276Speter/* out-of-band values for representing absent capabilities */ 214166124Srafan#define ABSENT_BOOLEAN ((signed char)-1) /* 255 */ 21597049Speter#define ABSENT_NUMERIC (-1) 21650276Speter#define ABSENT_STRING (char *)0 21750276Speter 21850276Speter/* out-of-band values for representing cancels */ 219166124Srafan#define CANCELLED_BOOLEAN ((signed char)-2) /* 254 */ 22097049Speter#define CANCELLED_NUMERIC (-2) 22197049Speter#define CANCELLED_STRING (char *)(-1) 22250276Speter 22397049Speter#define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1) /* reject "-1" */ 22450276Speter#define VALID_NUMERIC(s) ((s) >= 0) 225166124Srafan#define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING) 22650276Speter 22750276Speter/* termcap entries longer than this may break old binaries */ 22850276Speter#define MAX_TERMCAP_LENGTH 1023 22950276Speter 23050276Speter/* this is a documented limitation of terminfo */ 23150276Speter#define MAX_TERMINFO_LENGTH 4096 23250276Speter 23350276Speter#ifndef TERMINFO 23450276Speter#define TERMINFO "/usr/share/terminfo" 23550276Speter#endif 23650276Speter 23766963Speter/* access.c */ 238166124Srafanextern NCURSES_EXPORT(unsigned) _nc_pathlast (const char *); 239166124Srafanextern NCURSES_EXPORT(bool) _nc_is_abs_path (const char *); 240166124Srafanextern NCURSES_EXPORT(bool) _nc_is_dir_path (const char *); 241166124Srafanextern NCURSES_EXPORT(bool) _nc_is_file_path (const char *); 24276726Speterextern NCURSES_EXPORT(char *) _nc_basename (char *); 24397049Speterextern NCURSES_EXPORT(char *) _nc_rootname (char *); 24466963Speter 24550276Speter/* comp_hash.c: name lookup */ 24676726Speterextern NCURSES_EXPORT(struct name_table_entry const *) _nc_find_entry 247174993Srafan (const char *, const short *); 24876726Speterextern NCURSES_EXPORT(struct name_table_entry const *) _nc_find_type_entry 24976726Speter (const char *, int, const struct name_table_entry *); 25050276Speter 25150276Speter/* comp_scan.c: lexical analysis */ 25276726Speterextern NCURSES_EXPORT(int) _nc_get_token (bool); 25376726Speterextern NCURSES_EXPORT(void) _nc_panic_mode (char); 25476726Speterextern NCURSES_EXPORT(void) _nc_push_token (int); 25576726Speterextern NCURSES_EXPORT(void) _nc_reset_input (FILE *, char *); 25676726Speterextern NCURSES_EXPORT_VAR(int) _nc_curr_col; 25776726Speterextern NCURSES_EXPORT_VAR(int) _nc_curr_line; 25876726Speterextern NCURSES_EXPORT_VAR(int) _nc_syntax; 25976726Speterextern NCURSES_EXPORT_VAR(long) _nc_comment_end; 26076726Speterextern NCURSES_EXPORT_VAR(long) _nc_comment_start; 26176726Speterextern NCURSES_EXPORT_VAR(long) _nc_curr_file_pos; 26276726Speterextern NCURSES_EXPORT_VAR(long) _nc_start_line; 26350276Speter#define SYN_TERMINFO 0 26450276Speter#define SYN_TERMCAP 1 26550276Speter 26650276Speter/* comp_error.c: warning & abort messages */ 267166124Srafanextern NCURSES_EXPORT(const char *) _nc_get_source (void); 268166124Srafanextern NCURSES_EXPORT(void) _nc_err_abort (const char *const,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN; 26976726Speterextern NCURSES_EXPORT(void) _nc_get_type (char *name); 270166124Srafanextern NCURSES_EXPORT(void) _nc_set_source (const char *const); 271166124Srafanextern NCURSES_EXPORT(void) _nc_set_type (const char *const); 27276726Speterextern NCURSES_EXPORT(void) _nc_syserr_abort (const char *const,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN; 27376726Speterextern NCURSES_EXPORT(void) _nc_warning (const char *const,...) GCC_PRINTFLIKE(1,2); 27476726Speterextern NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings; 27550276Speter 27650276Speter/* comp_expand.c: expand string into readable form */ 27776726Speterextern NCURSES_EXPORT(char *) _nc_tic_expand (const char *, bool, int); 27850276Speter 27950276Speter/* comp_scan.c: decode string from readable form */ 280166124Srafanextern NCURSES_EXPORT(int) _nc_trans_string (char *, char *); 28150276Speter 28250276Speter/* captoinfo.c: capability conversion */ 28376726Speterextern NCURSES_EXPORT(char *) _nc_captoinfo (const char *, const char *, int const); 28476726Speterextern NCURSES_EXPORT(char *) _nc_infotocap (const char *, const char *, int const); 28550276Speter 286166124Srafan/* home_terminfo.c */ 287166124Srafanextern NCURSES_EXPORT(char *) _nc_home_terminfo (void); 288166124Srafan 289166124Srafan/* lib_tparm.c */ 290166124Srafan#define NUM_PARM 9 291166124Srafan 292166124Srafanextern NCURSES_EXPORT_VAR(int) _nc_tparm_err; 293166124Srafan 294166124Srafanextern NCURSES_EXPORT(int) _nc_tparm_analyze(const char *, char **, int *); 295166124Srafan 29650276Speter/* lib_tputs.c */ 29776726Speterextern NCURSES_EXPORT_VAR(int) _nc_nulls_sent; /* Add one for every null sent */ 29850276Speter 29950276Speter/* comp_main.c: compiler main */ 30076726Speterextern const char * _nc_progname; 30150276Speter 302166124Srafan/* db_iterator.c */ 303166124Srafantypedef enum { 304166124Srafan dbdTIC = 0, 305166124Srafan#if USE_DATABASE 306166124Srafan dbdEnvOnce, 307166124Srafan dbdHome, 308166124Srafan dbdEnvList, 309166124Srafan dbdCfgList, 310166124Srafan dbdCfgOnce, 311166124Srafan#endif 312166124Srafan#if USE_TERMCAP 313166124Srafan dbdEnvOnce2, 314166124Srafan dbdEnvList2, 315166124Srafan dbdCfgList2, 316166124Srafan#endif 317166124Srafan dbdLAST 318166124Srafan} DBDIRS; 319166124Srafan 320166124Srafanextern NCURSES_EXPORT(const char *) _nc_next_db(DBDIRS *, int *); 32176726Speterextern NCURSES_EXPORT(const char *) _nc_tic_dir (const char *); 322166124Srafanextern NCURSES_EXPORT(void) _nc_first_db(DBDIRS *, int *); 323166124Srafanextern NCURSES_EXPORT(void) _nc_last_db(void); 32450276Speter 32550276Speter/* write_entry.c */ 32676726Speterextern NCURSES_EXPORT(int) _nc_tic_written (void); 32750276Speter 32850276Speter#ifdef __cplusplus 32950276Speter} 33050276Speter#endif 33150276Speter 33250276Speter#endif /* __TIC_H */ 333