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