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