Home | History | Annotate | Line # | Download | only in libterminfo
term_private.h revision 1.8
      1 /* $NetBSD: term_private.h,v 1.8 2010/09/22 06:10:51 roy Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2009, 2010 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  * The header is version (char), name.
     46  * version 0 is an alias, and the name refers to the real terminfo.
     47  * version 1 capabilities are defined as so:
     48  * description,
     49  * cap length, num flags, index, char,
     50  * cap length, num numbers, index, number,
     51  * cap length, num strings, index, string,
     52  * cap lelngth, num undefined caps, name, type (char), flag, number, string
     53  * The database itself is created using ndbm(3) and the numbers are
     54  * always stored as little endian.
     55  */
     56 
     57 #include <sys/types.h>
     58 
     59 #define _TERMINFO
     60 
     61 /* We use the same ncurses tic macros so that our data is identical
     62  * when a caller uses the long name macros to access te terminfo data
     63  * directly. */
     64 #define ABSENT_BOOLEAN		((signed char)-1)       /* 255 */
     65 #define ABSENT_NUMERIC		(-1)
     66 #define ABSENT_STRING		(char *)0
     67 #define CANCELLED_BOOLEAN	((signed char)-2)       /* 254 */
     68 #define CANCELLED_NUMERIC	(-2)
     69 #define CANCELLED_STRING	(char *)(-1)
     70 #define VALID_BOOLEAN(s) ((unsigned char)(s) <= 1)	/* reject "-1" */
     71 #define VALID_NUMERIC(s) ((s) >= 0)
     72 #define VALID_STRING(s)  ((s) != CANCELLED_STRING && (s) != ABSENT_STRING)
     73 
     74 typedef struct {
     75 	const char *id;
     76 	char type;
     77 	char flag;
     78 	short num;
     79 	const char *str;
     80 } TERMUSERDEF;
     81 
     82 typedef struct {
     83 	int fildes;
     84 	/* We need to expose these so that the macros work */
     85 	const char *name;
     86 	const char *desc;
     87 	signed char *flags;
     88 	short *nums;
     89 	const char **strs;
     90 	/* Storage area for terminfo data */
     91 	char *_area;
     92 	size_t _arealen;
     93 	size_t _nuserdefs;
     94 	TERMUSERDEF *_userdefs;
     95 	/* So we don't rely on the global ospeed */
     96 	short _ospeed;
     97 	/* Output buffer for tparm */
     98 	char *_buf;
     99 	size_t _buflen;
    100 	size_t _bufpos;
    101 	/* A-Z static variables for tparm  */
    102 	long _snums[26];
    103 	/* aliases of the terminal, | separated */
    104 	const char *_alias;
    105 } TERMINAL;
    106 
    107 extern const char *	_ti_database;
    108 
    109 ssize_t		_ti_flagindex(const char *);
    110 ssize_t		_ti_numindex(const char *);
    111 ssize_t		_ti_strindex(const char *);
    112 const char *	_ti_flagid(ssize_t);
    113 const char *	_ti_numid(ssize_t);
    114 const char *	_ti_strid(ssize_t);
    115 int		_ti_getterm(TERMINAL *, const char *, int);
    116 void		_ti_setospeed(TERMINAL *);
    117 void		_ti_freeterm(TERMINAL *);
    118 
    119 /* libterminfo can compile terminfo strings too */
    120 #define TIC_WARNING	(1 << 0)
    121 #define TIC_DESCRIPTION	(1 << 1)
    122 #define TIC_ALIAS	(1 << 2)
    123 #define TIC_COMMENT	(1 << 3)
    124 #define TIC_EXTRA	(1 << 4)
    125 
    126 #define UINT16_T_MAX 0xffff
    127 
    128 typedef struct {
    129 	char *buf;
    130 	size_t buflen;
    131 	size_t bufpos;
    132 	size_t entries;
    133 } TBUF;
    134 
    135 typedef struct {
    136 	char *name;
    137 	char *alias;
    138 	char *desc;
    139 	TBUF flags;
    140 	TBUF nums;
    141 	TBUF strs;
    142 	TBUF extras;
    143 } TIC;
    144 
    145 char *_ti_grow_tbuf(TBUF *, size_t);
    146 char *_ti_get_token(char **, char);
    147 char *_ti_find_cap(TBUF *, char,  short);
    148 char *_ti_find_extra(TBUF *, const char *);
    149 size_t _ti_store_extra(TIC *, int, char *, char, char, short,
    150     char *, size_t, int);
    151 TIC *_ti_compile(char *, int);
    152 ssize_t _ti_flatten(uint8_t **, const TIC *);
    153 void _ti_freetic(TIC *);
    154 #endif
    155