xref: /openbsd-src/lib/libcurses/term_entry.h (revision a28daedfc357b214be5c701aa8ba8adb29a7f1c2)
1 /*	$OpenBSD: term_entry.h,v 1.11 2001/01/22 18:01:35 millert Exp $	*/
2 
3 /****************************************************************************
4  * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc.              *
5  *                                                                          *
6  * Permission is hereby granted, free of charge, to any person obtaining a  *
7  * copy of this software and associated documentation files (the            *
8  * "Software"), to deal in the Software without restriction, including      *
9  * without limitation the rights to use, copy, modify, merge, publish,      *
10  * distribute, distribute with modifications, sublicense, and/or sell       *
11  * copies of the Software, and to permit persons to whom the Software is    *
12  * furnished to do so, subject to the following conditions:                 *
13  *                                                                          *
14  * The above copyright notice and this permission notice shall be included  *
15  * in all copies or substantial portions of the Software.                   *
16  *                                                                          *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24  *                                                                          *
25  * Except as contained in this notice, the name(s) of the above copyright   *
26  * holders shall not be used in advertising or otherwise to promote the     *
27  * sale, use or other dealings in this Software without prior written       *
28  * authorization.                                                           *
29  ****************************************************************************/
30 
31 /****************************************************************************
32  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
33  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
34  ****************************************************************************/
35 
36 /* $From: term_entry.h,v 1.31 2001/01/13 22:44:41 tom Exp $ */
37 
38 /*
39  *	term_entry.h -- interface to entry-manipulation code
40  */
41 
42 #ifndef _TERM_ENTRY_H
43 #define _TERM_ENTRY_H
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
49 #include <term.h>
50 
51 #define MAX_USES	32
52 #define MAX_CROSSLINKS	16
53 
54 typedef struct entry {
55 	TERMTYPE	tterm;
56 	int		nuses;
57 	struct
58         {
59 	    char		*name;
60 	    struct entry	*link;
61 	    long	line;
62         }
63 	uses[MAX_USES];
64 	int		ncrosslinks;
65 	struct entry	*crosslinks[MAX_CROSSLINKS];
66 	long		cstart, cend;
67 	long		startline;
68 	struct entry	*next;
69 	struct entry	*last;
70 }
71 ENTRY;
72 
73 #if NCURSES_XNAMES
74 #define NUM_BOOLEANS(tp) (tp)->num_Booleans
75 #define NUM_NUMBERS(tp)  (tp)->num_Numbers
76 #define NUM_STRINGS(tp)  (tp)->num_Strings
77 #define EXT_NAMES(tp,i,limit,index,table) (i >= limit) ? tp->ext_Names[index] : table[i]
78 #else
79 #define NUM_BOOLEANS(tp) BOOLCOUNT
80 #define NUM_NUMBERS(tp)  NUMCOUNT
81 #define NUM_STRINGS(tp)  STRCOUNT
82 #define EXT_NAMES(tp,i,limit,index,table) table[i]
83 #endif
84 
85 #define NUM_EXT_NAMES(tp) ((tp)->ext_Booleans + (tp)->ext_Numbers + (tp)->ext_Strings)
86 
87 #define for_each_boolean(n,tp) for(n = 0; n < NUM_BOOLEANS(tp); n++)
88 #define for_each_number(n,tp)  for(n = 0; n < NUM_NUMBERS(tp);  n++)
89 #define for_each_string(n,tp)  for(n = 0; n < NUM_STRINGS(tp);  n++)
90 
91 #define ExtBoolname(tp,i,names) EXT_NAMES(tp, i, BOOLCOUNT, (i - (tp->num_Booleans - tp->ext_Booleans)), names)
92 #define ExtNumname(tp,i,names)  EXT_NAMES(tp, i, NUMCOUNT, (i - (tp->num_Numbers - tp->ext_Numbers)) + tp->ext_Booleans, names)
93 #define ExtStrname(tp,i,names)  EXT_NAMES(tp, i, STRCOUNT, (i - (tp->num_Strings - tp->ext_Strings)) + (tp->ext_Numbers + tp->ext_Booleans), names)
94 
95 extern NCURSES_EXPORT_VAR(ENTRY *) _nc_head;
96 extern NCURSES_EXPORT_VAR(ENTRY *) _nc_tail;
97 #define for_entry_list(qp)	for (qp = _nc_head; qp; qp = qp->next)
98 
99 #define MAX_LINE	132
100 
101 #define NULLHOOK        (bool(*)(ENTRY *))0
102 
103 /*
104  * Note that WANTED and PRESENT are not simple inverses!  If a capability
105  * has been explicitly cancelled, it's not considered WANTED.
106  */
107 #define WANTED(s)	((s) == ABSENT_STRING)
108 #define PRESENT(s)	(((s) != ABSENT_STRING) && ((s) != CANCELLED_STRING))
109 
110 #define ANDMISSING(p,q) \
111 		{if (PRESENT(p) && !PRESENT(q)) _nc_warning(#p " but no " #q);}
112 
113 #define PAIRED(p,q) \
114 		{ \
115 		if (PRESENT(q) && !PRESENT(p)) \
116 			_nc_warning(#q " but no " #p); \
117 		if (PRESENT(p) && !PRESENT(q)) \
118 			_nc_warning(#p " but no " #q); \
119 		}
120 
121 /* alloc_entry.c: elementary allocation code */
122 extern NCURSES_EXPORT(ENTRY *) _nc_copy_entry (ENTRY *oldp);
123 extern NCURSES_EXPORT(char *) _nc_save_str (const char *const);
124 extern NCURSES_EXPORT(void) _nc_init_entry (TERMTYPE *const);
125 extern NCURSES_EXPORT(void) _nc_merge_entry (TERMTYPE *const, TERMTYPE *const);
126 extern NCURSES_EXPORT(void) _nc_wrap_entry (ENTRY *const, bool);
127 
128 /* alloc_ttype.c: elementary allocation code */
129 extern NCURSES_EXPORT(void) _nc_align_termtype (TERMTYPE *, TERMTYPE *);
130 extern NCURSES_EXPORT(void) _nc_copy_termtype (TERMTYPE *, TERMTYPE *);
131 
132 /* free_ttype.c: elementary allocation code */
133 extern NCURSES_EXPORT(void) _nc_free_termtype (TERMTYPE *);
134 
135 /* lib_acs.c */
136 extern NCURSES_EXPORT(void) _nc_init_acs (void);	/* corresponds to traditional 'init_acs()' */
137 
138 /* parse_entry.c: entry-parsing code */
139 #if NCURSES_XNAMES
140 extern NCURSES_EXPORT_VAR(bool) _nc_user_definable;
141 extern NCURSES_EXPORT_VAR(bool) _nc_disable_period;
142 #endif
143 extern NCURSES_EXPORT(int) _nc_parse_entry (ENTRY *, int, bool);
144 extern NCURSES_EXPORT(int) _nc_capcmp (const char *, const char *);
145 
146 /* write_entry.c: writing an entry to the file system */
147 extern NCURSES_EXPORT(void) _nc_set_writedir (char *);
148 extern NCURSES_EXPORT(void) _nc_write_entry (TERMTYPE *const);
149 
150 /* comp_parse.c: entry list handling */
151 extern NCURSES_EXPORT(void) _nc_read_entry_source (FILE*, char*, int, bool, bool (*)(ENTRY*));
152 extern NCURSES_EXPORT(bool) _nc_entry_match (char *, char *);
153 extern NCURSES_EXPORT(int) _nc_resolve_uses (bool);
154 extern NCURSES_EXPORT(void) _nc_free_entries (ENTRY *);
155 extern NCURSES_IMPEXP void NCURSES_API (*_nc_check_termtype)(TERMTYPE *);
156 
157 /* trace_xnames.c */
158 extern NCURSES_EXPORT(void) _nc_trace_xnames (TERMTYPE *);
159 
160 #ifdef __OpenBSD__
161 /* read_bsd_terminfo.c: terminfo.db reading */
162 extern int _nc_read_bsd_terminfo_entry(const char * const, char * const, TERMTYPE *const);
163 extern int _nc_read_bsd_terminfo_file(const char * const, TERMTYPE *const);
164 #endif /* __OpenBSD__ */
165 
166 #ifdef __cplusplus
167 }
168 #endif
169 
170 #endif /* _TERM_ENTRY_H */
171