1*c7ef0cfcSnicm /**************************************************************************** 2*c7ef0cfcSnicm * Copyright 2021 Thomas E. Dickey * 3*c7ef0cfcSnicm * * 4*c7ef0cfcSnicm * Permission is hereby granted, free of charge, to any person obtaining a * 5*c7ef0cfcSnicm * copy of this software and associated documentation files (the * 6*c7ef0cfcSnicm * "Software"), to deal in the Software without restriction, including * 7*c7ef0cfcSnicm * without limitation the rights to use, copy, modify, merge, publish, * 8*c7ef0cfcSnicm * distribute, distribute with modifications, sublicense, and/or sell * 9*c7ef0cfcSnicm * copies of the Software, and to permit persons to whom the Software is * 10*c7ef0cfcSnicm * furnished to do so, subject to the following conditions: * 11*c7ef0cfcSnicm * * 12*c7ef0cfcSnicm * The above copyright notice and this permission notice shall be included * 13*c7ef0cfcSnicm * in all copies or substantial portions of the Software. * 14*c7ef0cfcSnicm * * 15*c7ef0cfcSnicm * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 16*c7ef0cfcSnicm * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 17*c7ef0cfcSnicm * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 18*c7ef0cfcSnicm * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 19*c7ef0cfcSnicm * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 20*c7ef0cfcSnicm * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 21*c7ef0cfcSnicm * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 22*c7ef0cfcSnicm * * 23*c7ef0cfcSnicm * Except as contained in this notice, the name(s) of the above copyright * 24*c7ef0cfcSnicm * holders shall not be used in advertising or otherwise to promote the * 25*c7ef0cfcSnicm * sale, use or other dealings in this Software without prior written * 26*c7ef0cfcSnicm * authorization. * 27*c7ef0cfcSnicm ****************************************************************************/ 28*c7ef0cfcSnicm 29*c7ef0cfcSnicm /* 30*c7ef0cfcSnicm * $Id: term.priv.h,v 1.1 2023/10/17 09:52:08 nicm Exp $ 31*c7ef0cfcSnicm * 32*c7ef0cfcSnicm * term.priv.h 33*c7ef0cfcSnicm * 34*c7ef0cfcSnicm * Header file for terminfo library objects which are private to 35*c7ef0cfcSnicm * the library. 36*c7ef0cfcSnicm * 37*c7ef0cfcSnicm */ 38*c7ef0cfcSnicm 39*c7ef0cfcSnicm #ifndef _TERM_PRIV_H 40*c7ef0cfcSnicm #define _TERM_PRIV_H 1 41*c7ef0cfcSnicm /* *INDENT-OFF* */ 42*c7ef0cfcSnicm 43*c7ef0cfcSnicm #ifdef __cplusplus 44*c7ef0cfcSnicm extern "C" { 45*c7ef0cfcSnicm #endif 46*c7ef0cfcSnicm 47*c7ef0cfcSnicm #include <ncurses_cfg.h> 48*c7ef0cfcSnicm 49*c7ef0cfcSnicm #undef NCURSES_OPAQUE 50*c7ef0cfcSnicm #define NCURSES_INTERNALS 1 51*c7ef0cfcSnicm #define NCURSES_OPAQUE 0 52*c7ef0cfcSnicm 53*c7ef0cfcSnicm #include <limits.h> /* PATH_MAX */ 54*c7ef0cfcSnicm #include <signal.h> /* sig_atomic_t */ 55*c7ef0cfcSnicm #include <time.h> /* time_t */ 56*c7ef0cfcSnicm #include <term.h> /* time_t */ 57*c7ef0cfcSnicm 58*c7ef0cfcSnicm #ifdef USE_PTHREADS 59*c7ef0cfcSnicm #if USE_REENTRANT 60*c7ef0cfcSnicm #include <pthread.h> 61*c7ef0cfcSnicm #endif 62*c7ef0cfcSnicm #endif 63*c7ef0cfcSnicm 64*c7ef0cfcSnicm /* 65*c7ef0cfcSnicm * State of tparm(). 66*c7ef0cfcSnicm */ 67*c7ef0cfcSnicm #define STACKSIZE 20 68*c7ef0cfcSnicm 69*c7ef0cfcSnicm typedef struct { 70*c7ef0cfcSnicm union { 71*c7ef0cfcSnicm int num; 72*c7ef0cfcSnicm char * str; 73*c7ef0cfcSnicm } data; 74*c7ef0cfcSnicm bool num_type; 75*c7ef0cfcSnicm } STACK_FRAME; 76*c7ef0cfcSnicm 77*c7ef0cfcSnicm #define NUM_VARS 26 78*c7ef0cfcSnicm 79*c7ef0cfcSnicm typedef struct { 80*c7ef0cfcSnicm const char * tparam_base; 81*c7ef0cfcSnicm 82*c7ef0cfcSnicm STACK_FRAME stack[STACKSIZE]; 83*c7ef0cfcSnicm int stack_ptr; 84*c7ef0cfcSnicm 85*c7ef0cfcSnicm char * out_buff; 86*c7ef0cfcSnicm size_t out_size; 87*c7ef0cfcSnicm size_t out_used; 88*c7ef0cfcSnicm 89*c7ef0cfcSnicm char * fmt_buff; 90*c7ef0cfcSnicm size_t fmt_size; 91*c7ef0cfcSnicm 92*c7ef0cfcSnicm int static_vars[NUM_VARS]; 93*c7ef0cfcSnicm #ifdef TRACE 94*c7ef0cfcSnicm const char * tname; 95*c7ef0cfcSnicm #endif 96*c7ef0cfcSnicm } TPARM_STATE; 97*c7ef0cfcSnicm 98*c7ef0cfcSnicm typedef struct { 99*c7ef0cfcSnicm char * text; 100*c7ef0cfcSnicm size_t size; 101*c7ef0cfcSnicm } TRACEBUF; 102*c7ef0cfcSnicm 103*c7ef0cfcSnicm typedef struct { 104*c7ef0cfcSnicm const char * name; 105*c7ef0cfcSnicm char * value; 106*c7ef0cfcSnicm } ITERATOR_VARS; 107*c7ef0cfcSnicm 108*c7ef0cfcSnicm /* 109*c7ef0cfcSnicm * Internals for term.h 110*c7ef0cfcSnicm */ 111*c7ef0cfcSnicm typedef struct term { /* describe an actual terminal */ 112*c7ef0cfcSnicm TERMTYPE type; /* terminal type description */ 113*c7ef0cfcSnicm short Filedes; /* file description being written to */ 114*c7ef0cfcSnicm TTY Ottyb; /* original state of the terminal */ 115*c7ef0cfcSnicm TTY Nttyb; /* current state of the terminal */ 116*c7ef0cfcSnicm int _baudrate; /* used to compute padding */ 117*c7ef0cfcSnicm char * _termname; /* used for termname() */ 118*c7ef0cfcSnicm TPARM_STATE tparm_state; 119*c7ef0cfcSnicm #if NCURSES_EXT_COLORS 120*c7ef0cfcSnicm TERMTYPE2 type2; /* extended terminal type description */ 121*c7ef0cfcSnicm #endif 122*c7ef0cfcSnicm #undef TERMINAL 123*c7ef0cfcSnicm } TERMINAL; 124*c7ef0cfcSnicm 125*c7ef0cfcSnicm /* 126*c7ef0cfcSnicm * Internals for soft-keys 127*c7ef0cfcSnicm */ 128*c7ef0cfcSnicm typedef struct { 129*c7ef0cfcSnicm WINDOW * win; /* the window used in the hook */ 130*c7ef0cfcSnicm int line; /* lines to take, < 0 => from bottom*/ 131*c7ef0cfcSnicm int (*hook)(WINDOW *, int); /* callback for user */ 132*c7ef0cfcSnicm } ripoff_t; 133*c7ef0cfcSnicm 134*c7ef0cfcSnicm /* 135*c7ef0cfcSnicm * Internals for tgetent 136*c7ef0cfcSnicm */ 137*c7ef0cfcSnicm typedef struct { 138*c7ef0cfcSnicm long sequence; 139*c7ef0cfcSnicm bool last_used; 140*c7ef0cfcSnicm char * fix_sgr0; /* this holds the filtered sgr0 string */ 141*c7ef0cfcSnicm char * last_bufp; /* help with fix_sgr0 leak */ 142*c7ef0cfcSnicm TERMINAL * last_term; 143*c7ef0cfcSnicm } TGETENT_CACHE; 144*c7ef0cfcSnicm 145*c7ef0cfcSnicm #define TGETENT_MAX 4 146*c7ef0cfcSnicm 147*c7ef0cfcSnicm #include <term_entry.h> /* dbdLAST */ 148*c7ef0cfcSnicm 149*c7ef0cfcSnicm #ifdef USE_TERM_DRIVER 150*c7ef0cfcSnicm struct DriverTCB; /* Terminal Control Block forward declaration */ 151*c7ef0cfcSnicm #endif 152*c7ef0cfcSnicm 153*c7ef0cfcSnicm /* 154*c7ef0cfcSnicm * Global data which is not specific to a screen. 155*c7ef0cfcSnicm */ 156*c7ef0cfcSnicm typedef struct { 157*c7ef0cfcSnicm SIG_ATOMIC_T have_sigtstp; 158*c7ef0cfcSnicm SIG_ATOMIC_T have_sigwinch; 159*c7ef0cfcSnicm SIG_ATOMIC_T cleanup_nested; 160*c7ef0cfcSnicm 161*c7ef0cfcSnicm bool init_signals; 162*c7ef0cfcSnicm bool init_screen; 163*c7ef0cfcSnicm 164*c7ef0cfcSnicm char * comp_sourcename; 165*c7ef0cfcSnicm char * comp_termtype; 166*c7ef0cfcSnicm 167*c7ef0cfcSnicm bool have_tic_directory; 168*c7ef0cfcSnicm bool keep_tic_directory; 169*c7ef0cfcSnicm const char * tic_directory; 170*c7ef0cfcSnicm 171*c7ef0cfcSnicm char * dbi_list; 172*c7ef0cfcSnicm int dbi_size; 173*c7ef0cfcSnicm 174*c7ef0cfcSnicm char * first_name; 175*c7ef0cfcSnicm char ** keyname_table; 176*c7ef0cfcSnicm int init_keyname; 177*c7ef0cfcSnicm 178*c7ef0cfcSnicm int slk_format; 179*c7ef0cfcSnicm 180*c7ef0cfcSnicm int getstr_limit; /* getstr_limit based on POSIX LINE_MAX */ 181*c7ef0cfcSnicm 182*c7ef0cfcSnicm char * safeprint_buf; 183*c7ef0cfcSnicm size_t safeprint_used; 184*c7ef0cfcSnicm 185*c7ef0cfcSnicm TGETENT_CACHE tgetent_cache[TGETENT_MAX]; 186*c7ef0cfcSnicm int tgetent_index; 187*c7ef0cfcSnicm long tgetent_sequence; 188*c7ef0cfcSnicm int terminal_count; 189*c7ef0cfcSnicm 190*c7ef0cfcSnicm char * dbd_blob; /* string-heap for dbd_list[] */ 191*c7ef0cfcSnicm char ** dbd_list; /* distinct places to look for data */ 192*c7ef0cfcSnicm int dbd_size; /* length of dbd_list[] */ 193*c7ef0cfcSnicm time_t dbd_time; /* cache last updated */ 194*c7ef0cfcSnicm ITERATOR_VARS dbd_vars[dbdLAST]; 195*c7ef0cfcSnicm 196*c7ef0cfcSnicm #if HAVE_TSEARCH 197*c7ef0cfcSnicm void * cached_tparm; 198*c7ef0cfcSnicm int count_tparm; 199*c7ef0cfcSnicm #endif /* HAVE_TSEARCH */ 200*c7ef0cfcSnicm 201*c7ef0cfcSnicm #ifdef USE_TERM_DRIVER 202*c7ef0cfcSnicm int (*term_driver)(struct DriverTCB*, const char*, int*); 203*c7ef0cfcSnicm #endif 204*c7ef0cfcSnicm 205*c7ef0cfcSnicm #define WINDOWLIST struct _win_list 206*c7ef0cfcSnicm 207*c7ef0cfcSnicm #ifndef USE_SP_WINDOWLIST 208*c7ef0cfcSnicm WINDOWLIST * _nc_windowlist; 209*c7ef0cfcSnicm #define WindowList(sp) _nc_globals._nc_windowlist 210*c7ef0cfcSnicm #endif 211*c7ef0cfcSnicm 212*c7ef0cfcSnicm #if USE_HOME_TERMINFO 213*c7ef0cfcSnicm char * home_terminfo; 214*c7ef0cfcSnicm #endif 215*c7ef0cfcSnicm 216*c7ef0cfcSnicm #if !USE_SAFE_SPRINTF 217*c7ef0cfcSnicm int safeprint_cols; 218*c7ef0cfcSnicm int safeprint_rows; 219*c7ef0cfcSnicm #endif 220*c7ef0cfcSnicm 221*c7ef0cfcSnicm #ifdef USE_PTHREADS 222*c7ef0cfcSnicm pthread_mutex_t mutex_curses; 223*c7ef0cfcSnicm pthread_mutex_t mutex_prescreen; 224*c7ef0cfcSnicm pthread_mutex_t mutex_screen; 225*c7ef0cfcSnicm pthread_mutex_t mutex_update; 226*c7ef0cfcSnicm pthread_mutex_t mutex_tst_tracef; 227*c7ef0cfcSnicm pthread_mutex_t mutex_tracef; 228*c7ef0cfcSnicm int nested_tracef; 229*c7ef0cfcSnicm int use_pthreads; 230*c7ef0cfcSnicm #define _nc_use_pthreads _nc_globals.use_pthreads 231*c7ef0cfcSnicm #if USE_PTHREADS_EINTR 232*c7ef0cfcSnicm pthread_t read_thread; /* The reading thread */ 233*c7ef0cfcSnicm #endif 234*c7ef0cfcSnicm #endif 235*c7ef0cfcSnicm #if USE_WIDEC_SUPPORT 236*c7ef0cfcSnicm char key_name[MB_LEN_MAX + 1]; 237*c7ef0cfcSnicm #endif 238*c7ef0cfcSnicm 239*c7ef0cfcSnicm #ifdef TRACE 240*c7ef0cfcSnicm bool trace_opened; 241*c7ef0cfcSnicm char trace_fname[PATH_MAX]; 242*c7ef0cfcSnicm int trace_level; 243*c7ef0cfcSnicm FILE * trace_fp; 244*c7ef0cfcSnicm int trace_fd; 245*c7ef0cfcSnicm 246*c7ef0cfcSnicm char * tracearg_buf; 247*c7ef0cfcSnicm size_t tracearg_used; 248*c7ef0cfcSnicm 249*c7ef0cfcSnicm TRACEBUF * tracebuf_ptr; 250*c7ef0cfcSnicm size_t tracebuf_used; 251*c7ef0cfcSnicm 252*c7ef0cfcSnicm char tracechr_buf[40]; 253*c7ef0cfcSnicm 254*c7ef0cfcSnicm char * tracedmp_buf; 255*c7ef0cfcSnicm size_t tracedmp_used; 256*c7ef0cfcSnicm 257*c7ef0cfcSnicm unsigned char * tracetry_buf; 258*c7ef0cfcSnicm size_t tracetry_used; 259*c7ef0cfcSnicm 260*c7ef0cfcSnicm char traceatr_color_buf[2][80]; 261*c7ef0cfcSnicm int traceatr_color_sel; 262*c7ef0cfcSnicm int traceatr_color_last; 263*c7ef0cfcSnicm #if !defined(USE_PTHREADS) && USE_REENTRANT 264*c7ef0cfcSnicm int nested_tracef; 265*c7ef0cfcSnicm #endif 266*c7ef0cfcSnicm #endif /* TRACE */ 267*c7ef0cfcSnicm 268*c7ef0cfcSnicm #if NO_LEAKS 269*c7ef0cfcSnicm bool leak_checking; 270*c7ef0cfcSnicm #endif 271*c7ef0cfcSnicm } NCURSES_GLOBALS; 272*c7ef0cfcSnicm 273*c7ef0cfcSnicm extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals; 274*c7ef0cfcSnicm 275*c7ef0cfcSnicm #define N_RIPS 5 276*c7ef0cfcSnicm 277*c7ef0cfcSnicm #ifdef USE_PTHREADS 278*c7ef0cfcSnicm typedef struct _prescreen_list { 279*c7ef0cfcSnicm struct _prescreen_list *next; 280*c7ef0cfcSnicm pthread_t id; 281*c7ef0cfcSnicm struct screen * sp; 282*c7ef0cfcSnicm } PRESCREEN_LIST; 283*c7ef0cfcSnicm #endif 284*c7ef0cfcSnicm 285*c7ef0cfcSnicm /* 286*c7ef0cfcSnicm * Global data which can be swept up into a SCREEN when one is created. 287*c7ef0cfcSnicm * It may be modified before the next SCREEN is created. 288*c7ef0cfcSnicm */ 289*c7ef0cfcSnicm typedef struct { 290*c7ef0cfcSnicm #ifdef USE_PTHREADS 291*c7ef0cfcSnicm PRESCREEN_LIST *allocated; 292*c7ef0cfcSnicm #else 293*c7ef0cfcSnicm struct screen * allocated; 294*c7ef0cfcSnicm #endif 295*c7ef0cfcSnicm bool use_env; 296*c7ef0cfcSnicm bool filter_mode; 297*c7ef0cfcSnicm attr_t previous_attr; 298*c7ef0cfcSnicm TPARM_STATE tparm_state; 299*c7ef0cfcSnicm TTY * saved_tty; /* savetty/resetty information */ 300*c7ef0cfcSnicm bool use_tioctl; 301*c7ef0cfcSnicm NCURSES_SP_OUTC _outch; /* output handler if not putc */ 302*c7ef0cfcSnicm #ifndef USE_SP_RIPOFF 303*c7ef0cfcSnicm ripoff_t rippedoff[N_RIPS]; 304*c7ef0cfcSnicm ripoff_t * rsp; 305*c7ef0cfcSnicm #endif 306*c7ef0cfcSnicm #if NCURSES_NO_PADDING 307*c7ef0cfcSnicm bool _no_padding; /* flag to set if padding disabled */ 308*c7ef0cfcSnicm #endif 309*c7ef0cfcSnicm #if BROKEN_LINKER || USE_REENTRANT 310*c7ef0cfcSnicm chtype * real_acs_map; 311*c7ef0cfcSnicm int _LINES; 312*c7ef0cfcSnicm int _COLS; 313*c7ef0cfcSnicm int _TABSIZE; 314*c7ef0cfcSnicm int _ESCDELAY; 315*c7ef0cfcSnicm TERMINAL * _cur_term; 316*c7ef0cfcSnicm #endif 317*c7ef0cfcSnicm #ifdef TRACE 318*c7ef0cfcSnicm #if BROKEN_LINKER || USE_REENTRANT 319*c7ef0cfcSnicm long _outchars; 320*c7ef0cfcSnicm const char * _tputs_trace; 321*c7ef0cfcSnicm #endif 322*c7ef0cfcSnicm #endif 323*c7ef0cfcSnicm } NCURSES_PRESCREEN; 324*c7ef0cfcSnicm 325*c7ef0cfcSnicm extern NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen; 326*c7ef0cfcSnicm 327*c7ef0cfcSnicm extern NCURSES_EXPORT(void) _nc_free_tparm(TERMINAL*); 328*c7ef0cfcSnicm 329*c7ef0cfcSnicm #ifdef __cplusplus 330*c7ef0cfcSnicm } 331*c7ef0cfcSnicm #endif 332*c7ef0cfcSnicm 333*c7ef0cfcSnicm /* *INDENT-ON* */ 334*c7ef0cfcSnicm 335*c7ef0cfcSnicm #endif /* _TERM_PRIV_H */ 336