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