1 /* $OpenBSD: term_entry.h,v 1.13 2023/10/17 09:52:08 nicm Exp $ */ 2 3 /**************************************************************************** 4 * Copyright 2018-2022,2023 Thomas E. Dickey * 5 * Copyright 1998-2015,2017 Free Software Foundation, Inc. * 6 * * 7 * Permission is hereby granted, free of charge, to any person obtaining a * 8 * copy of this software and associated documentation files (the * 9 * "Software"), to deal in the Software without restriction, including * 10 * without limitation the rights to use, copy, modify, merge, publish, * 11 * distribute, distribute with modifications, sublicense, and/or sell * 12 * copies of the Software, and to permit persons to whom the Software is * 13 * furnished to do so, subject to the following conditions: * 14 * * 15 * The above copyright notice and this permission notice shall be included * 16 * in all copies or substantial portions of the Software. * 17 * * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 21 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 24 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 25 * * 26 * Except as contained in this notice, the name(s) of the above copyright * 27 * holders shall not be used in advertising or otherwise to promote the * 28 * sale, use or other dealings in this Software without prior written * 29 * authorization. * 30 ****************************************************************************/ 31 32 /**************************************************************************** 33 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * 34 * and: Eric S. Raymond <esr@snark.thyrsus.com> * 35 * and: Thomas E. Dickey 1998-on * 36 ****************************************************************************/ 37 38 /* $Id: term_entry.h,v 1.13 2023/10/17 09:52:08 nicm Exp $ */ 39 40 /* 41 * term_entry.h -- interface to entry-manipulation code 42 */ 43 44 #ifndef NCURSES_TERM_ENTRY_H_incl 45 #define NCURSES_TERM_ENTRY_H_incl 1 46 /* *INDENT-OFF* */ 47 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 #include <curses.h> 53 #include <term.h> 54 55 /* 56 * These macros may be used by programs that know about TERMTYPE: 57 */ 58 #if NCURSES_XNAMES 59 #define NUM_BOOLEANS(tp) (tp)->num_Booleans 60 #define NUM_NUMBERS(tp) (tp)->num_Numbers 61 #define NUM_STRINGS(tp) (tp)->num_Strings 62 #define EXT_NAMES(tp,i,limit,index,table) (i >= limit) ? tp->ext_Names[index] : table[i] 63 #else 64 #define NUM_BOOLEANS(tp) BOOLCOUNT 65 #define NUM_NUMBERS(tp) NUMCOUNT 66 #define NUM_STRINGS(tp) STRCOUNT 67 #define EXT_NAMES(tp,i,limit,index,table) table[i] 68 #endif 69 70 #define NUM_EXT_NAMES(tp) (unsigned) ((tp)->ext_Booleans + (tp)->ext_Numbers + (tp)->ext_Strings) 71 72 #define for_each_boolean(n,tp) for(n = 0; n < NUM_BOOLEANS(tp); n++) 73 #define for_each_number(n,tp) for(n = 0; n < NUM_NUMBERS(tp); n++) 74 #define for_each_string(n,tp) for(n = 0; n < NUM_STRINGS(tp); n++) 75 76 #if NCURSES_XNAMES 77 #define for_each_ext_boolean(n,tp) for(n = BOOLCOUNT; (int) n < (int) NUM_BOOLEANS(tp); n++) 78 #define for_each_ext_number(n,tp) for(n = NUMCOUNT; (int) n < (int) NUM_NUMBERS(tp); n++) 79 #define for_each_ext_string(n,tp) for(n = STRCOUNT; (int) n < (int) NUM_STRINGS(tp); n++) 80 #endif 81 82 #define ExtBoolname(tp,i,names) EXT_NAMES(tp, i, BOOLCOUNT, (i - (tp->num_Booleans - tp->ext_Booleans)), names) 83 #define ExtNumname(tp,i,names) EXT_NAMES(tp, i, NUMCOUNT, (i - (tp->num_Numbers - tp->ext_Numbers)) + tp->ext_Booleans, names) 84 #define ExtStrname(tp,i,names) EXT_NAMES(tp, i, STRCOUNT, (i - (tp->num_Strings - tp->ext_Strings)) + (tp->ext_Numbers + tp->ext_Booleans), names) 85 86 /* 87 * The remaining type-definitions and macros are used only internally by the 88 * ncurses utilities. 89 */ 90 #ifdef NCURSES_INTERNALS 91 92 /* 93 * see db_iterator.c - this enumeration lists the places searched for a 94 * terminal description and defines the order in which they are searched. 95 */ 96 typedef enum { 97 dbdTIC = 0, /* special, used by tic when writing entry */ 98 #if NCURSES_USE_DATABASE 99 dbdEnvOnce, /* the $TERMINFO environment variable */ 100 dbdHome, /* $HOME/.terminfo */ 101 dbdEnvList, /* the $TERMINFO_DIRS environment variable */ 102 dbdCfgList, /* the compiled-in TERMINFO_DIRS value */ 103 dbdCfgOnce, /* the compiled-in TERMINFO value */ 104 #endif 105 #if NCURSES_USE_TERMCAP 106 dbdEnvOnce2, /* the $TERMCAP environment variable */ 107 dbdEnvList2, /* the $TERMPATH environment variable */ 108 dbdCfgList2, /* the compiled-in TERMPATH */ 109 #endif 110 dbdLAST 111 } DBDIRS; 112 113 #define MAX_USES 32 114 #define MAX_CROSSLINKS 16 115 116 typedef struct entry ENTRY; 117 118 typedef struct { 119 char *name; 120 ENTRY *link; 121 long line; 122 } ENTRY_USES; 123 124 struct entry { 125 TERMTYPE2 tterm; 126 unsigned nuses; 127 ENTRY_USES uses[MAX_USES]; 128 int ncrosslinks; 129 ENTRY *crosslinks[MAX_CROSSLINKS]; 130 long cstart; 131 long cend; 132 long startline; 133 ENTRY *next; 134 ENTRY *last; 135 }; 136 137 extern NCURSES_EXPORT_VAR(ENTRY *) _nc_head; 138 extern NCURSES_EXPORT_VAR(ENTRY *) _nc_tail; 139 #define for_entry_list(qp) for (qp = _nc_head; qp; qp = qp->next) 140 #define for_entry_list2(qp,q0) for (qp = q0; qp; qp = qp->next) 141 142 #define MAX_LINE 132 143 144 #define NULLHOOK (bool(*)(ENTRY *))0 145 146 /* 147 * Note that WANTED and PRESENT are not simple inverses! If a capability 148 * has been explicitly cancelled, it is not considered WANTED. 149 */ 150 #define WANTED(s) ((s) == ABSENT_STRING) 151 #define PRESENT(s) (((s) != ABSENT_STRING) && ((s) != CANCELLED_STRING)) 152 153 #define ANDMISSING(p,q) \ 154 { \ 155 if (PRESENT(p) && !PRESENT(q)) \ 156 _nc_warning(#p " but no " #q); \ 157 } 158 159 #define PAIRED(p,q) \ 160 { \ 161 if (PRESENT(q) && !PRESENT(p)) \ 162 _nc_warning(#q " but no " #p); \ 163 if (PRESENT(p) && !PRESENT(q)) \ 164 _nc_warning(#p " but no " #q); \ 165 } 166 167 /* 168 * These entrypoints are used only by the ncurses utilities such as tic. 169 */ 170 171 /* alloc_entry.c: elementary allocation code */ 172 extern NCURSES_EXPORT(ENTRY *) _nc_copy_entry (ENTRY *oldp); 173 extern NCURSES_EXPORT(char *) _nc_save_str (const char *const); 174 extern NCURSES_EXPORT(void) _nc_init_entry (ENTRY *const); 175 extern NCURSES_EXPORT(void) _nc_merge_entry (ENTRY *const, ENTRY *const); 176 extern NCURSES_EXPORT(void) _nc_wrap_entry (ENTRY *const, bool); 177 178 /* alloc_ttype.c: elementary allocation code */ 179 extern NCURSES_EXPORT(void) _nc_align_termtype (TERMTYPE2 *, TERMTYPE2 *); 180 181 /* free_ttype.c: elementary allocation code */ 182 extern NCURSES_EXPORT(void) _nc_free_termtype (TERMTYPE *); 183 extern NCURSES_EXPORT(void) _nc_free_termtype1 (TERMTYPE *); 184 extern NCURSES_EXPORT(void) _nc_free_termtype2 (TERMTYPE2 *); 185 186 /* lib_termcap.c: trim sgr0 string for termcap users */ 187 extern NCURSES_EXPORT(char *) _nc_trim_sgr0 (TERMTYPE2 *); 188 189 /* parse_entry.c: entry-parsing code */ 190 #if NCURSES_XNAMES 191 extern NCURSES_EXPORT_VAR(bool) _nc_user_definable; 192 extern NCURSES_EXPORT_VAR(bool) _nc_disable_period; 193 #endif 194 extern NCURSES_EXPORT(int) _nc_parse_entry (ENTRY *, int, bool); 195 extern NCURSES_EXPORT(int) _nc_capcmp (const char *, const char *); 196 197 /* write_entry.c: writing an entry to the file system */ 198 extern NCURSES_EXPORT(void) _nc_set_writedir (const char *); 199 extern NCURSES_EXPORT(void) _nc_write_entry (TERMTYPE2 *const); 200 extern NCURSES_EXPORT(int) _nc_write_object (TERMTYPE2 *, char *, unsigned *, unsigned); 201 202 /* comp_parse.c: entry list handling */ 203 extern NCURSES_EXPORT(void) _nc_read_entry_source (FILE*, char*, int, bool, bool (*)(ENTRY*)); 204 extern NCURSES_EXPORT(bool) _nc_entry_match (char *, char *); 205 extern NCURSES_EXPORT(int) _nc_resolve_uses (bool); /* obs 20040705 */ 206 extern NCURSES_EXPORT(int) _nc_resolve_uses2 (bool, bool); 207 extern NCURSES_EXPORT(void) _nc_free_entries (ENTRY *); 208 extern NCURSES_IMPEXP void (NCURSES_API *_nc_check_termtype)(TERMTYPE *); /* obs 20040705 */ 209 extern NCURSES_IMPEXP void (NCURSES_API *_nc_check_termtype2)(TERMTYPE2 *, bool); 210 211 /* trace_xnames.c */ 212 extern NCURSES_EXPORT(void) _nc_trace_xnames (TERMTYPE *); 213 214 #endif /* NCURSES_INTERNALS */ 215 216 #ifdef __cplusplus 217 } 218 #endif 219 220 /* *INDENT-ON* */ 221 222 #endif /* NCURSES_TERM_ENTRY_H_incl */ 223