1*c7ef0cfcSnicm /* $OpenBSD: term_entry.h,v 1.13 2023/10/17 09:52:08 nicm Exp $ */ 204dfece0Smillert 304dfece0Smillert /**************************************************************************** 4*c7ef0cfcSnicm * Copyright 2018-2022,2023 Thomas E. Dickey * 5*c7ef0cfcSnicm * Copyright 1998-2015,2017 Free Software Foundation, Inc. * 604dfece0Smillert * * 704dfece0Smillert * Permission is hereby granted, free of charge, to any person obtaining a * 804dfece0Smillert * copy of this software and associated documentation files (the * 904dfece0Smillert * "Software"), to deal in the Software without restriction, including * 1004dfece0Smillert * without limitation the rights to use, copy, modify, merge, publish, * 1104dfece0Smillert * distribute, distribute with modifications, sublicense, and/or sell * 1204dfece0Smillert * copies of the Software, and to permit persons to whom the Software is * 1304dfece0Smillert * furnished to do so, subject to the following conditions: * 1404dfece0Smillert * * 1504dfece0Smillert * The above copyright notice and this permission notice shall be included * 1604dfece0Smillert * in all copies or substantial portions of the Software. * 1704dfece0Smillert * * 1804dfece0Smillert * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 1904dfece0Smillert * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 2004dfece0Smillert * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 2104dfece0Smillert * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 2204dfece0Smillert * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 2304dfece0Smillert * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 2404dfece0Smillert * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 2504dfece0Smillert * * 2604dfece0Smillert * Except as contained in this notice, the name(s) of the above copyright * 2704dfece0Smillert * holders shall not be used in advertising or otherwise to promote the * 2804dfece0Smillert * sale, use or other dealings in this Software without prior written * 2904dfece0Smillert * authorization. * 3004dfece0Smillert ****************************************************************************/ 3104dfece0Smillert 3204dfece0Smillert /**************************************************************************** 3304dfece0Smillert * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * 3404dfece0Smillert * and: Eric S. Raymond <esr@snark.thyrsus.com> * 3581d8c4e1Snicm * and: Thomas E. Dickey 1998-on * 3604dfece0Smillert ****************************************************************************/ 3704dfece0Smillert 38*c7ef0cfcSnicm /* $Id: term_entry.h,v 1.13 2023/10/17 09:52:08 nicm Exp $ */ 3904dfece0Smillert 4004dfece0Smillert /* 4104dfece0Smillert * term_entry.h -- interface to entry-manipulation code 4204dfece0Smillert */ 4304dfece0Smillert 4481d8c4e1Snicm #ifndef NCURSES_TERM_ENTRY_H_incl 4581d8c4e1Snicm #define NCURSES_TERM_ENTRY_H_incl 1 46*c7ef0cfcSnicm /* *INDENT-OFF* */ 4704dfece0Smillert 4892dd1ec0Smillert #ifdef __cplusplus 4992dd1ec0Smillert extern "C" { 5092dd1ec0Smillert #endif 5192dd1ec0Smillert 52*c7ef0cfcSnicm #include <curses.h> 53feef4803Smillert #include <term.h> 54feef4803Smillert 55*c7ef0cfcSnicm /* 56*c7ef0cfcSnicm * These macros may be used by programs that know about TERMTYPE: 57*c7ef0cfcSnicm */ 58feef4803Smillert #if NCURSES_XNAMES 59feef4803Smillert #define NUM_BOOLEANS(tp) (tp)->num_Booleans 60feef4803Smillert #define NUM_NUMBERS(tp) (tp)->num_Numbers 61feef4803Smillert #define NUM_STRINGS(tp) (tp)->num_Strings 62feef4803Smillert #define EXT_NAMES(tp,i,limit,index,table) (i >= limit) ? tp->ext_Names[index] : table[i] 63feef4803Smillert #else 64feef4803Smillert #define NUM_BOOLEANS(tp) BOOLCOUNT 65feef4803Smillert #define NUM_NUMBERS(tp) NUMCOUNT 66feef4803Smillert #define NUM_STRINGS(tp) STRCOUNT 67feef4803Smillert #define EXT_NAMES(tp,i,limit,index,table) table[i] 68feef4803Smillert #endif 69feef4803Smillert 70*c7ef0cfcSnicm #define NUM_EXT_NAMES(tp) (unsigned) ((tp)->ext_Booleans + (tp)->ext_Numbers + (tp)->ext_Strings) 71feef4803Smillert 72feef4803Smillert #define for_each_boolean(n,tp) for(n = 0; n < NUM_BOOLEANS(tp); n++) 73feef4803Smillert #define for_each_number(n,tp) for(n = 0; n < NUM_NUMBERS(tp); n++) 74feef4803Smillert #define for_each_string(n,tp) for(n = 0; n < NUM_STRINGS(tp); n++) 75feef4803Smillert 76*c7ef0cfcSnicm #if NCURSES_XNAMES 77*c7ef0cfcSnicm #define for_each_ext_boolean(n,tp) for(n = BOOLCOUNT; (int) n < (int) NUM_BOOLEANS(tp); n++) 78*c7ef0cfcSnicm #define for_each_ext_number(n,tp) for(n = NUMCOUNT; (int) n < (int) NUM_NUMBERS(tp); n++) 79*c7ef0cfcSnicm #define for_each_ext_string(n,tp) for(n = STRCOUNT; (int) n < (int) NUM_STRINGS(tp); n++) 80*c7ef0cfcSnicm #endif 81*c7ef0cfcSnicm 82feef4803Smillert #define ExtBoolname(tp,i,names) EXT_NAMES(tp, i, BOOLCOUNT, (i - (tp->num_Booleans - tp->ext_Booleans)), names) 83feef4803Smillert #define ExtNumname(tp,i,names) EXT_NAMES(tp, i, NUMCOUNT, (i - (tp->num_Numbers - tp->ext_Numbers)) + tp->ext_Booleans, names) 84feef4803Smillert #define ExtStrname(tp,i,names) EXT_NAMES(tp, i, STRCOUNT, (i - (tp->num_Strings - tp->ext_Strings)) + (tp->ext_Numbers + tp->ext_Booleans), names) 85feef4803Smillert 86*c7ef0cfcSnicm /* 87*c7ef0cfcSnicm * The remaining type-definitions and macros are used only internally by the 88*c7ef0cfcSnicm * ncurses utilities. 89*c7ef0cfcSnicm */ 90*c7ef0cfcSnicm #ifdef NCURSES_INTERNALS 91*c7ef0cfcSnicm 92*c7ef0cfcSnicm /* 93*c7ef0cfcSnicm * see db_iterator.c - this enumeration lists the places searched for a 94*c7ef0cfcSnicm * terminal description and defines the order in which they are searched. 95*c7ef0cfcSnicm */ 96*c7ef0cfcSnicm typedef enum { 97*c7ef0cfcSnicm dbdTIC = 0, /* special, used by tic when writing entry */ 98*c7ef0cfcSnicm #if NCURSES_USE_DATABASE 99*c7ef0cfcSnicm dbdEnvOnce, /* the $TERMINFO environment variable */ 100*c7ef0cfcSnicm dbdHome, /* $HOME/.terminfo */ 101*c7ef0cfcSnicm dbdEnvList, /* the $TERMINFO_DIRS environment variable */ 102*c7ef0cfcSnicm dbdCfgList, /* the compiled-in TERMINFO_DIRS value */ 103*c7ef0cfcSnicm dbdCfgOnce, /* the compiled-in TERMINFO value */ 104*c7ef0cfcSnicm #endif 105*c7ef0cfcSnicm #if NCURSES_USE_TERMCAP 106*c7ef0cfcSnicm dbdEnvOnce2, /* the $TERMCAP environment variable */ 107*c7ef0cfcSnicm dbdEnvList2, /* the $TERMPATH environment variable */ 108*c7ef0cfcSnicm dbdCfgList2, /* the compiled-in TERMPATH */ 109*c7ef0cfcSnicm #endif 110*c7ef0cfcSnicm dbdLAST 111*c7ef0cfcSnicm } DBDIRS; 112*c7ef0cfcSnicm 113*c7ef0cfcSnicm #define MAX_USES 32 114*c7ef0cfcSnicm #define MAX_CROSSLINKS 16 115*c7ef0cfcSnicm 116*c7ef0cfcSnicm typedef struct entry ENTRY; 117*c7ef0cfcSnicm 118*c7ef0cfcSnicm typedef struct { 119*c7ef0cfcSnicm char *name; 120*c7ef0cfcSnicm ENTRY *link; 121*c7ef0cfcSnicm long line; 122*c7ef0cfcSnicm } ENTRY_USES; 123*c7ef0cfcSnicm 124*c7ef0cfcSnicm struct entry { 125*c7ef0cfcSnicm TERMTYPE2 tterm; 126*c7ef0cfcSnicm unsigned nuses; 127*c7ef0cfcSnicm ENTRY_USES uses[MAX_USES]; 128*c7ef0cfcSnicm int ncrosslinks; 129*c7ef0cfcSnicm ENTRY *crosslinks[MAX_CROSSLINKS]; 130*c7ef0cfcSnicm long cstart; 131*c7ef0cfcSnicm long cend; 132*c7ef0cfcSnicm long startline; 133*c7ef0cfcSnicm ENTRY *next; 134*c7ef0cfcSnicm ENTRY *last; 135*c7ef0cfcSnicm }; 136*c7ef0cfcSnicm 13784af20ceSmillert extern NCURSES_EXPORT_VAR(ENTRY *) _nc_head; 13884af20ceSmillert extern NCURSES_EXPORT_VAR(ENTRY *) _nc_tail; 13904dfece0Smillert #define for_entry_list(qp) for (qp = _nc_head; qp; qp = qp->next) 140*c7ef0cfcSnicm #define for_entry_list2(qp,q0) for (qp = q0; qp; qp = qp->next) 14104dfece0Smillert 14204dfece0Smillert #define MAX_LINE 132 14304dfece0Smillert 14404dfece0Smillert #define NULLHOOK (bool(*)(ENTRY *))0 14504dfece0Smillert 146c21ba70dSmillert /* 147c21ba70dSmillert * Note that WANTED and PRESENT are not simple inverses! If a capability 148*c7ef0cfcSnicm * has been explicitly cancelled, it is not considered WANTED. 149c21ba70dSmillert */ 150c21ba70dSmillert #define WANTED(s) ((s) == ABSENT_STRING) 151c21ba70dSmillert #define PRESENT(s) (((s) != ABSENT_STRING) && ((s) != CANCELLED_STRING)) 152c21ba70dSmillert 153c21ba70dSmillert #define ANDMISSING(p,q) \ 154*c7ef0cfcSnicm { \ 155*c7ef0cfcSnicm if (PRESENT(p) && !PRESENT(q)) \ 156*c7ef0cfcSnicm _nc_warning(#p " but no " #q); \ 157*c7ef0cfcSnicm } 158c21ba70dSmillert 159c21ba70dSmillert #define PAIRED(p,q) \ 160c21ba70dSmillert { \ 161c21ba70dSmillert if (PRESENT(q) && !PRESENT(p)) \ 162c21ba70dSmillert _nc_warning(#q " but no " #p); \ 163c21ba70dSmillert if (PRESENT(p) && !PRESENT(q)) \ 164c21ba70dSmillert _nc_warning(#p " but no " #q); \ 165c21ba70dSmillert } 166c21ba70dSmillert 167*c7ef0cfcSnicm /* 168*c7ef0cfcSnicm * These entrypoints are used only by the ncurses utilities such as tic. 169*c7ef0cfcSnicm */ 170*c7ef0cfcSnicm 17104dfece0Smillert /* alloc_entry.c: elementary allocation code */ 17284af20ceSmillert extern NCURSES_EXPORT(ENTRY *) _nc_copy_entry (ENTRY *oldp); 17384af20ceSmillert extern NCURSES_EXPORT(char *) _nc_save_str (const char *const); 174*c7ef0cfcSnicm extern NCURSES_EXPORT(void) _nc_init_entry (ENTRY *const); 175*c7ef0cfcSnicm extern NCURSES_EXPORT(void) _nc_merge_entry (ENTRY *const, ENTRY *const); 17684af20ceSmillert extern NCURSES_EXPORT(void) _nc_wrap_entry (ENTRY *const, bool); 17704dfece0Smillert 178feef4803Smillert /* alloc_ttype.c: elementary allocation code */ 179*c7ef0cfcSnicm extern NCURSES_EXPORT(void) _nc_align_termtype (TERMTYPE2 *, TERMTYPE2 *); 180feef4803Smillert 181feef4803Smillert /* free_ttype.c: elementary allocation code */ 18284af20ceSmillert extern NCURSES_EXPORT(void) _nc_free_termtype (TERMTYPE *); 183*c7ef0cfcSnicm extern NCURSES_EXPORT(void) _nc_free_termtype1 (TERMTYPE *); 184*c7ef0cfcSnicm extern NCURSES_EXPORT(void) _nc_free_termtype2 (TERMTYPE2 *); 185d753508aSmillert 18681d8c4e1Snicm /* lib_termcap.c: trim sgr0 string for termcap users */ 187*c7ef0cfcSnicm extern NCURSES_EXPORT(char *) _nc_trim_sgr0 (TERMTYPE2 *); 18881d8c4e1Snicm 18904dfece0Smillert /* parse_entry.c: entry-parsing code */ 190feef4803Smillert #if NCURSES_XNAMES 19184af20ceSmillert extern NCURSES_EXPORT_VAR(bool) _nc_user_definable; 19284af20ceSmillert extern NCURSES_EXPORT_VAR(bool) _nc_disable_period; 193feef4803Smillert #endif 19484af20ceSmillert extern NCURSES_EXPORT(int) _nc_parse_entry (ENTRY *, int, bool); 19584af20ceSmillert extern NCURSES_EXPORT(int) _nc_capcmp (const char *, const char *); 19604dfece0Smillert 19704dfece0Smillert /* write_entry.c: writing an entry to the file system */ 198*c7ef0cfcSnicm extern NCURSES_EXPORT(void) _nc_set_writedir (const char *); 199*c7ef0cfcSnicm extern NCURSES_EXPORT(void) _nc_write_entry (TERMTYPE2 *const); 200*c7ef0cfcSnicm extern NCURSES_EXPORT(int) _nc_write_object (TERMTYPE2 *, char *, unsigned *, unsigned); 20104dfece0Smillert 20204dfece0Smillert /* comp_parse.c: entry list handling */ 20384af20ceSmillert extern NCURSES_EXPORT(void) _nc_read_entry_source (FILE*, char*, int, bool, bool (*)(ENTRY*)); 20484af20ceSmillert extern NCURSES_EXPORT(bool) _nc_entry_match (char *, char *); 20581d8c4e1Snicm extern NCURSES_EXPORT(int) _nc_resolve_uses (bool); /* obs 20040705 */ 20681d8c4e1Snicm extern NCURSES_EXPORT(int) _nc_resolve_uses2 (bool, bool); 20784af20ceSmillert extern NCURSES_EXPORT(void) _nc_free_entries (ENTRY *); 208*c7ef0cfcSnicm extern NCURSES_IMPEXP void (NCURSES_API *_nc_check_termtype)(TERMTYPE *); /* obs 20040705 */ 209*c7ef0cfcSnicm extern NCURSES_IMPEXP void (NCURSES_API *_nc_check_termtype2)(TERMTYPE2 *, bool); 210c21ba70dSmillert 211feef4803Smillert /* trace_xnames.c */ 21284af20ceSmillert extern NCURSES_EXPORT(void) _nc_trace_xnames (TERMTYPE *); 21384af20ceSmillert 214*c7ef0cfcSnicm #endif /* NCURSES_INTERNALS */ 21504dfece0Smillert 21692dd1ec0Smillert #ifdef __cplusplus 21792dd1ec0Smillert } 21892dd1ec0Smillert #endif 21904dfece0Smillert 220*c7ef0cfcSnicm /* *INDENT-ON* */ 221*c7ef0cfcSnicm 22281d8c4e1Snicm #endif /* NCURSES_TERM_ENTRY_H_incl */ 223