Home | History | Annotate | Line # | Download | only in libterminfo
term_private.h revision 1.9.4.2
      1 /* $NetBSD: term_private.h,v 1.9.4.2 2013/03/14 15:48:29 riz Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2009, 2010, 2013 The NetBSD Foundation, Inc.
      5  *
      6  * This code is derived from software contributed to The NetBSD Foundation
      7  * by Roy Marples.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  *
     18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     23  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     24  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     25  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     26  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     27  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     28  */
     29 
     30 #ifndef _TERM_PRIVATE_H_
     31 #define	_TERM_PRIVATE_H_
     32 
     33 /* This header should only be used by libterminfo, tic and infocmp. */
     34 
     35 /* The terminfo database structure is private to us,
     36  * so it's documented here.
     37  * terminfo defines the largest number as 32767 and the largest
     38  * compiled entry as 4093 bytes long.
     39  * Thus, we store all numbers as uint16_t, including string length.
     40  * All strings are prefixed by length, including the null terminator.
     41  * The largest string length we can handle is 65535 bytes,
     42  * including the null terminator.
     43  * The largest capability block we can handle is 65535 bytes.
     44  * This means that we exceed the current terminfo defined limits.
     45  *
     46  * Version 1 capabilities are defined as:
     47  * header byte (always 1)
     48  * name
     49  * description,
     50  * cap length, num flags, index, char,
     51  * cap length, num numbers, index, number,
     52  * cap length, num strings, index, string,
     53  * cap length, num undefined caps, name, type (char), flag, number, string
     54  *
     55  * Version 2 entries are aliases and defined as:
     56  * header byte (always 2)
     57  * 32bit id of the corresponding terminal in the file
     58  * name
     59  *
     60  * The database itself is created using cdbw(3) and the numbers are
     61  * always stored as little endian.
     62  */
     63 
     64 #include <sys/types.h>
     65 
     66 #define _TERMINFO
     67 
     68 /* We use the same ncurses tic macros so that our data is identical
     69  * when a caller uses the long name macros to access te terminfo data
     70  * directly. */
     71 #define ABSENT_BOOLEAN		((signed char)-1)       /* 255 */
     72 #define ABSENT_NUMERIC		(-1)
     73 #define ABSENT_STRING		(char *)0
     74 #define CANCELLED_BOOLEAN	((signed char)-2)       /* 254 */
     75 #define CANCELLED_NUMERIC	(-2)
     76 #define CANCELLED_STRING	(char *)(-1)
     77 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1)	/* reject "-1" */
     78 #define VALID_NUMERIC(s) ((s) >= 0)
     79 #define VALID_STRING(s)  ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
     80 
     81 typedef struct {
     82 	const char *id;
     83 	char type;
     84 	char flag;
     85 	short num;
     86 	const char *str;
     87 } TERMUSERDEF;
     88 
     89 typedef struct {
     90 	int fildes;
     91 	/* We need to expose these so that the macros work */
     92 	const char *name;
     93 	const char *desc;
     94 	signed char *flags;
     95 	short *nums;
     96 	const char **strs;
     97 	/* Storage area for terminfo data */
     98 	char *_area;
     99 	size_t _arealen;
    100 	size_t _nuserdefs;
    101 	TERMUSERDEF *_userdefs;
    102 	/* So we don't rely on the global ospeed */
    103 	short _ospeed;
    104 	/* Output buffer for tparm */
    105 	char *_buf;
    106 	size_t _buflen;
    107 	size_t _bufpos;
    108 	/* A-Z static variables for tparm  */
    109 	long _snums[26];
    110 	/* aliases of the terminal, | separated */
    111 	const char *_alias;
    112 } TERMINAL;
    113 
    114 extern const char *	_ti_database;
    115 
    116 ssize_t		_ti_flagindex(const char *);
    117 ssize_t		_ti_numindex(const char *);
    118 ssize_t		_ti_strindex(const char *);
    119 const char *	_ti_flagid(ssize_t);
    120 const char *	_ti_numid(ssize_t);
    121 const char *	_ti_strid(ssize_t);
    122 int		_ti_getterm(TERMINAL *, const char *, int);
    123 void		_ti_setospeed(TERMINAL *);
    124 
    125 /* libterminfo can compile terminfo strings too */
    126 #define TIC_WARNING	(1 << 0)
    127 #define TIC_DESCRIPTION	(1 << 1)
    128 #define TIC_ALIAS	(1 << 2)
    129 #define TIC_COMMENT	(1 << 3)
    130 #define TIC_EXTRA	(1 << 4)
    131 
    132 #define UINT16_T_MAX 0xffff
    133 
    134 typedef struct {
    135 	char *buf;
    136 	size_t buflen;
    137 	size_t bufpos;
    138 	size_t entries;
    139 } TBUF;
    140 
    141 typedef struct {
    142 	char *name;
    143 	char *alias;
    144 	char *desc;
    145 	TBUF flags;
    146 	TBUF nums;
    147 	TBUF strs;
    148 	TBUF extras;
    149 } TIC;
    150 
    151 char *_ti_grow_tbuf(TBUF *, size_t);
    152 char *_ti_get_token(char **, char);
    153 char *_ti_find_cap(TBUF *, char,  short);
    154 char *_ti_find_extra(TBUF *, const char *);
    155 size_t _ti_store_extra(TIC *, int, char *, char, char, short,
    156     char *, size_t, int);
    157 TIC *_ti_compile(char *, int);
    158 ssize_t _ti_flatten(uint8_t **, const TIC *);
    159 void _ti_freetic(TIC *);
    160 
    161 #define TPARM_MAX 9	/* not likely to change */
    162 int _ti_parm_analyse(const char *, int *, int);
    163 #endif
    164