tic.h revision 76726
150276Speter/****************************************************************************
262449Speter * Copyright (c) 1998-2000 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>                         *
3250276Speter ****************************************************************************/
3350276Speter
3450276Speter/*
3576726Speter * $Id: tic.h,v 1.38 2001/03/11 15:12:08 tom Exp $
3650276Speter *	tic.h - Global variables and structures for the terminfo
3750276Speter *			compiler.
3850276Speter */
3950276Speter
4050276Speter#ifndef __TIC_H
4150276Speter#define __TIC_H
4250276Speter
4350276Speter#ifdef __cplusplus
4450276Speterextern "C" {
4550276Speter#endif
4650276Speter
4750276Speter#include <curses.h>	/* for the _tracef() prototype, ERR/OK, bool defs */
4850276Speter
4950276Speter/*
5050276Speter** The format of compiled terminfo files is as follows:
5150276Speter**
5250276Speter**		Header (12 bytes), containing information given below
5350276Speter**		Names Section, containing the names of the terminal
5450276Speter**		Boolean Section, containing the values of all of the
5550276Speter**				boolean capabilities
5650276Speter**				A null byte may be inserted here to make
5750276Speter**				sure that the Number Section begins on an
5850276Speter**				even word boundary.
5950276Speter**		Number Section, containing the values of all of the numeric
6050276Speter**				capabilities, each as a short integer
6150276Speter**		String Section, containing short integer offsets into the
6250276Speter**				String Table, one per string capability
6350276Speter**		String Table, containing the actual characters of the string
6450276Speter**				capabilities.
6550276Speter**
6650276Speter**	NOTE that all short integers in the file are stored using VAX/PDP-style
6750276Speter**	byte-order, i.e., least-significant byte first.
6850276Speter**
6950276Speter**	There is no structure definition here because it would only confuse
7050276Speter**	matters.  Terminfo format is a raw byte layout, not a structure
7150276Speter**	dump.  If you happen to be on a little-endian machine with 16-bit
7250276Speter**	shorts that requires no padding between short members in a struct,
7350276Speter**	then there is a natural C structure that captures the header, but
7450276Speter**	not very helpfully.
7550276Speter*/
7650276Speter
7750276Speter#define MAGIC		0432	/* first two bytes of a compiled entry */
7850276Speter
7950276Speter/*
8050276Speter * The "maximum" here is misleading; XSI guarantees minimum values, which a
8150276Speter * given implementation may exceed.
8250276Speter */
8350276Speter#define MAX_NAME_SIZE	512	/* maximum legal name field size (XSI:127) */
8450276Speter#define MAX_ENTRY_SIZE	4096	/* maximum legal entry size */
8550276Speter
8650276Speter/* The maximum size of individual name or alias is guaranteed in XSI to
8750276Speter * be 14, since that corresponds to the older filename lengths.  Newer
8850276Speter * systems allow longer aliases, though not many terminal descriptions
8950276Speter * are written to use them.
9050276Speter */
9150276Speter#if HAVE_LONG_FILE_NAMES
9250276Speter#define MAX_ALIAS	32	/* POSIX minimum for PATH_MAX */
9350276Speter#else
9450276Speter#define MAX_ALIAS	14	/* SVr3 filename length */
9550276Speter#endif
9650276Speter
9750276Speter/* location of user's personal info directory */
9850276Speter#define PRIVATE_INFO	"%s/.terminfo"	/* plug getenv("HOME") into %s */
9950276Speter
10062449Speter/*
10162449Speter * Some traces are designed to be used via tic's verbose option (and similar in
10262449Speter * infocmp and toe) rather than the 'trace()' function.  So we use the bits
10362449Speter * above the normal trace() parameter as a debug-level.
10462449Speter */
10562449Speter
10662449Speter#define MAX_DEBUG_LEVEL 15
10762449Speter#define DEBUG_LEVEL(n)	((n) << 12)	/* see TRACE_MAXIMUM */
10862449Speter
10962449Speter#define set_trace_level(n) \
11062449Speter 	_nc_tracing &= DEBUG_LEVEL(MAX_DEBUG_LEVEL), \
11162449Speter	_nc_tracing |= DEBUG_LEVEL(n)
11262449Speter
11350276Speter#ifdef TRACE
11462449Speter#define DEBUG(n, a)	if (_nc_tracing >= DEBUG_LEVEL(n)) _tracef a
11550276Speter#else
11650276Speter#define DEBUG(n, a)	/*nothing*/
11750276Speter#endif
11850276Speter
11976726Speterextern NCURSES_EXPORT_VAR(unsigned) _nc_tracing;
12076726Speterextern NCURSES_EXPORT(void) _nc_tracef (char *, ...) GCC_PRINTFLIKE(1,2);
12176726Speterextern NCURSES_EXPORT(const char *) _nc_visbuf (const char *);
12250276Speter
12350276Speter/*
12450276Speter * These are the types of tokens returned by the scanner.  The first
12550276Speter * three are also used in the hash table of capability names.  The scanner
12650276Speter * returns one of these values after loading the specifics into the global
12750276Speter * structure curr_token.
12850276Speter */
12950276Speter
13050276Speter#define BOOLEAN 0		/* Boolean capability */
13150276Speter#define NUMBER 1		/* Numeric capability */
13250276Speter#define STRING 2		/* String-valued capability */
13350276Speter#define CANCEL 3		/* Capability to be cancelled in following tc's */
13450276Speter#define NAMES  4		/* The names for a terminal type */
13550276Speter#define UNDEF  5		/* Undefined */
13650276Speter
13750276Speter#define NO_PUSHBACK	-1	/* used in pushtype to indicate no pushback */
13850276Speter
13950276Speter	/*
14050276Speter	 *	The global structure in which the specific parts of a
14150276Speter	 *	scanned token are returned.
14250276Speter	 *
14350276Speter	 */
14450276Speter
14550276Speterstruct token
14650276Speter{
14750276Speter	char	*tk_name;		/* name of capability */
14850276Speter	int	tk_valnumber;	/* value of capability (if a number) */
14950276Speter	char	*tk_valstring;	/* value of capability (if a string) */
15050276Speter};
15150276Speter
15276726Speterextern NCURSES_EXPORT_VAR(struct token)	_nc_curr_token;
15350276Speter
15450276Speter	/*
15550276Speter	 * List of keynames with their corresponding code.
15650276Speter	 */
15750276Speterstruct kn {
15850276Speter	const char *name;
15950276Speter	int code;
16050276Speter};
16150276Speter
16276726Speterextern NCURSES_EXPORT_VAR(const struct kn) _nc_key_names[];
16350276Speter
16450276Speter	/*
16550276Speter	 * Offsets to string capabilities, with the corresponding functionkey
16650276Speter	 * codes.
16750276Speter	 */
16850276Speterstruct tinfo_fkeys {
16950276Speter	unsigned offset;
17050276Speter	chtype code;
17150276Speter	};
17250276Speter
17362449Speter#if	BROKEN_LINKER
17456639Speter
17556639Speter#define	_nc_tinfo_fkeys	_nc_tinfo_fkeysf()
17676726Speterextern NCURSES_EXPORT(struct tinfo_fkeys *) _nc_tinfo_fkeysf (void);
17756639Speter
17856639Speter#else
17956639Speter
18076726Speterextern NCURSES_EXPORT_VAR(struct tinfo_fkeys) _nc_tinfo_fkeys[];
18150276Speter
18256639Speter#endif
18356639Speter
18450276Speter	/*
18550276Speter	 * The file comp_captab.c contains an array of these structures, one
18650276Speter	 * per possible capability.  These are indexed by a hash table array of
18750276Speter	 * pointers to the same structures for use by the parser.
18850276Speter	 */
18950276Speter
19050276Speterstruct name_table_entry
19150276Speter{
19250276Speter	const char *nte_name;	/* name to hash on */
19350276Speter	int	nte_type;	/* BOOLEAN, NUMBER or STRING */
19450276Speter	short	nte_index;	/* index of associated variable in its array */
19550276Speter	short	nte_link;	/* index in table of next hash, or -1 */
19650276Speter};
19750276Speter
19850276Speterstruct alias
19950276Speter{
20050276Speter	const char	*from;
20150276Speter	const char	*to;
20250276Speter	const char	*source;
20350276Speter};
20450276Speter
20576726Speterextern NCURSES_EXPORT_VAR(int) _nc_tparm_err;
20650276Speter
20776726Speterextern NCURSES_EXPORT_VAR(const struct name_table_entry * const) _nc_info_hash_table[];
20876726Speterextern NCURSES_EXPORT_VAR(const struct name_table_entry * const) _nc_cap_hash_table[];
20950276Speter
21076726Speterextern NCURSES_EXPORT_VAR(const struct alias) _nc_capalias_table[];
21176726Speterextern NCURSES_EXPORT_VAR(const struct alias) _nc_infoalias_table[];
21250276Speter
21376726Speterextern NCURSES_EXPORT(const struct name_table_entry *) _nc_get_table (bool);
21476726Speterextern NCURSES_EXPORT(const struct name_table_entry * const *) _nc_get_hash_table (bool);
21576726Speter
21650276Speter#define NOTFOUND	((struct name_table_entry *) 0)
21750276Speter
21850276Speter/* out-of-band values for representing absent capabilities */
21950276Speter#define ABSENT_BOOLEAN		-1
22050276Speter#define ABSENT_NUMERIC		-1
22150276Speter#define ABSENT_STRING		(char *)0
22250276Speter
22350276Speter/* out-of-band values for representing cancels */
22450276Speter#define CANCELLED_BOOLEAN	(char)(-2)
22550276Speter#define CANCELLED_NUMERIC	-2
22650276Speter#define CANCELLED_STRING	(char *)-1
22750276Speter
22850276Speter#define VALID_BOOLEAN(s) ((s) >= 0)
22950276Speter#define VALID_NUMERIC(s) ((s) >= 0)
23050276Speter#define VALID_STRING(s) ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
23150276Speter
23250276Speter/* termcap entries longer than this may break old binaries */
23350276Speter#define MAX_TERMCAP_LENGTH	1023
23450276Speter
23550276Speter/* this is a documented limitation of terminfo */
23650276Speter#define MAX_TERMINFO_LENGTH	4096
23750276Speter
23850276Speter#ifndef TERMINFO
23950276Speter#define TERMINFO "/usr/share/terminfo"
24050276Speter#endif
24150276Speter
24266963Speter/* access.c */
24376726Speterextern NCURSES_EXPORT(char *) _nc_basename (char *);
24466963Speter
24550276Speter/* comp_hash.c: name lookup */
24676726Speterextern NCURSES_EXPORT(struct name_table_entry const *) _nc_find_entry
24776726Speter	(const char *, const struct name_table_entry *const *);
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 */
26776726Speterextern NCURSES_EXPORT(void) _nc_set_source (const char *const name);
26876726Speterextern NCURSES_EXPORT(void) _nc_get_type (char *name);
26976726Speterextern NCURSES_EXPORT(void) _nc_set_type (const char *const name);
27076726Speterextern NCURSES_EXPORT(void) _nc_syserr_abort (const char *const,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN;
27176726Speterextern NCURSES_EXPORT(void) _nc_err_abort (const char *const,...) GCC_PRINTFLIKE(1,2) GCC_NORETURN;
27276726Speterextern NCURSES_EXPORT(void) _nc_warning (const char *const,...) GCC_PRINTFLIKE(1,2);
27376726Speterextern NCURSES_EXPORT_VAR(bool) _nc_suppress_warnings;
27450276Speter
27550276Speter/* comp_expand.c: expand string into readable form */
27676726Speterextern NCURSES_EXPORT(char *) _nc_tic_expand (const char *, bool, int);
27750276Speter
27850276Speter/* comp_scan.c: decode string from readable form */
27976726Speterextern NCURSES_EXPORT(char) _nc_trans_string (char *, char *);
28050276Speter
28150276Speter/* captoinfo.c: capability conversion */
28276726Speterextern NCURSES_EXPORT(char *) _nc_captoinfo (const char *, const char *, int const);
28376726Speterextern NCURSES_EXPORT(char *) _nc_infotocap (const char *, const char *, int const);
28450276Speter
28550276Speter/* lib_tputs.c */
28676726Speterextern NCURSES_EXPORT_VAR(int) _nc_nulls_sent;		/* Add one for every null sent */
28750276Speter
28850276Speter/* comp_main.c: compiler main */
28976726Speterextern const char * _nc_progname;
29050276Speter
29150276Speter/* read_entry.c */
29276726Speterextern NCURSES_EXPORT(const char *) _nc_tic_dir (const char *);
29350276Speter
29450276Speter/* write_entry.c */
29576726Speterextern NCURSES_EXPORT(int) _nc_tic_written (void);
29650276Speter
29750276Speter#ifdef __cplusplus
29850276Speter}
29950276Speter#endif
30050276Speter
30150276Speter#endif /* __TIC_H */
302