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