]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/term.priv.h
ncurses 6.4 - patch 20240420
[ncurses.git] / ncurses / term.priv.h
1 /****************************************************************************
2  * Copyright 2021-2023,2024 Thomas E. Dickey                                *
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  * $Id: term.priv.h,v 1.13 2024/03/02 20:43:06 tom Exp $
31  *
32  *      term.priv.h
33  *
34  *      Header file for terminfo library objects which are private to
35  *      the library.
36  */
37
38 #ifndef _TERM_PRIV_H
39 #define _TERM_PRIV_H 1
40 /* *INDENT-OFF* */
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 #include <ncurses_cfg.h>
47
48 #ifndef __NCURSES_H
49 #include <curses.h>
50 #endif
51
52 #undef NCURSES_OPAQUE
53 #define NCURSES_INTERNALS 1
54 #define NCURSES_OPAQUE 0
55
56 #if HAVE_LIMITS_H
57 # include <limits.h>            /* PATH_MAX, MB_LEN_MAX, etc */
58 #elif HAVE_SYS_PARAM_H
59 # include <sys/param.h>
60 #endif
61
62 #include <signal.h>             /* sig_atomic_t */
63 #include <time.h>               /* time_t */
64 #include <term.h>               /* time_t */
65
66 #ifdef USE_PTHREADS
67 #if USE_REENTRANT
68 #include <pthread.h>
69 #endif
70 #endif
71
72 /*
73  * If not properly configured to use the system's limits.h, we get gcc's
74  * fallback for limits.h which sets MB_LEN_MAX to 1, which is never correct.
75  */
76 #if !HAVE_CONSISTENT_MB_LEN_MAX
77 #undef MB_LEN_MAX
78 #endif
79
80 #ifndef MB_LEN_MAX
81 #define MB_LEN_MAX 16   /* should be >= MB_CUR_MAX, but that may be a function */
82 #endif
83
84 #ifndef PATH_MAX
85 # if defined(_POSIX_PATH_MAX)
86 #  define PATH_MAX _POSIX_PATH_MAX
87 # elif defined(MAXPATHLEN)
88 #  define PATH_MAX MAXPATHLEN
89 # else
90 #  define PATH_MAX 255  /* the Posix minimum path-size */
91 # endif
92 #endif
93
94 /*
95  * State of tparm().
96  */
97 #define STACKSIZE 20
98
99 typedef struct {
100         union {
101                 int     num;
102                 char *  str;
103         } data;
104         bool num_type;
105 } STACK_FRAME;
106
107 #define NUM_VARS 26
108
109 typedef struct {
110         const char *    tparam_base;
111
112         STACK_FRAME     stack[STACKSIZE];
113         int             stack_ptr;
114
115         char *          out_buff;
116         size_t          out_size;
117         size_t          out_used;
118
119         char *          fmt_buff;
120         size_t          fmt_size;
121
122         int             static_vars[NUM_VARS];
123 #ifdef TRACE
124         const char *    tname;
125 #endif
126 } TPARM_STATE;
127
128 typedef struct {
129         char *          text;
130         size_t          size;
131 } TRACEBUF;
132
133 typedef struct {
134         const char *    name;
135         char *          value;
136 } ITERATOR_VARS;
137
138 /*
139  * Internals for term.h
140  */
141 typedef struct term {                   /* describe an actual terminal */
142         TERMTYPE        type;           /* terminal type description */
143         short           Filedes;        /* file description being written to */
144         TTY             Ottyb;          /* original state of the terminal */
145         TTY             Nttyb;          /* current state of the terminal */
146         int             _baudrate;      /* used to compute padding */
147         char *          _termname;      /* used for termname() */
148         TPARM_STATE     tparm_state;
149 #if NCURSES_EXT_COLORS
150         TERMTYPE2       type2;          /* extended terminal type description */
151 #endif
152 #undef TERMINAL
153 } TERMINAL;
154
155 /*
156  * Internals for soft-keys
157  */
158 typedef struct {
159         WINDOW *        win;            /* the window used in the hook      */
160         int             line;           /* lines to take, < 0 => from bottom*/
161         int             (*hook)(WINDOW *, int); /* callback for user        */
162 } ripoff_t;
163
164 /*
165  * Internals for tgetent
166  */
167 typedef struct {
168         long            sequence;
169         bool            last_used;
170         char *          fix_sgr0;       /* this holds the filtered sgr0 string */
171         char *          last_bufp;      /* help with fix_sgr0 leak */
172         TERMINAL *      last_term;
173 } TGETENT_CACHE;
174
175 #define TGETENT_MAX 4
176
177 #include <term_entry.h>         /* dbdLAST */
178
179 #ifdef USE_TERM_DRIVER
180 struct DriverTCB; /* Terminal Control Block forward declaration */
181 #endif
182
183 /*
184  * Global data which is not specific to a screen.
185  */
186 typedef struct {
187         SIG_ATOMIC_T    have_sigtstp;
188         SIG_ATOMIC_T    have_sigwinch;
189         SIG_ATOMIC_T    cleanup_nested;
190
191         bool            init_signals;
192         bool            init_screen;
193
194         char *          comp_sourcename;
195         char *          comp_termtype;
196
197         bool            have_tic_directory;
198         bool            keep_tic_directory;
199         const char *    tic_directory;
200
201         char *          dbi_list;
202         int             dbi_size;
203
204         char *          first_name;
205         char **         keyname_table;
206         int             init_keyname;
207
208         int             slk_format;
209
210         int             getstr_limit;   /* getstr_limit based on POSIX LINE_MAX */
211
212         char *          safeprint_buf;
213         size_t          safeprint_used;
214
215         TGETENT_CACHE   tgetent_cache[TGETENT_MAX];
216         int             tgetent_index;
217         long            tgetent_sequence;
218         int             terminal_count;
219
220         char *          dbd_blob;       /* string-heap for dbd_list[] */
221         char **         dbd_list;       /* distinct places to look for data */
222         int             dbd_size;       /* length of dbd_list[] */
223         time_t          dbd_time;       /* cache last updated */
224         ITERATOR_VARS   dbd_vars[dbdLAST];
225
226 #if HAVE_TSEARCH
227         void *          cached_tparm;
228         int             count_tparm;
229 #endif /* HAVE_TSEARCH */
230
231 #ifdef USE_TERM_DRIVER
232         int             (*term_driver)(struct DriverTCB*, const char*, int*);
233 #endif
234
235 #define WINDOWLIST struct _win_list
236
237 #ifndef USE_SP_WINDOWLIST
238         WINDOWLIST *    _nc_windowlist;
239 #define WindowList(sp)  _nc_globals._nc_windowlist
240 #endif
241
242 #if USE_HOME_TERMINFO
243         char *          home_terminfo;
244 #endif
245
246 #if !USE_SAFE_SPRINTF
247         int             safeprint_cols;
248         int             safeprint_rows;
249 #endif
250
251 #ifdef USE_PTHREADS
252         pthread_mutex_t mutex_curses;
253         pthread_mutex_t mutex_prescreen;
254         pthread_mutex_t mutex_screen;
255         pthread_mutex_t mutex_update;
256         pthread_mutex_t mutex_tst_tracef;
257         pthread_mutex_t mutex_tracef;
258         int             nested_tracef;
259         int             use_pthreads;
260 #define _nc_use_pthreads        _nc_globals.use_pthreads
261 #if USE_PTHREADS_EINTR
262         pthread_t       read_thread;    /* The reading thread */
263 #endif
264 #endif
265 #if USE_WIDEC_SUPPORT
266         char            key_name[MB_LEN_MAX + 1];
267 #endif
268
269 #ifdef TRACE
270         bool            trace_opened;
271         int             trace_level;
272         FILE *          trace_fp;
273         int             trace_fd;
274
275         char *          tracearg_buf;
276         size_t          tracearg_used;
277
278         TRACEBUF *      tracebuf_ptr;
279         size_t          tracebuf_used;
280
281         char            tracechr_buf[40];
282
283         char *          tracedmp_buf;
284         size_t          tracedmp_used;
285
286         unsigned char * tracetry_buf;
287         size_t          tracetry_used;
288
289         char            traceatr_color_buf[2][80];
290         int             traceatr_color_sel;
291         int             traceatr_color_last;
292 #if !defined(USE_PTHREADS) && USE_REENTRANT
293         int             nested_tracef;
294 #endif
295 #endif  /* TRACE */
296
297 #if NO_LEAKS
298         bool            leak_checking;
299 #endif
300 } NCURSES_GLOBALS;
301
302 extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals;
303
304 #define N_RIPS 5
305
306 #ifdef USE_PTHREADS
307 typedef struct _prescreen_list {
308         struct _prescreen_list *next;
309         pthread_t       id;
310         struct screen * sp;
311 } PRESCREEN_LIST;
312 #endif
313
314 /*
315  * Global data which can be swept up into a SCREEN when one is created.
316  * It may be modified before the next SCREEN is created.
317  */
318 typedef struct {
319 #ifdef USE_PTHREADS
320         PRESCREEN_LIST *allocated;
321 #else
322         struct screen * allocated;
323 #endif
324         bool            use_env;
325         bool            filter_mode;
326         attr_t          previous_attr;
327         TPARM_STATE     tparm_state;
328         TTY *           saved_tty;      /* savetty/resetty information    */
329         bool            use_tioctl;
330         NCURSES_SP_OUTC _outch;         /* output handler if not putc */
331 #ifndef USE_SP_RIPOFF
332         ripoff_t        rippedoff[N_RIPS];
333         ripoff_t *      rsp;
334 #endif
335 #if NCURSES_NO_PADDING
336         bool            _no_padding;    /* flag to set if padding disabled */
337 #endif
338 #if BROKEN_LINKER || USE_REENTRANT
339         chtype *        real_acs_map;
340         int             _LINES;
341         int             _COLS;
342         int             _TABSIZE;
343         int             _ESCDELAY;
344         TERMINAL *      _cur_term;
345 #endif
346 #ifdef TRACE
347 #if BROKEN_LINKER || USE_REENTRANT
348         long            _outchars;
349         const char *    _tputs_trace;
350 #endif
351 #endif
352 } NCURSES_PRESCREEN;
353
354 extern NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen;
355
356 extern NCURSES_EXPORT(void) _nc_free_tparm(TERMINAL*);
357
358 #ifdef __cplusplus
359 }
360 #endif
361
362 /* *INDENT-ON* */
363
364 #endif /* _TERM_PRIV_H */