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