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