xref: /openbsd-src/lib/libcurses/curses.priv.h (revision a0747c9f67a4ae71ccb71e62a28d1ea19e06a63c)
1 /* $OpenBSD: curses.priv.h,v 1.35 2021/03/10 20:16:08 millert Exp $ */
2 
3 /****************************************************************************
4  * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
5  *                                                                          *
6  * Permission is hereby granted, free of charge, to any person obtaining a  *
7  * copy of this software and associated documentation files (the            *
8  * "Software"), to deal in the Software without restriction, including      *
9  * without limitation the rights to use, copy, modify, merge, publish,      *
10  * distribute, distribute with modifications, sublicense, and/or sell       *
11  * copies of the Software, and to permit persons to whom the Software is    *
12  * furnished to do so, subject to the following conditions:                 *
13  *                                                                          *
14  * The above copyright notice and this permission notice shall be included  *
15  * in all copies or substantial portions of the Software.                   *
16  *                                                                          *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24  *                                                                          *
25  * Except as contained in this notice, the name(s) of the above copyright   *
26  * holders shall not be used in advertising or otherwise to promote the     *
27  * sale, use or other dealings in this Software without prior written       *
28  * authorization.                                                           *
29  ****************************************************************************/
30 
31 /****************************************************************************
32  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
33  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
34  *     and: Thomas E. Dickey                        1996-on                 *
35  ****************************************************************************/
36 
37 
38 /*
39  * $Id: curses.priv.h,v 1.35 2021/03/10 20:16:08 millert Exp $
40  *
41  *	curses.priv.h
42  *
43  *	Header file for curses library objects which are private to
44  *	the library.
45  *
46  */
47 
48 #ifndef CURSES_PRIV_H
49 #define CURSES_PRIV_H 1
50 
51 #if !defined(NCURSES_IMPEXP)
52 #  define NCURSES_IMPEXP /* nothing */
53 #endif
54 #if !defined(NCURSES_API)
55 #  define NCURSES_API /* nothing */
56 #endif
57 #if !defined(NCURSES_EXPORT)
58 #  define NCURSES_EXPORT(type) NCURSES_IMPEXP type NCURSES_API
59 #endif
60 #if !defined(NCURSES_EXPORT_VAR)
61 #  define NCURSES_EXPORT_VAR(type) NCURSES_IMPEXP type
62 #endif
63 
64 #ifdef __cplusplus
65 extern "C" {
66 #endif
67 
68 #include <ncurses_cfg.h>
69 
70 #if USE_RCS_IDS
71 #define MODULE_ID(id) static const char Ident[] = id;
72 #else
73 #define MODULE_ID(id) /*nothing*/
74 #endif
75 
76 #include <stdlib.h>
77 #include <string.h>
78 #include <sys/types.h>
79 
80 #if HAVE_UNISTD_H
81 #include <unistd.h>
82 #endif
83 
84 #if HAVE_SYS_BSDTYPES_H
85 #include <sys/bsdtypes.h>	/* needed for ISC */
86 #endif
87 
88 #if HAVE_LIMITS_H
89 # include <limits.h>
90 #elif HAVE_SYS_PARAM_H
91 # include <sys/param.h>
92 #endif
93 
94 #include <assert.h>
95 #include <stdio.h>
96 
97 #include <errno.h>
98 
99 #ifndef PATH_MAX
100 # if defined(_POSIX_PATH_MAX)
101 #  define PATH_MAX _POSIX_PATH_MAX
102 # elif defined(MAXPATHLEN)
103 #  define PATH_MAX MAXPATHLEN
104 # else
105 #  define PATH_MAX 255	/* the Posix minimum path-size */
106 # endif
107 #endif
108 
109 #if DECL_ERRNO
110 extern int errno;
111 #endif
112 
113 #include <nc_panel.h>
114 
115 /* Some systems have a broken 'select()', but workable 'poll()'.  Use that */
116 #if HAVE_WORKING_POLL
117 #define USE_FUNC_POLL 1
118 #if HAVE_POLL_H
119 #include <poll.h>
120 #else
121 #include <sys/poll.h>
122 #endif
123 #else
124 #define USE_FUNC_POLL 0
125 #endif
126 
127 /* include signal.h before curses.h to work-around defect in glibc 2.1.3 */
128 #include <signal.h>
129 
130 /* Alessandro Rubini's GPM (general-purpose mouse) */
131 #if HAVE_LIBGPM && HAVE_GPM_H
132 #define USE_GPM_SUPPORT 1
133 #else
134 #define USE_GPM_SUPPORT 0
135 #endif
136 
137 /* QNX mouse support */
138 #if defined(__QNX__) && !defined(__QNXNTO__)
139 #define USE_QNX_MOUSE 1
140 #else
141 #define USE_QNX_MOUSE 0
142 #endif
143 
144 /* EMX mouse support */
145 #ifdef __EMX__
146 #define USE_EMX_MOUSE 1
147 #else
148 #define USE_EMX_MOUSE 0
149 #endif
150 
151 #define DEFAULT_MAXCLICK 166
152 #define EV_MAX		8	/* size of mouse circular event queue */
153 
154 /*
155  * If we don't have signals to support it, don't add a sigwinch handler.
156  * In any case, resizing is an extended feature.  Use it if we've got it.
157  */
158 #if !NCURSES_EXT_FUNCS
159 #undef HAVE_SIZECHANGE
160 #define HAVE_SIZECHANGE 0
161 #endif
162 
163 #if HAVE_SIZECHANGE && USE_SIGWINCH && defined(SIGWINCH)
164 #define USE_SIZECHANGE 1
165 #else
166 #define USE_SIZECHANGE 0
167 #undef USE_SIGWINCH
168 #define USE_SIGWINCH 0
169 #endif
170 
171 /*
172  * If desired, one can configure this, disabling environment variables that
173  * point to custom terminfo/termcap locations.
174  */
175 #ifdef USE_ROOT_ENVIRON
176 #ifdef __OpenBSD__
177 #define use_terminfo_vars() (!issetugid())
178 #else
179 #define use_terminfo_vars() 1
180 #endif
181 #else
182 #define use_terminfo_vars() _nc_env_access()
183 extern NCURSES_EXPORT(int) _nc_env_access (void);
184 #endif
185 
186 /*
187  * Not all platforms have memmove; some have an equivalent bcopy.  (Some may
188  * have neither).
189  */
190 #if USE_OK_BCOPY
191 #define memmove(d,s,n) bcopy(s,d,n)
192 #elif USE_MY_MEMMOVE
193 #define memmove(d,s,n) _nc_memmove(d,s,n)
194 extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t);
195 #endif
196 
197 /*
198  * Scroll hints are useless when hashmap is used
199  */
200 #if !USE_SCROLL_HINTS
201 #if !USE_HASHMAP
202 #define USE_SCROLL_HINTS 1
203 #else
204 #define USE_SCROLL_HINTS 0
205 #endif
206 #endif
207 
208 #if USE_SCROLL_HINTS
209 #define if_USE_SCROLL_HINTS(stmt) stmt
210 #else
211 #define if_USE_SCROLL_HINTS(stmt) /*nothing*/
212 #endif
213 
214 /*
215  * Note:  ht/cbt expansion flakes out randomly under Linux 1.1.47, but only
216  * when we're throwing control codes at the screen at high volume.  To see
217  * this, re-enable USE_HARD_TABS and run worm for a while.  Other systems
218  * probably don't want to define this either due to uncertainties about tab
219  * delays and expansion in raw mode.
220  */
221 
222 #define TRIES struct tries
223 typedef TRIES {
224 	TRIES    *child;            /* ptr to child.  NULL if none          */
225 	TRIES    *sibling;          /* ptr to sibling.  NULL if none        */
226 	unsigned char    ch;        /* character at this node               */
227 	unsigned short   value;     /* code of string so far.  0 if none.   */
228 #undef TRIES
229 } TRIES;
230 
231 /*
232  * Common/troublesome character definitions
233  */
234 #define StringOf(ch) {ch, 0}
235 
236 #define L_BRACE '{'
237 #define R_BRACE '}'
238 #define S_QUOTE '\''
239 #define D_QUOTE '"'
240 
241 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
242 
243 /*
244  * Structure for palette tables
245  */
246 
247 typedef struct
248 {
249     short red, green, blue;	/* what color_content() returns */
250     short r, g, b;		/* params to init_color() */
251     int init;			/* true if we called init_color() */
252 }
253 color_t;
254 
255 #define MAXCOLUMNS    135
256 #define MAXLINES      66
257 #define FIFO_SIZE     MAXCOLUMNS+2  /* for nocbreak mode input */
258 
259 #define ACS_LEN       128
260 
261 #define WINDOWLIST struct _win_list
262 
263 #if USE_WIDEC_SUPPORT
264 #define _nc_bkgd    _bkgrnd
265 #define _XOPEN_SOURCE_EXTENDED 1
266 #else
267 #undef _XOPEN_SOURCE_EXTENDED
268 #define _nc_bkgd    _bkgd
269 #define wgetbkgrnd(win, wch)	*wch = win->_bkgd
270 #define wbkgrnd	    wbkgd
271 #endif
272 
273 #undef NCURSES_OPAQUE
274 #define NCURSES_INTERNALS 1
275 #define NCURSES_OPAQUE 0
276 
277 #include <curses.h>	/* we'll use -Ipath directive to get the right one! */
278 #include <term.h>
279 #include <term_entry.h>
280 #include <nc_tparm.h>
281 
282 #if NCURSES_EXT_COLORS && USE_WIDEC_SUPPORT
283 #define if_EXT_COLORS(stmt)	stmt
284 #define NetPair(value,p)	(value).ext_color = (p), \
285 				AttrOf(value) &= ALL_BUT_COLOR, \
286 				AttrOf(value) |= (A_COLOR & COLOR_PAIR((p > 255) ? 255 : p))
287 #define SetPair(value,p)	(value).ext_color = (p)
288 #define GetPair(value)		(value).ext_color
289 #define unColor(n)		(AttrOf(n) & ALL_BUT_COLOR)
290 #define GET_WINDOW_PAIR(w)	(w)->_color
291 #define SET_WINDOW_PAIR(w,p)	(w)->_color = (p)
292 #define SameAttrOf(a,b)		(AttrOf(a) == AttrOf(b) && GetPair(a) == GetPair(b))
293 #define VIDATTR(attr, pair)	vid_attr(attr, pair, 0)
294 #else
295 #define if_EXT_COLORS(stmt)	/* nothing */
296 #define SetPair(value,p)	RemAttr(value, A_COLOR), \
297 				SetAttr(value, AttrOf(value) | (A_COLOR & COLOR_PAIR(p)))
298 #define GetPair(value)		PAIR_NUMBER(AttrOf(value))
299 #define unColor(n)		(AttrOf(n) & ALL_BUT_COLOR)
300 #define GET_WINDOW_PAIR(w)	PAIR_NUMBER(WINDOW_ATTRS(w))
301 #define SET_WINDOW_PAIR(w,p)	WINDOW_ATTRS(w) &= ALL_BUT_COLOR, \
302 				WINDOW_ATTRS(w) |= (A_COLOR & COLOR_PAIR(p))
303 #define SameAttrOf(a,b)		(AttrOf(a) == AttrOf(b))
304 #define VIDATTR(attr, pair)	vidattr(attr)
305 #endif
306 
307 #if NCURSES_NO_PADDING
308 #define GetNoPadding(sp)	((sp) ? (sp)->_no_padding : _nc_prescreen._no_padding)
309 #define SetNoPadding(sp)	_nc_set_no_padding(sp)
310 extern NCURSES_EXPORT(void) _nc_set_no_padding(SCREEN *);
311 #else
312 #define GetNoPadding(sp)	FALSE
313 #define SetNoPadding(sp)	/*nothing*/
314 #endif
315 
316 #define WINDOW_ATTRS(w)		((w)->_attrs)
317 
318 #define SCREEN_ATTRS(s)		(*((s)->_current_attr))
319 #define GET_SCREEN_PAIR(s)	GetPair(SCREEN_ATTRS(s))
320 #define SET_SCREEN_PAIR(s,p)	SetPair(SCREEN_ATTRS(s), p)
321 
322 #if USE_REENTRANT
323 NCURSES_EXPORT(int *) _nc_ptr_Lines (void);
324 NCURSES_EXPORT(int *) _nc_ptr_Cols (void);
325 #define ptrLines() (SP ? &(SP->_LINES) : &(_nc_prescreen._LINES))
326 #define ptrCols()  (SP ? &(SP->_COLS)  : &(_nc_prescreen._COLS))
327 #define SET_LINES(value) *_nc_ptr_Lines() = value
328 #define SET_COLS(value)  *_nc_ptr_Cols() = value
329 #else
330 #define ptrLines() &LINES
331 #define ptrCols()  &COLS
332 #define SET_LINES(value) LINES = value
333 #define SET_COLS(value)  COLS = value
334 #endif
335 
336 #define TR_MUTEX(data) _tracef("%s@%d: me:%08lX COUNT:%2u/%2d/%6d/%2d/%s%9u: " #data, \
337 	    __FILE__, __LINE__, \
338 	    (unsigned long) (pthread_self()), \
339 	    data.__data.__lock, \
340 	    data.__data.__count, \
341 	    data.__data.__owner, \
342 	    data.__data.__kind, \
343 	    (data.__data.__nusers > 5) ? " OOPS " : "", \
344 	    data.__data.__nusers)
345 #define TR_GLOBAL_MUTEX(name) TR_MUTEX(_nc_globals.mutex_##name)
346 
347 #ifdef USE_PTHREADS
348 
349 #if USE_REENTRANT
350 #include <pthread.h>
351 extern NCURSES_EXPORT(void) _nc_init_pthreads(void);
352 extern NCURSES_EXPORT(void) _nc_mutex_init(pthread_mutex_t *);
353 extern NCURSES_EXPORT(int) _nc_mutex_lock(pthread_mutex_t *);
354 extern NCURSES_EXPORT(int) _nc_mutex_trylock(pthread_mutex_t *);
355 extern NCURSES_EXPORT(int) _nc_mutex_unlock(pthread_mutex_t *);
356 #define _nc_lock_global(name)	_nc_mutex_lock(&_nc_globals.mutex_##name)
357 #define _nc_try_global(name)    _nc_mutex_trylock(&_nc_globals.mutex_##name)
358 #define _nc_unlock_global(name)	_nc_mutex_unlock(&_nc_globals.mutex_##name)
359 
360 #else
361 #error POSIX threads requires --enable-reentrant option
362 #endif
363 
364 #if USE_WEAK_SYMBOLS
365 #if defined(__GNUC__)
366 #  if defined __USE_ISOC99
367 #    define _cat_pragma(exp)	_Pragma(#exp)
368 #    define _weak_pragma(exp)	_cat_pragma(weak name)
369 #  else
370 #    define _weak_pragma(exp)
371 #  endif
372 #  define _declare(name)	__extension__ extern __typeof__(name) name
373 #  define weak_symbol(name)	_weak_pragma(name) _declare(name) __attribute__((weak))
374 #endif
375 #endif
376 
377 #ifdef USE_PTHREADS
378 #  if USE_WEAK_SYMBOLS
379 weak_symbol(pthread_sigmask);
380 weak_symbol(pthread_self);
381 weak_symbol(pthread_equal);
382 weak_symbol(pthread_mutex_init);
383 weak_symbol(pthread_mutex_lock);
384 weak_symbol(pthread_mutex_unlock);
385 weak_symbol(pthread_mutex_trylock);
386 weak_symbol(pthread_mutexattr_settype);
387 weak_symbol(pthread_mutexattr_init);
388 extern NCURSES_EXPORT(int) _nc_sigprocmask(int, const sigset_t *, sigset_t *);
389 #    undef  sigprocmask
390 #    define sigprocmask _nc_sigprocmask
391 #  endif
392 #endif
393 
394 #if HAVE_NANOSLEEP
395 #undef HAVE_NANOSLEEP
396 #define HAVE_NANOSLEEP 0	/* nanosleep suspends all threads */
397 #endif
398 
399 #else /* !USE_PTHREADS */
400 
401 #define _nc_init_pthreads()	/* nothing */
402 #define _nc_mutex_init(obj)	/* nothing */
403 
404 #define _nc_lock_global(name)	/* nothing */
405 #define _nc_try_global(name)    0
406 #define _nc_unlock_global(name)	/* nothing */
407 
408 #endif /* USE_PTHREADS */
409 
410 #if HAVE_GETTIMEOFDAY
411 # define PRECISE_GETTIME 1
412 # define TimeType struct timeval
413 #else
414 # define PRECISE_GETTIME 0
415 # define TimeType time_t
416 #endif
417 
418 /*
419  * Definitions for color pairs
420  */
421 typedef unsigned colorpair_t;	/* type big enough to store PAIR_OF() */
422 #define C_SHIFT 9		/* we need more bits than there are colors */
423 #define C_MASK			((1 << C_SHIFT) - 1)
424 #define PAIR_OF(fg, bg)		((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK))
425 #define isDefaultColor(c)	((c) >= COLOR_DEFAULT || (c) < 0)
426 
427 #define COLOR_DEFAULT		C_MASK
428 
429 #if defined(USE_TERMLIB) && !defined(NEED_NCURSES_CH_T)
430 
431 #undef NCURSES_CH_T		/* this is not a termlib feature */
432 #define NCURSES_CH_T void	/* ...but we need a pointer in SCREEN */
433 
434 #endif	/* USE_TERMLIB */
435 
436 #ifndef USE_TERMLIB
437 struct ldat
438 {
439 	NCURSES_CH_T	*text;		/* text of the line */
440 	NCURSES_SIZE_T	firstchar;	/* first changed character in the line */
441 	NCURSES_SIZE_T	lastchar;	/* last changed character in the line */
442 	NCURSES_SIZE_T	oldindex;	/* index of the line at last update */
443 };
444 #endif	/* USE_TERMLIB */
445 
446 typedef enum {
447 	M_XTERM	= -1		/* use xterm's mouse tracking? */
448 	,M_NONE = 0		/* no mouse device */
449 #if USE_GPM_SUPPORT
450 	,M_GPM			/* use GPM */
451 #endif
452 #if USE_SYSMOUSE
453 	,M_SYSMOUSE		/* FreeBSD sysmouse on console */
454 #endif
455 } MouseType;
456 
457 /*
458  * Structures for scrolling.
459  */
460 
461 typedef struct {
462 	unsigned long hashval;
463 	int oldcount, newcount;
464 	int oldindex, newindex;
465 } HASHMAP;
466 
467 /*
468  * Structures for soft labels.
469  */
470 
471 struct _SLK;
472 
473 #ifndef USE_TERMLIB
474 
475 typedef struct
476 {
477 	char *ent_text;		/* text for the label */
478 	char *form_text;	/* formatted text (left/center/...) */
479 	int ent_x;		/* x coordinate of this field */
480 	char dirty;		/* this label has changed */
481 	char visible;		/* field is visible */
482 } slk_ent;
483 
484 typedef struct _SLK {
485 	char dirty;		/* all labels have changed */
486 	char hidden;		/* soft labels are hidden */
487 	WINDOW *win;
488 	slk_ent *ent;
489 	short  maxlab;		/* number of available labels */
490 	short  labcnt;		/* number of allocated labels */
491 	short  maxlen;		/* length of labels */
492 	NCURSES_CH_T attr;	/* soft label attribute */
493 } SLK;
494 
495 #endif	/* USE_TERMLIB */
496 
497 typedef	struct {
498 	WINDOW *win;		/* the window used in the hook      */
499 	int	line;		/* lines to take, < 0 => from bottom*/
500 	int	(*hook)(WINDOW *, int); /* callback for user	    */
501 } ripoff_t;
502 
503 #if USE_GPM_SUPPORT
504 #undef buttons			/* term.h defines this, and gpm uses it! */
505 #include <gpm.h>
506 
507 #ifdef HAVE_LIBDL
508 /* link dynamically to GPM */
509 typedef int *TYPE_gpm_fd;
510 typedef int (*TYPE_Gpm_Open) (Gpm_Connect *, int);
511 typedef int (*TYPE_Gpm_Close) (void);
512 typedef int (*TYPE_Gpm_GetEvent) (Gpm_Event *);
513 
514 #define my_gpm_fd       SP->_mouse_gpm_fd
515 #define my_Gpm_Open     SP->_mouse_Gpm_Open
516 #define my_Gpm_Close    SP->_mouse_Gpm_Close
517 #define my_Gpm_GetEvent SP->_mouse_Gpm_GetEvent
518 #else
519 /* link statically to GPM */
520 #define my_gpm_fd       &gpm_fd
521 #define my_Gpm_Open     Gpm_Open
522 #define my_Gpm_Close    Gpm_Close
523 #define my_Gpm_GetEvent Gpm_GetEvent
524 #endif /* HAVE_LIBDL */
525 #endif /* USE_GPM_SUPPORT */
526 
527 typedef struct {
528     long sequence;
529     bool last_used;
530     char *fix_sgr0;		/* this holds the filtered sgr0 string */
531     char *last_bufp;		/* help with fix_sgr0 leak */
532     TERMINAL *last_term;
533 } TGETENT_CACHE;
534 
535 #define TGETENT_MAX 4
536 
537 /*
538  * State of tparm().
539  */
540 #define STACKSIZE 20
541 
542 typedef struct {
543 	union {
544 		int	num;
545 		char	*str;
546 	} data;
547 	bool num_type;
548 } STACK_FRAME;
549 
550 #define NUM_VARS 26
551 
552 typedef struct {
553 #ifdef TRACE
554 	const char	*tname;
555 #endif
556 	const char	*tparam_base;
557 
558 	STACK_FRAME	stack[STACKSIZE];
559 	int		stack_ptr;
560 
561 	char		*out_buff;
562 	size_t		out_size;
563 	size_t		out_used;
564 
565 	char		*fmt_buff;
566 	size_t		fmt_size;
567 
568 	int		dynamic_var[NUM_VARS];
569 	int		static_vars[NUM_VARS];
570 } TPARM_STATE;
571 
572 typedef struct {
573     char *text;
574     size_t size;
575 } TRACEBUF;
576 
577 /*
578  * The filesystem database normally uses a single-letter for the lower level
579  * of directories.  Use a hexadecimal code for filesystems which do not
580  * preserve mixed-case names.
581  */
582 #if MIXEDCASE_FILENAMES
583 #define LEAF_FMT "%c"
584 #else
585 #define LEAF_FMT "%02x"
586 #endif
587 
588 /*
589  * TRACEMSE_FMT is no longer than 80 columns, there are 5 numbers that
590  * could at most have 10 digits, and the mask contains no more than 32 bits
591  * with each bit representing less than 15 characters.  Usually the whole
592  * string is less than 80 columns, but this buffer size is an absolute
593  * limit.
594  */
595 #define TRACEMSE_MAX	(80 + (5 * 10) + (32 * 15))
596 #define TRACEMSE_FMT	"id %2d  at (%2d, %2d, %2d) state %4lx = {" /* } */
597 
598 /*
599  * Global data which is not specific to a screen.
600  */
601 typedef struct {
602 	SIG_ATOMIC_T	have_sigwinch;
603 	SIG_ATOMIC_T	cleanup_nested;
604 
605 	bool		init_signals;
606 	bool		init_screen;
607 
608 	const char	*comp_sourcename;
609 	char		*comp_termtype;
610 
611 	bool		have_tic_directory;
612 	bool		keep_tic_directory;
613 	const char	*tic_directory;
614 
615 	char		*dbi_list;
616 	int		dbi_size;
617 
618 	char		*first_name;
619 	char		**keyname_table;
620 
621 	int		slk_format;
622 
623 	char		*safeprint_buf;
624 	size_t		safeprint_used;
625 
626 	TGETENT_CACHE	tgetent_cache[TGETENT_MAX];
627 	int		tgetent_index;
628 	long		tgetent_sequence;
629 
630 	WINDOWLIST	*_nc_windowlist;
631 #define _nc_windows	_nc_globals._nc_windowlist
632 
633 #if USE_HOME_TERMINFO
634 	char		*home_terminfo;
635 #endif
636 
637 #if !USE_SAFE_SPRINTF
638 	int		safeprint_cols;
639 	int		safeprint_rows;
640 #endif
641 
642 #ifdef TRACE
643 	bool		init_trace;
644 	char		trace_fname[PATH_MAX];
645 	int		trace_level;
646 	FILE		*trace_fp;
647 
648 	char		*tracearg_buf;
649 	size_t		tracearg_used;
650 
651 	TRACEBUF	*tracebuf_ptr;
652 	size_t		tracebuf_used;
653 
654 	char		tracechr_buf[40];
655 
656 	char		*tracedmp_buf;
657 	size_t		tracedmp_used;
658 
659 	unsigned char	*tracetry_buf;
660 	size_t		tracetry_used;
661 
662 #define _nc_globals_traceatr_color_buf_size 80
663 	char		traceatr_color_buf[2][_nc_globals_traceatr_color_buf_size];
664 	int		traceatr_color_sel;
665 	int		traceatr_color_last;
666 
667 #endif	/* TRACE */
668 
669 #ifdef USE_PTHREADS
670 	pthread_mutex_t	mutex_curses;
671 	pthread_mutex_t	mutex_tst_tracef;
672 	pthread_mutex_t	mutex_tracef;
673 	int		nested_tracef;
674 	int		use_pthreads;
675 #define _nc_use_pthreads	_nc_globals.use_pthreads
676 #endif
677 } NCURSES_GLOBALS;
678 
679 extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals;
680 
681 #define N_RIPS 5
682 
683 /*
684  * Global data which can be swept up into a SCREEN when one is created.
685  * It may be modified before the next SCREEN is created.
686  */
687 typedef struct {
688 	bool		use_env;
689 	bool		filter_mode;
690 	attr_t		previous_attr;
691 	ripoff_t	rippedoff[N_RIPS];
692 	ripoff_t	*rsp;
693 	TPARM_STATE	tparm_state;
694 	TTY		*saved_tty;	/* savetty/resetty information	    */
695 #if NCURSES_NO_PADDING
696 	bool		_no_padding;	/* flag to set if padding disabled  */
697 #endif
698 #if BROKEN_LINKER || USE_REENTRANT
699 	chtype		*real_acs_map;
700 	int		_LINES;
701 	int		_COLS;
702 	TERMINAL	*_cur_term;
703 #ifdef TRACE
704 	long		_outchars;
705 	const char	*_tputs_trace;
706 #endif
707 #endif
708 } NCURSES_PRESCREEN;
709 
710 #define ripoff_sp	_nc_prescreen.rsp
711 #define ripoff_stack	_nc_prescreen.rippedoff
712 
713 extern NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen;
714 
715 /*
716  * The SCREEN structure.
717  */
718 
719 struct screen {
720 	int		_ifd;		/* input file ptr for screen	    */
721 	FILE		*_ofp;		/* output file ptr for screen	    */
722 	char		*_setbuf;	/* buffered I/O for output	    */
723 	bool		_filtered;	/* filter() was called		    */
724 	bool		_buffered;	/* setvbuf uses _setbuf data	    */
725 	int		_checkfd;	/* filedesc for typeahead check	    */
726 	TERMINAL	*_term;		/* terminal type information	    */
727 	TTY		_saved_tty;	/* savetty/resetty information	    */
728 	NCURSES_SIZE_T	_lines;		/* screen lines			    */
729 	NCURSES_SIZE_T	_columns;	/* screen columns		    */
730 
731 	NCURSES_SIZE_T	_lines_avail;	/* lines available for stdscr	    */
732 	NCURSES_SIZE_T	_topstolen;	/* lines stolen from top	    */
733 
734 	WINDOW		*_curscr;	/* current screen		    */
735 	WINDOW		*_newscr;	/* virtual screen to be updated to  */
736 	WINDOW		*_stdscr;	/* screen's full-window context	    */
737 
738 	TRIES		*_keytry;	/* "Try" for use with keypad mode   */
739 	TRIES		*_key_ok;	/* Disabled keys via keyok(,FALSE)  */
740 	bool		_tried;		/* keypad mode was initialized	    */
741 	bool		_keypad_on;	/* keypad mode is currently on	    */
742 
743 	bool		_called_wgetch;	/* check for recursion in wgetch()  */
744 	int		_fifo[FIFO_SIZE];	/* input push-back buffer   */
745 	short		_fifohead,	/* head of fifo queue		    */
746 			_fifotail,	/* tail of fifo queue		    */
747 			_fifopeek,	/* where to peek for next char	    */
748 			_fifohold;	/* set if breakout marked	    */
749 
750 	int		_endwin;	/* are we out of window mode?	    */
751 	NCURSES_CH_T	*_current_attr; /* holds current attributes set	    */
752 	int		_coloron;	/* is color enabled?		    */
753 	int		_color_defs;	/* are colors modified		    */
754 	int		_cursor;	/* visibility of the cursor	    */
755 	int		_cursrow;	/* physical cursor row		    */
756 	int		_curscol;	/* physical cursor column	    */
757 	bool		_notty;		/* true if we cannot switch non-tty */
758 	int		_nl;		/* True if NL -> CR/NL is on	    */
759 	int		_raw;		/* True if in raw mode		    */
760 	int		_cbreak;	/* 1 if in cbreak mode		    */
761 					/* > 1 if in halfdelay mode	    */
762 	int		_echo;		/* True if echo on		    */
763 	int		_use_meta;	/* use the meta key?		    */
764 	struct _SLK	*_slk;		/* ptr to soft key struct / NULL    */
765 	int		slk_format;	/* selected format for this screen  */
766 	/* cursor movement costs; units are 10ths of milliseconds */
767 #if NCURSES_NO_PADDING
768 	bool		_no_padding;	/* flag to set if padding disabled  */
769 #endif
770 	int		_char_padding;	/* cost of character put	    */
771 	int		_cr_cost;	/* cost of (carriage_return)	    */
772 	int		_cup_cost;	/* cost of (cursor_address)	    */
773 	int		_home_cost;	/* cost of (cursor_home)	    */
774 	int		_ll_cost;	/* cost of (cursor_to_ll)	    */
775 #if USE_HARD_TABS
776 	int		_ht_cost;	/* cost of (tab)		    */
777 	int		_cbt_cost;	/* cost of (backtab)		    */
778 #endif /* USE_HARD_TABS */
779 	int		_cub1_cost;	/* cost of (cursor_left)	    */
780 	int		_cuf1_cost;	/* cost of (cursor_right)	    */
781 	int		_cud1_cost;	/* cost of (cursor_down)	    */
782 	int		_cuu1_cost;	/* cost of (cursor_up)		    */
783 	int		_cub_cost;	/* cost of (parm_cursor_left)	    */
784 	int		_cuf_cost;	/* cost of (parm_cursor_right)	    */
785 	int		_cud_cost;	/* cost of (parm_cursor_down)	    */
786 	int		_cuu_cost;	/* cost of (parm_cursor_up)	    */
787 	int		_hpa_cost;	/* cost of (column_address)	    */
788 	int		_vpa_cost;	/* cost of (row_address)	    */
789 	/* used in tty_update.c, must be chars */
790 	int		_ed_cost;	/* cost of (clr_eos)		    */
791 	int		_el_cost;	/* cost of (clr_eol)		    */
792 	int		_el1_cost;	/* cost of (clr_bol)		    */
793 	int		_dch1_cost;	/* cost of (delete_character)	    */
794 	int		_ich1_cost;	/* cost of (insert_character)	    */
795 	int		_dch_cost;	/* cost of (parm_dch)		    */
796 	int		_ich_cost;	/* cost of (parm_ich)		    */
797 	int		_ech_cost;	/* cost of (erase_chars)	    */
798 	int		_rep_cost;	/* cost of (repeat_char)	    */
799 	int		_hpa_ch_cost;	/* cost of (column_address)	    */
800 	int		_cup_ch_cost;	/* cost of (cursor_address)	    */
801 	int		_cuf_ch_cost;	/* cost of (parm_cursor_right)	    */
802 	int		_inline_cost;	/* cost of inline-move		    */
803 	int		_smir_cost;	/* cost of (enter_insert_mode)	    */
804 	int		_rmir_cost;	/* cost of (exit_insert_mode)	    */
805 	int		_ip_cost;	/* cost of (insert_padding)	    */
806 	/* used in lib_mvcur.c */
807 	char *		_address_cursor;
808 	/* used in tty_update.c */
809 	int		_scrolling;	/* 1 if terminal's smart enough to  */
810 
811 	/* used in lib_color.c */
812 	color_t		*_color_table;	/* screen's color palette	     */
813 	int		_color_count;	/* count of colors in palette	     */
814 	colorpair_t	*_color_pairs;	/* screen's color pair list	     */
815 	int		_pair_count;	/* count of color pairs		     */
816 #if NCURSES_EXT_FUNCS
817 	bool		_default_color; /* use default colors		     */
818 	bool		_has_sgr_39_49; /* has ECMA default color support    */
819 	int		_default_fg;	/* assumed default foreground	     */
820 	int		_default_bg;	/* assumed default background	     */
821 #endif
822 	chtype		_ok_attributes; /* valid attributes for terminal     */
823 	chtype		_xmc_suppress;	/* attributes to suppress if xmc     */
824 	chtype		_xmc_triggers;	/* attributes to process if xmc	     */
825 	chtype *	_acs_map;	/* the real alternate-charset map    */
826 	bool *		_screen_acs_map;
827 
828 
829 	/* used in lib_vidattr.c */
830 	bool		_use_rmso;	/* true if we may use 'rmso'	     */
831 	bool		_use_rmul;	/* true if we may use 'rmul'	     */
832 
833 	/*
834 	 * These data correspond to the state of the idcok() and idlok()
835 	 * functions.  A caveat is in order here:  the XSI and SVr4
836 	 * documentation specify that these functions apply to the window which
837 	 * is given as an argument.  However, ncurses implements this logic
838 	 * only for the newscr/curscr update process, _not_ per-window.
839 	 */
840 	bool		_nc_sp_idlok;
841 	bool		_nc_sp_idcok;
842 #define _nc_idlok SP->_nc_sp_idlok
843 #define _nc_idcok SP->_nc_sp_idcok
844 
845 	/*
846 	 * These are the data that support the mouse interface.
847 	 */
848 	bool		_mouse_initialized;
849 	MouseType	_mouse_type;
850 	int		_maxclick;
851 	bool		(*_mouse_event) (SCREEN *);
852 	bool		(*_mouse_inline)(SCREEN *);
853 	bool		(*_mouse_parse) (SCREEN *, int);
854 	void		(*_mouse_resume)(SCREEN *);
855 	void		(*_mouse_wrap)	(SCREEN *);
856 	int		_mouse_fd;	/* file-descriptor, if any */
857 	bool		_mouse_active;	/* true if initialized */
858 	mmask_t		_mouse_mask;
859 	NCURSES_CONST char *_mouse_xtermcap; /* string to enable/disable mouse */
860 	MEVENT		_mouse_events[EV_MAX];	/* hold the last mouse event seen */
861 	MEVENT		*_mouse_eventp;	/* next free slot in event queue */
862 
863 #if USE_GPM_SUPPORT
864 	bool		_mouse_gpm_loaded;
865 	bool		_mouse_gpm_found;
866 #ifdef HAVE_LIBDL
867 	void		*_dlopen_gpm;
868 	TYPE_gpm_fd	_mouse_gpm_fd;
869 	TYPE_Gpm_Open	_mouse_Gpm_Open;
870 	TYPE_Gpm_Close	_mouse_Gpm_Close;
871 	TYPE_Gpm_GetEvent _mouse_Gpm_GetEvent;
872 #endif
873 	Gpm_Connect	_mouse_gpm_connect;
874 #endif /* USE_GPM_SUPPORT */
875 
876 #if USE_EMX_MOUSE
877 	int		_emxmouse_wfd;
878 	int		_emxmouse_thread;
879 	int		_emxmouse_activated;
880 	char		_emxmouse_buttons[4];
881 #endif
882 
883 #if USE_SYSMOUSE
884 	MEVENT		_sysmouse_fifo[FIFO_SIZE];
885 	int		_sysmouse_head;
886 	int		_sysmouse_tail;
887 	int		_sysmouse_char_width;	/* character width */
888 	int		_sysmouse_char_height;	/* character height */
889 	int		_sysmouse_old_buttons;
890 	int		_sysmouse_new_buttons;
891 #endif
892 
893 	/*
894 	 * This supports automatic resizing
895 	 */
896 #if USE_SIZECHANGE
897 	int		(*_resize)(int,int);
898 	int		(*_ungetch)(SCREEN *, int);
899 #endif
900 
901 	/*
902 	 * These are data that support the proper handling of the panel stack on an
903 	 * per screen basis.
904 	 */
905 	struct panelhook _panelHook;
906 
907 	bool		_sig_winch;
908 	SCREEN		*_next_screen;
909 
910 	/* hashes for old and new lines */
911 	unsigned long	*oldhash, *newhash;
912 	HASHMAP		*hashtab;
913 	int		hashtab_len;
914 	int		*_oldnum_list;
915 	int		_oldnum_size;
916 
917 	bool		_cleanup;	/* cleanup after int/quit signal */
918 	int		(*_outch)(int); /* output handler if not putc */
919 
920 	int		_legacy_coding;	/* see use_legacy_coding() */
921 
922 #if USE_REENTRANT
923 	char		_ttytype[NAMESIZE];
924 	int		_ESCDELAY;
925 	int		_TABSIZE;
926 	int		_LINES;
927 	int		_COLS;
928 #ifdef TRACE
929 	long		_outchars;
930 	const char	*_tputs_trace;
931 #endif
932 #endif
933 
934 #ifdef TRACE
935 #define _nc_screen_tracechr_buf_size 40
936 	char		tracechr_buf[_nc_screen_tracechr_buf_size];
937 	char		tracemse_buf[TRACEMSE_MAX];
938 #endif
939 	/*
940 	 * ncurses/ncursesw are the same up to this point.
941 	 */
942 #if USE_WIDEC_SUPPORT
943 	/* recent versions of 'screen' have partially-working support for
944 	 * UTF-8, but do not permit ACS at the same time (see tty_update.c).
945 	 */
946 	bool		_screen_acs_fix;
947 #endif
948 };
949 
950 extern NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain;
951 extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
952 
953 	WINDOWLIST {
954 	WINDOW	win;		/* first, so WINDOW_EXT() works */
955 	WINDOWLIST *next;
956 	SCREEN *screen;		/* screen containing the window */
957 #ifdef _XOPEN_SOURCE_EXTENDED
958 	char addch_work[(MB_LEN_MAX * 9) + 1];
959 	unsigned addch_used;	/* number of bytes in addch_work[] */
960 	int addch_x;		/* x-position for addch_work[] */
961 	int addch_y;		/* y-position for addch_work[] */
962 #endif
963 };
964 
965 #define WINDOW_EXT(win,field) (((WINDOWLIST *)(win))->field)
966 
967 /* usually in <limits.h> */
968 #ifndef UCHAR_MAX
969 #define UCHAR_MAX 255
970 #endif
971 
972 /* The terminfo source is assumed to be 7-bit ASCII */
973 #define is7bits(c)	((unsigned)(c) < 128)
974 
975 /* Checks for isprint() should be done on 8-bit characters (non-wide) */
976 #define is8bits(c)	((unsigned)(c) <= UCHAR_MAX)
977 
978 #ifndef min
979 #define min(a,b)	((a) > (b)  ?  (b)  :  (a))
980 #endif
981 
982 #ifndef max
983 #define max(a,b)	((a) < (b)  ?  (b)  :  (a))
984 #endif
985 
986 /* usually in <unistd.h> */
987 #ifndef STDIN_FILENO
988 #define STDIN_FILENO 0
989 #endif
990 
991 #ifndef STDOUT_FILENO
992 #define STDOUT_FILENO 1
993 #endif
994 
995 #ifndef STDERR_FILENO
996 #define STDERR_FILENO 2
997 #endif
998 
999 #ifndef EXIT_SUCCESS
1000 #define EXIT_SUCCESS 0
1001 #endif
1002 
1003 #ifndef EXIT_FAILURE
1004 #define EXIT_FAILURE 1
1005 #endif
1006 
1007 #ifndef R_OK
1008 #define	R_OK	4		/* Test for read permission.  */
1009 #endif
1010 #ifndef W_OK
1011 #define	W_OK	2		/* Test for write permission.  */
1012 #endif
1013 #ifndef X_OK
1014 #define	X_OK	1		/* Test for execute permission.  */
1015 #endif
1016 #ifndef F_OK
1017 #define	F_OK	0		/* Test for existence.  */
1018 #endif
1019 
1020 #if HAVE_FCNTL_H
1021 #include <fcntl.h>		/* may define O_BINARY	*/
1022 #endif
1023 
1024 #ifndef O_BINARY
1025 #define O_BINARY 0
1026 #endif
1027 
1028 #ifdef TRACE
1029 #if USE_REENTRANT
1030 #define COUNT_OUTCHARS(n) _nc_count_outchars(n);
1031 #else
1032 #define COUNT_OUTCHARS(n) _nc_outchars += (n);
1033 #endif
1034 #else
1035 #define COUNT_OUTCHARS(n) /* nothing */
1036 #endif
1037 
1038 #define RESET_OUTCHARS() COUNT_OUTCHARS(-_nc_outchars)
1039 
1040 #define UChar(c)	((unsigned char)(c))
1041 #define ChCharOf(c)	((c) & (chtype)A_CHARTEXT)
1042 #define ChAttrOf(c)	((c) & (chtype)A_ATTRIBUTES)
1043 
1044 #ifndef MB_LEN_MAX
1045 #define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */
1046 #endif
1047 
1048 #if USE_WIDEC_SUPPORT /* { */
1049 #define isEILSEQ(status) (((size_t)status == (size_t)-1) && (errno == EILSEQ))
1050 
1051 #define init_mb(state)	memset(&state, 0, sizeof(state))
1052 
1053 #if NCURSES_EXT_COLORS
1054 #define NulColor	, 0
1055 #else
1056 #define NulColor	/* nothing */
1057 #endif
1058 
1059 #define NulChar		0,0,0,0	/* FIXME: see CCHARW_MAX */
1060 #define CharOf(c)	((c).chars[0])
1061 #define AttrOf(c)	((c).attr)
1062 
1063 #define AddAttr(c,a)	AttrOf(c) |=  ((a) & A_ATTRIBUTES)
1064 #define RemAttr(c,a)	AttrOf(c) &= ~((a) & A_ATTRIBUTES)
1065 #define SetAttr(c,a)	AttrOf(c) =   ((a) & A_ATTRIBUTES) | WidecExt(c)
1066 
1067 #define NewChar2(c,a)	{ a, { c, NulChar } NulColor }
1068 #define NewChar(ch)	NewChar2(ChCharOf(ch), ChAttrOf(ch))
1069 
1070 #if CCHARW_MAX == 5
1071 #define CharEq(a,b)	(((a).attr == (b).attr) \
1072 		       && (a).chars[0] == (b).chars[0] \
1073 		       && (a).chars[1] == (b).chars[1] \
1074 		       && (a).chars[2] == (b).chars[2] \
1075 		       && (a).chars[3] == (b).chars[3] \
1076 		       && (a).chars[4] == (b).chars[4] \
1077 			if_EXT_COLORS(&& (a).ext_color == (b).ext_color))
1078 #else
1079 #define CharEq(a,b)	(!memcmp(&(a), &(b), sizeof(a)))
1080 #endif
1081 
1082 #define SetChar(ch,c,a) do {							    \
1083 			    NCURSES_CH_T *_cp = &ch;				    \
1084 			    memset(_cp, 0, sizeof(ch));				    \
1085 			    _cp->chars[0] = (c);					    \
1086 			    _cp->attr = (a);					    \
1087 			    if_EXT_COLORS(SetPair(ch, PAIR_NUMBER(a)));		    \
1088 			} while (0)
1089 #define CHREF(wch)	(&wch)
1090 #define CHDEREF(wch)	(*wch)
1091 #define ARG_CH_T	NCURSES_CH_T *
1092 #define CARG_CH_T	const NCURSES_CH_T *
1093 #define PUTC_DATA	char PUTC_buf[MB_LEN_MAX]; int PUTC_i, PUTC_n; \
1094 			mbstate_t PUT_st; wchar_t PUTC_ch
1095 #define PUTC_INIT	init_mb (PUT_st)
1096 #define PUTC(ch,b)	do { if(!isWidecExt(ch)) {				    \
1097 			if (Charable(ch)) {					    \
1098 			    fputc(CharOf(ch), b);				    \
1099 			    COUNT_OUTCHARS(1);					    \
1100 			} else {						    \
1101 			    PUTC_INIT;						    \
1102 			    for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {	    \
1103 				PUTC_ch = (ch).chars[PUTC_i];			    \
1104 				if (PUTC_ch == L'\0')				    \
1105 				    break;					    \
1106 				PUTC_n = wcrtomb(PUTC_buf,			    \
1107 						 (ch).chars[PUTC_i], &PUT_st);	    \
1108 				if (PUTC_n <= 0) {				    \
1109 				    if (PUTC_ch && is8bits(PUTC_ch) && PUTC_i == 0) \
1110 					putc(PUTC_ch,b);			    \
1111 				    break;					    \
1112 				}						    \
1113 				fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b);	    \
1114 			    }							    \
1115 			    COUNT_OUTCHARS(PUTC_i);				    \
1116 			} } } while (0)
1117 
1118 #define BLANK		NewChar2(' ', WA_NORMAL)
1119 #define ZEROS		NewChar2('\0', WA_NORMAL)
1120 #define ISBLANK(ch)	((ch).chars[0] == L' ' && (ch).chars[1] == L'\0')
1121 
1122 	/*
1123 	 * Wide characters cannot be represented in the A_CHARTEXT mask of
1124 	 * attr_t's but an application might have set a narrow character there.
1125 	 * But even in that case, it would only be a printable character, or
1126 	 * zero.  Otherwise we can use those bits to tell if a cell is the
1127 	 * first or extension part of a wide character.
1128 	 */
1129 #define WidecExt(ch)	(AttrOf(ch) & A_CHARTEXT)
1130 #define isWidecBase(ch)	(WidecExt(ch) == 1)
1131 #define isWidecExt(ch)	(WidecExt(ch) > 1 && WidecExt(ch) < 32)
1132 #define SetWidecExt(dst, ext)	AttrOf(dst) &= ~A_CHARTEXT,		\
1133 				AttrOf(dst) |= (ext + 1)
1134 
1135 #define if_WIDEC(code)  code
1136 #define Charable(ch)	((SP != 0 && SP->_legacy_coding)		\
1137 			 || (AttrOf(ch) & A_ALTCHARSET)			\
1138 			 || (!isWidecExt(ch) &&				\
1139 			     (ch).chars[1] == L'\0' &&			\
1140 			     _nc_is_charable(CharOf(ch))))
1141 
1142 #define L(ch)		L ## ch
1143 #else /* }{ */
1144 #define CharOf(c)	ChCharOf(c)
1145 #define AttrOf(c)	ChAttrOf(c)
1146 #define AddAttr(c,a)	c |= (a)
1147 #define RemAttr(c,a)	c &= ~((a) & A_ATTRIBUTES)
1148 #define SetAttr(c,a)	c = ((c) & ~A_ATTRIBUTES) | (a)
1149 #define NewChar(ch)	(ch)
1150 #define NewChar2(c,a)	((c) | (a))
1151 #define CharEq(a,b)	((a) == (b))
1152 #define SetChar(ch,c,a)	ch = (c) | (a)
1153 #define CHREF(wch)	wch
1154 #define CHDEREF(wch)	wch
1155 #define ARG_CH_T	NCURSES_CH_T
1156 #define CARG_CH_T	NCURSES_CH_T
1157 #define PUTC_DATA	int data = 0
1158 #define PUTC(ch,b)	do { data = CharOf(ch); putc(data,b); } while (0)
1159 
1160 #define BLANK		(' '|A_NORMAL)
1161 #define ZEROS		('\0'|A_NORMAL)
1162 #define ISBLANK(ch)	(CharOf(ch) == ' ')
1163 
1164 #define isWidecExt(ch)	(0)
1165 #define if_WIDEC(code) /* nothing */
1166 
1167 #define L(ch)		ch
1168 #endif /* } */
1169 
1170 #define AttrOfD(ch)	AttrOf(CHDEREF(ch))
1171 #define CharOfD(ch)	CharOf(CHDEREF(ch))
1172 #define SetChar2(wch,ch)    SetChar(wch,ChCharOf(ch),ChAttrOf(ch))
1173 
1174 #define BLANK_ATTR	A_NORMAL
1175 #define BLANK_TEXT	L(' ')
1176 
1177 #define CHANGED     -1
1178 
1179 #define LEGALYX(w, y, x) \
1180 	      ((w) != 0 && \
1181 		((x) >= 0 && (x) <= (w)->_maxx && \
1182 		 (y) >= 0 && (y) <= (w)->_maxy))
1183 
1184 #define CHANGED_CELL(line,col) \
1185 	if (line->firstchar == _NOCHANGE) \
1186 		line->firstchar = line->lastchar = col; \
1187 	else if ((col) < line->firstchar) \
1188 		line->firstchar = col; \
1189 	else if ((col) > line->lastchar) \
1190 		line->lastchar = col
1191 
1192 #define CHANGED_RANGE(line,start,end) \
1193 	if (line->firstchar == _NOCHANGE \
1194 	 || line->firstchar > (start)) \
1195 		line->firstchar = start; \
1196 	if (line->lastchar == _NOCHANGE \
1197 	 || line->lastchar < (end)) \
1198 		line->lastchar = end
1199 
1200 #define CHANGED_TO_EOL(line,start,end) \
1201 	if (line->firstchar == _NOCHANGE \
1202 	 || line->firstchar > (start)) \
1203 		line->firstchar = start; \
1204 	line->lastchar = end
1205 
1206 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
1207 
1208 #define FreeIfNeeded(p)  if ((p) != 0) free(p)
1209 
1210 /* FreeAndNull() is not a comma-separated expression because some compilers
1211  * do not accept a mixture of void with values.
1212  */
1213 #define FreeAndNull(p)   free(p); p = 0
1214 
1215 #include <nc_alloc.h>
1216 
1217 /*
1218  * TTY bit definition for converting tabs to spaces.
1219  */
1220 #ifdef TAB3
1221 # define OFLAGS_TABS TAB3	/* POSIX specifies TAB3 */
1222 #else
1223 # ifdef XTABS
1224 #  define OFLAGS_TABS XTABS	/* XTABS is usually the "same" */
1225 # else
1226 #  ifdef OXTABS
1227 #   define OFLAGS_TABS OXTABS	/* the traditional BSD equivalent */
1228 #  else
1229 #   define OFLAGS_TABS 0
1230 #  endif
1231 # endif
1232 #endif
1233 
1234 /*
1235  * Standardize/simplify common loops
1236  */
1237 #define each_screen(p) p = _nc_screen_chain; p != 0; p = (p)->_next_screen
1238 #define each_window(p) p = _nc_windows; p != 0; p = (p)->next
1239 #define each_ripoff(p) p = ripoff_stack; (p - ripoff_stack) < N_RIPS; ++p
1240 
1241 /*
1242  * Prefixes for call/return points of library function traces.  We use these to
1243  * instrument the public functions so that the traces can be easily transformed
1244  * into regression scripts.
1245  */
1246 #define T_CALLED(fmt) "called {" fmt
1247 #define T_CREATE(fmt) "create :" fmt
1248 #define T_RETURN(fmt) "return }" fmt
1249 
1250 #ifdef TRACE
1251 
1252 #if USE_REENTRANT
1253 #define TPUTS_TRACE(s)	_nc_set_tputs_trace(s);
1254 #else
1255 #define TPUTS_TRACE(s)	_nc_tputs_trace = s;
1256 #endif
1257 
1258 #define START_TRACE() \
1259 	if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
1260 	    int t = _nc_getenv_num("NCURSES_TRACE"); \
1261 	    if (t >= 0) \
1262 		trace((unsigned) t); \
1263 	}
1264 
1265 /*
1266  * Many of the _tracef() calls use static buffers; lock the trace state before
1267  * trying to fill them.
1268  */
1269 #if USE_REENTRANT
1270 #define USE_TRACEF(mask) _nc_use_tracef(mask)
1271 extern NCURSES_EXPORT(int)	_nc_use_tracef (unsigned);
1272 extern NCURSES_EXPORT(void)	_nc_locked_tracef (const char *, ...) GCC_PRINTFLIKE(1,2);
1273 #else
1274 #define USE_TRACEF(mask) (_nc_tracing & (mask))
1275 #define _nc_locked_tracef _tracef
1276 #endif
1277 
1278 #define TR(n, a)	if (USE_TRACEF(n)) _nc_locked_tracef a
1279 #define T(a)		TR(TRACE_CALLS, a)
1280 #define TRACE_RETURN(value,type) return _nc_retrace_##type(value)
1281 
1282 #define returnAttr(code)	TRACE_RETURN(code,attr_t)
1283 #define returnBits(code)	TRACE_RETURN(code,unsigned)
1284 #define returnBool(code)	TRACE_RETURN(code,bool)
1285 #define returnCPtr(code)	TRACE_RETURN(code,cptr)
1286 #define returnCVoidPtr(code)	TRACE_RETURN(code,cvoid_ptr)
1287 #define returnChar(code)	TRACE_RETURN(code,chtype)
1288 #define returnCode(code)	TRACE_RETURN(code,int)
1289 #define returnPtr(code)		TRACE_RETURN(code,ptr)
1290 #define returnSP(code)		TRACE_RETURN(code,sp)
1291 #define returnVoid		T((T_RETURN(""))); return
1292 #define returnVoidPtr(code)	TRACE_RETURN(code,void_ptr)
1293 #define returnWin(code)		TRACE_RETURN(code,win)
1294 
1295 extern NCURSES_EXPORT(NCURSES_BOOL)     _nc_retrace_bool (NCURSES_BOOL);
1296 extern NCURSES_EXPORT(NCURSES_CONST void *) _nc_retrace_cvoid_ptr (NCURSES_CONST void *);
1297 extern NCURSES_EXPORT(SCREEN *)         _nc_retrace_sp (SCREEN *);
1298 extern NCURSES_EXPORT(WINDOW *)         _nc_retrace_win (WINDOW *);
1299 extern NCURSES_EXPORT(attr_t)           _nc_retrace_attr_t (attr_t);
1300 extern NCURSES_EXPORT(char *)           _nc_retrace_ptr (char *);
1301 extern NCURSES_EXPORT(char *)           _nc_trace_ttymode(TTY *tty);
1302 extern NCURSES_EXPORT(char *)           _nc_varargs (const char *, va_list);
1303 extern NCURSES_EXPORT(chtype)           _nc_retrace_chtype (chtype);
1304 extern NCURSES_EXPORT(const char *)     _nc_altcharset_name(attr_t, chtype);
1305 extern NCURSES_EXPORT(const char *)     _nc_retrace_cptr (const char *);
1306 extern NCURSES_EXPORT(int)              _nc_retrace_int (int);
1307 extern NCURSES_EXPORT(unsigned)         _nc_retrace_unsigned (unsigned);
1308 extern NCURSES_EXPORT(void *)           _nc_retrace_void_ptr (void *);
1309 extern NCURSES_EXPORT(void)             _nc_fifo_dump (SCREEN *);
1310 
1311 #if USE_REENTRANT
1312 NCURSES_WRAPPED_VAR(long, _nc_outchars);
1313 NCURSES_WRAPPED_VAR(const char *, _nc_tputs_trace);
1314 #define _nc_outchars       NCURSES_PUBLIC_VAR(_nc_outchars())
1315 #define _nc_tputs_trace    NCURSES_PUBLIC_VAR(_nc_tputs_trace())
1316 extern NCURSES_EXPORT(void)		_nc_set_tputs_trace (const char *);
1317 extern NCURSES_EXPORT(void)		_nc_count_outchars (long);
1318 #else
1319 extern NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace;
1320 extern NCURSES_EXPORT_VAR(long)         _nc_outchars;
1321 #endif
1322 
1323 extern NCURSES_EXPORT_VAR(unsigned)     _nc_tracing;
1324 
1325 #if USE_WIDEC_SUPPORT
1326 extern NCURSES_EXPORT(const char *) _nc_viswbuf2 (int, const wchar_t *);
1327 extern NCURSES_EXPORT(const char *) _nc_viswbufn (const wchar_t *, int);
1328 #endif
1329 
1330 extern NCURSES_EXPORT(const char *) _nc_viscbuf2 (int, const NCURSES_CH_T *, int);
1331 extern NCURSES_EXPORT(const char *) _nc_viscbuf (const NCURSES_CH_T *, int);
1332 
1333 #else /* !TRACE */
1334 
1335 #define START_TRACE() /* nothing */
1336 
1337 #define T(a)
1338 #define TR(n, a)
1339 #define TPUTS_TRACE(s)
1340 
1341 #define returnAttr(code)	return code
1342 #define returnBits(code)	return code
1343 #define returnBool(code)	return code
1344 #define returnCPtr(code)	return code
1345 #define returnCVoidPtr(code)	return code
1346 #define returnChar(code)	return code
1347 #define returnCode(code)	return code
1348 #define returnPtr(code)		return code
1349 #define returnSP(code)		return code
1350 #define returnVoid		return
1351 #define returnVoidPtr(code)	return code
1352 #define returnWin(code)		return code
1353 
1354 #endif /* TRACE/!TRACE */
1355 
1356 /*
1357  * Return-codes for tgetent() and friends.
1358  */
1359 #define TGETENT_YES  1		/* entry is found */
1360 #define TGETENT_NO   0		/* entry is not found */
1361 #define TGETENT_ERR -1		/* an error occurred */
1362 
1363 extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *);
1364 extern NCURSES_EXPORT(const char *) _nc_visbufn (const char *, int);
1365 
1366 #define EMPTY_MODULE(name) \
1367 extern	NCURSES_EXPORT(void) name (void); \
1368 	NCURSES_EXPORT(void) name (void) { }
1369 
1370 #define ALL_BUT_COLOR ((chtype)~(A_COLOR))
1371 #define NONBLANK_ATTR (A_NORMAL|A_BOLD|A_DIM|A_BLINK)
1372 #define XMC_CHANGES(c) ((c) & SP->_xmc_suppress)
1373 
1374 #define toggle_attr_on(S,at) {\
1375    if (PAIR_NUMBER(at) > 0) {\
1376       (S) = ((S) & ALL_BUT_COLOR) | (at);\
1377    } else {\
1378       (S) |= (at);\
1379    }\
1380    TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
1381 
1382 
1383 #define toggle_attr_off(S,at) {\
1384    if (PAIR_NUMBER(at) > 0) {\
1385       (S) &= ~(at|A_COLOR);\
1386    } else {\
1387       (S) &= ~(at);\
1388    }\
1389    TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
1390 
1391 #define DelCharCost(count) \
1392 		((parm_dch != 0) \
1393 		? SP->_dch_cost \
1394 		: ((delete_character != 0) \
1395 			? (SP->_dch1_cost * count) \
1396 			: INFINITY))
1397 
1398 #define InsCharCost(count) \
1399 		((parm_ich != 0) \
1400 		? SP->_ich_cost \
1401 		: ((enter_insert_mode && exit_insert_mode) \
1402 		  ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) \
1403 		  : ((insert_character != 0) \
1404 		    ? ((SP->_ich1_cost + SP->_ip_cost) * count) \
1405 		    : INFINITY)))
1406 
1407 #if USE_XMC_SUPPORT
1408 #define UpdateAttrs(c)	if (!SameAttrOf(SCREEN_ATTRS(SP), c)) { \
1409 				attr_t chg = AttrOf(SCREEN_ATTRS(SP)); \
1410 				VIDATTR(AttrOf(c), GetPair(c)); \
1411 				if (magic_cookie_glitch > 0 \
1412 				 && XMC_CHANGES((chg ^ AttrOf(SCREEN_ATTRS(SP))))) { \
1413 					T(("%s @%d before glitch %d,%d", \
1414 						__FILE__, __LINE__, \
1415 						SP->_cursrow, \
1416 						SP->_curscol)); \
1417 					_nc_do_xmc_glitch(chg); \
1418 				} \
1419 			}
1420 #else
1421 #define UpdateAttrs(c)	if (!SameAttrOf(SCREEN_ATTRS(SP), c)) \
1422 				VIDATTR(AttrOf(c), GetPair(c));
1423 #endif
1424 
1425 /*
1426  * Macros to make additional parameter to implement wgetch_events()
1427  */
1428 #ifdef NCURSES_WGETCH_EVENTS
1429 #define EVENTLIST_0th(param) param
1430 #define EVENTLIST_1st(param) param
1431 #define EVENTLIST_2nd(param) , param
1432 #else
1433 #define EVENTLIST_0th(param) void
1434 #define EVENTLIST_1st(param) /* nothing */
1435 #define EVENTLIST_2nd(param) /* nothing */
1436 #endif
1437 
1438 #if NCURSES_EXPANDED && NCURSES_EXT_FUNCS
1439 
1440 #undef  toggle_attr_on
1441 #define toggle_attr_on(S,at) _nc_toggle_attr_on(&(S), at)
1442 extern NCURSES_EXPORT(void) _nc_toggle_attr_on (attr_t *, attr_t);
1443 
1444 #undef  toggle_attr_off
1445 #define toggle_attr_off(S,at) _nc_toggle_attr_off(&(S), at)
1446 extern NCURSES_EXPORT(void) _nc_toggle_attr_off (attr_t *, attr_t);
1447 
1448 #undef  DelCharCost
1449 #define DelCharCost(count) _nc_DelCharCost(count)
1450 extern NCURSES_EXPORT(int) _nc_DelCharCost (int);
1451 
1452 #undef  InsCharCost
1453 #define InsCharCost(count) _nc_InsCharCost(count)
1454 extern NCURSES_EXPORT(int) _nc_InsCharCost (int);
1455 
1456 #undef  UpdateAttrs
1457 #define UpdateAttrs(c) _nc_UpdateAttrs(c)
1458 extern NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T);
1459 
1460 #else
1461 
1462 extern NCURSES_EXPORT(void) _nc_expanded (void);
1463 
1464 #endif
1465 
1466 #if !NCURSES_EXT_FUNCS
1467 #define set_escdelay(value) ESCDELAY = value
1468 #endif
1469 
1470 #if !HAVE_GETCWD
1471 #define getcwd(buf,len) getwd(buf)
1472 #endif
1473 
1474 /* charable.c */
1475 #if USE_WIDEC_SUPPORT
1476 extern NCURSES_EXPORT(bool) _nc_is_charable(wchar_t);
1477 extern NCURSES_EXPORT(int) _nc_to_char(wint_t);
1478 extern NCURSES_EXPORT(wint_t) _nc_to_widechar(int);
1479 #endif
1480 
1481 /* comp_captab.c */
1482 typedef struct {
1483 	short	nte_name;	/* offset of name to hash on */
1484 	int	nte_type;	/* BOOLEAN, NUMBER or STRING */
1485 	short	nte_index;	/* index of associated variable in its array */
1486 	short	nte_link;	/* index in table of next hash, or -1 */
1487 } name_table_data;
1488 
1489 typedef struct
1490 {
1491 	short	from;
1492 	short	to;
1493 	short	source;
1494 } alias_table_data;
1495 
1496 /* doupdate.c */
1497 #if USE_XMC_SUPPORT
1498 extern NCURSES_EXPORT(void) _nc_do_xmc_glitch (attr_t);
1499 #endif
1500 
1501 /* hardscroll.c */
1502 #if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
1503 extern NCURSES_EXPORT(void) _nc_linedump (void);
1504 #endif
1505 
1506 /* lib_acs.c */
1507 extern NCURSES_EXPORT(void) _nc_init_acs (void);	/* corresponds to traditional 'init_acs()' */
1508 extern NCURSES_EXPORT(int) _nc_msec_cost (const char *const, int);  /* used by 'tack' program */
1509 
1510 /* lib_addch.c */
1511 #if USE_WIDEC_SUPPORT
1512 NCURSES_EXPORT(int) _nc_build_wch(WINDOW *win, ARG_CH_T ch);
1513 #endif
1514 
1515 /* lib_addstr.c */
1516 #if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
1517 extern NCURSES_EXPORT(int) _nc_wchstrlen(const cchar_t *);
1518 #endif
1519 
1520 /* lib_color.c */
1521 extern NCURSES_EXPORT(bool) _nc_reset_colors(void);
1522 
1523 /* lib_getch.c */
1524 extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, unsigned long *, int EVENTLIST_2nd(_nc_eventlist *));
1525 
1526 /* lib_insch.c */
1527 extern NCURSES_EXPORT(int) _nc_insert_ch(WINDOW *, chtype);
1528 
1529 /* lib_mvcur.c */
1530 #define INFINITY	1000000	/* cost: too high to use */
1531 
1532 extern NCURSES_EXPORT(void) _nc_mvcur_init (void);
1533 extern NCURSES_EXPORT(void) _nc_mvcur_resume (void);
1534 extern NCURSES_EXPORT(void) _nc_mvcur_wrap (void);
1535 
1536 extern NCURSES_EXPORT(int) _nc_scrolln (int, int, int, int);
1537 
1538 extern NCURSES_EXPORT(void) _nc_screen_init (void);
1539 extern NCURSES_EXPORT(void) _nc_screen_resume (void);
1540 extern NCURSES_EXPORT(void) _nc_screen_wrap (void);
1541 
1542 /* lib_mouse.c */
1543 extern NCURSES_EXPORT(int) _nc_has_mouse (void);
1544 
1545 /* lib_mvcur.c */
1546 #define INFINITY	1000000	/* cost: too high to use */
1547 #define BAUDBYTE	9	/* 9 = 7 bits + 1 parity + 1 stop */
1548 
1549 /* lib_setup.c */
1550 extern NCURSES_EXPORT(char *) _nc_get_locale(void);
1551 extern NCURSES_EXPORT(int) _nc_unicode_locale(void);
1552 extern NCURSES_EXPORT(int) _nc_locale_breaks_acs(TERMINAL *);
1553 extern NCURSES_EXPORT(int) _nc_setupterm(NCURSES_CONST char *, int, int *, bool);
1554 extern NCURSES_EXPORT(void) _nc_get_screensize(SCREEN *, int *, int *);
1555 
1556 /* lib_tstp.c */
1557 #if USE_SIGWINCH
1558 extern NCURSES_EXPORT(int) _nc_handle_sigwinch(SCREEN *);
1559 #else
1560 #define _nc_handle_sigwinch(a) /* nothing */
1561 #endif
1562 
1563 /* lib_ungetch.c */
1564 extern NCURSES_EXPORT(int) _nc_ungetch (SCREEN *, int);
1565 
1566 /* lib_wacs.c */
1567 #if USE_WIDEC_SUPPORT
1568 extern NCURSES_EXPORT(void) _nc_init_wacs(void);
1569 #endif
1570 
1571 typedef struct {
1572     char *s_head;	/* beginning of the string (may be null) */
1573     char *s_tail;	/* end of the string (may be null) */
1574     size_t s_size;	/* current remaining size available */
1575     size_t s_init;	/* total size available */
1576 } string_desc;
1577 
1578 /* strings.c */
1579 extern NCURSES_EXPORT(string_desc *) _nc_str_init (string_desc *, char *, size_t);
1580 extern NCURSES_EXPORT(string_desc *) _nc_str_null (string_desc *, size_t);
1581 extern NCURSES_EXPORT(string_desc *) _nc_str_copy (string_desc *, string_desc *);
1582 extern NCURSES_EXPORT(bool) _nc_safe_strcat (string_desc *, const char *);
1583 extern NCURSES_EXPORT(bool) _nc_safe_strcpy (string_desc *, const char *);
1584 
1585 #if !HAVE_STRSTR
1586 #define strstr _nc_strstr
1587 extern NCURSES_EXPORT(char *) _nc_strstr (const char *, const char *);
1588 #endif
1589 
1590 /* safe_sprintf.c */
1591 extern NCURSES_EXPORT(char *) _nc_printf_string (const char *, va_list);
1592 
1593 /* tries.c */
1594 extern NCURSES_EXPORT(int) _nc_add_to_try (TRIES **, const char *, unsigned);
1595 extern NCURSES_EXPORT(char *) _nc_expand_try (TRIES *, unsigned, int *, size_t);
1596 extern NCURSES_EXPORT(int) _nc_remove_key (TRIES **, unsigned);
1597 extern NCURSES_EXPORT(int) _nc_remove_string (TRIES **, const char *);
1598 
1599 /* elsewhere ... */
1600 extern NCURSES_EXPORT(ENTRY *) _nc_delink_entry (ENTRY *, TERMTYPE *);
1601 extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_keyname (SCREEN *, int);
1602 extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_unctrl (SCREEN *, chtype);
1603 extern NCURSES_EXPORT(SCREEN *) _nc_screen_of (WINDOW *);
1604 extern NCURSES_EXPORT(WINDOW *) _nc_makenew (int, int, int, int, int);
1605 extern NCURSES_EXPORT(char *) _nc_trace_buf (int, size_t);
1606 extern NCURSES_EXPORT(char *) _nc_trace_bufcat (int, const char *);
1607 extern NCURSES_EXPORT(char *) _nc_tracechar (SCREEN *, int);
1608 extern NCURSES_EXPORT(char *) _nc_tracemouse (SCREEN *, MEVENT const *);
1609 extern NCURSES_EXPORT(int) _nc_access (const char *, int);
1610 extern NCURSES_EXPORT(int) _nc_baudrate (int);
1611 extern NCURSES_EXPORT(int) _nc_freewin (WINDOW *);
1612 extern NCURSES_EXPORT(int) _nc_getenv_num (const char *);
1613 extern NCURSES_EXPORT(int) _nc_keypad (SCREEN *, bool);
1614 extern NCURSES_EXPORT(int) _nc_ospeed (int);
1615 extern NCURSES_EXPORT(int) _nc_outch (int);
1616 extern NCURSES_EXPORT(int) _nc_read_termcap_entry (const char *const, TERMTYPE *const);
1617 extern NCURSES_EXPORT(int) _nc_setupscreen (int, int, FILE *, bool, int);
1618 extern NCURSES_EXPORT(int) _nc_timed_wait (SCREEN *, int, int, int * EVENTLIST_2nd(_nc_eventlist *));
1619 extern NCURSES_EXPORT(void) _nc_do_color (short, short, bool, int (*)(int));
1620 extern NCURSES_EXPORT(void) _nc_flush (void);
1621 extern NCURSES_EXPORT(void) _nc_free_and_exit (int);
1622 extern NCURSES_EXPORT(void) _nc_free_entry (ENTRY *, TERMTYPE *);
1623 extern NCURSES_EXPORT(void) _nc_freeall (void);
1624 extern NCURSES_EXPORT(void) _nc_hash_map (void);
1625 extern NCURSES_EXPORT(void) _nc_init_keytry (SCREEN *);
1626 extern NCURSES_EXPORT(void) _nc_keep_tic_dir (const char *);
1627 extern NCURSES_EXPORT(void) _nc_make_oldhash (int i);
1628 extern NCURSES_EXPORT(void) _nc_scroll_oldhash (int n, int top, int bot);
1629 extern NCURSES_EXPORT(void) _nc_scroll_optimize (void);
1630 extern NCURSES_EXPORT(void) _nc_set_buffer (FILE *, bool);
1631 extern NCURSES_EXPORT(void) _nc_signal_handler (bool);
1632 extern NCURSES_EXPORT(void) _nc_synchook (WINDOW *);
1633 extern NCURSES_EXPORT(void) _nc_trace_tries (TRIES *);
1634 
1635 #if NO_LEAKS
1636 extern NCURSES_EXPORT(void) _nc_alloc_entry_leaks(void);
1637 extern NCURSES_EXPORT(void) _nc_captoinfo_leaks(void);
1638 extern NCURSES_EXPORT(void) _nc_codes_leaks(void);
1639 extern NCURSES_EXPORT(void) _nc_comp_captab_leaks(void);
1640 extern NCURSES_EXPORT(void) _nc_comp_scan_leaks(void);
1641 extern NCURSES_EXPORT(void) _nc_keyname_leaks(void);
1642 extern NCURSES_EXPORT(void) _nc_names_leaks(void);
1643 extern NCURSES_EXPORT(void) _nc_tgetent_leaks(void);
1644 #endif
1645 
1646 #ifndef USE_TERMLIB
1647 extern NCURSES_EXPORT(NCURSES_CH_T) _nc_render (WINDOW *, NCURSES_CH_T);
1648 extern NCURSES_EXPORT(int) _nc_waddch_nosync (WINDOW *, const NCURSES_CH_T);
1649 extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, NCURSES_SIZE_T const, NCURSES_SIZE_T const, NCURSES_CH_T);
1650 #endif
1651 
1652 #if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
1653 extern NCURSES_EXPORT(size_t) _nc_wcrtomb (char *, wchar_t, mbstate_t *);
1654 #endif
1655 
1656 #if USE_SIZECHANGE
1657 extern NCURSES_EXPORT(void) _nc_update_screensize (SCREEN *);
1658 #endif
1659 
1660 #if HAVE_RESIZETERM
1661 extern NCURSES_EXPORT(void) _nc_resize_margins (WINDOW *);
1662 #else
1663 #define _nc_resize_margins(wp) /* nothing */
1664 #endif
1665 
1666 #ifdef NCURSES_WGETCH_EVENTS
1667 extern NCURSES_EXPORT(int) _nc_eventlist_timeout(_nc_eventlist *);
1668 #else
1669 #define wgetch_events(win, evl) wgetch(win)
1670 #define wgetnstr_events(win, str, maxlen, evl) wgetnstr(win, str, maxlen)
1671 #endif
1672 
1673 /*
1674  * Not everyone has vsscanf(), but we'd like to use it for scanw().
1675  */
1676 #if !HAVE_VSSCANF
1677 extern int vsscanf(const char *str, const char *format, va_list __arg);
1678 #endif
1679 
1680 /* scroll indices */
1681 extern NCURSES_EXPORT_VAR(int *) _nc_oldnums;
1682 
1683 #define USE_SETBUF_0 0
1684 
1685 #define NC_BUFFERED(flag) _nc_set_buffer(SP->_ofp, flag)
1686 
1687 #define NC_OUTPUT ((SP != 0) ? SP->_ofp : stdout)
1688 
1689 /*
1690  * On systems with a broken linker, define 'SP' as a function to force the
1691  * linker to pull in the data-only module with 'SP'.
1692  */
1693 #if BROKEN_LINKER
1694 #define SP _nc_screen()
1695 extern NCURSES_EXPORT(SCREEN *) _nc_screen (void);
1696 extern NCURSES_EXPORT(int) _nc_alloc_screen (void);
1697 extern NCURSES_EXPORT(void) _nc_set_screen (SCREEN *);
1698 #else
1699 /* current screen is private data; avoid possible linking conflicts too */
1700 extern NCURSES_EXPORT_VAR(SCREEN *) SP;
1701 #define _nc_alloc_screen() ((SP = typeCalloc(SCREEN, 1)) != 0)
1702 #define _nc_set_screen(sp) SP = sp
1703 #endif
1704 
1705 /*
1706  * We don't want to use the lines or columns capabilities internally, because
1707  * if the application is running multiple screens under X, it's quite possible
1708  * they could all have type xterm but have different sizes!  So...
1709  */
1710 #define screen_lines	SP->_lines
1711 #define screen_columns	SP->_columns
1712 
1713 extern NCURSES_EXPORT(int) _nc_slk_initialize (WINDOW *, int);
1714 
1715 /*
1716  * Some constants related to SLK's
1717  */
1718 #define MAX_SKEY_OLD	   8	/* count of soft keys */
1719 #define MAX_SKEY_LEN_OLD   8	/* max length of soft key text */
1720 #define MAX_SKEY_PC       12    /* This is what most PC's have */
1721 #define MAX_SKEY_LEN_PC    5
1722 
1723 /* Macro to check whether or not we use a standard format */
1724 #define SLK_STDFMT(fmt) (fmt < 3)
1725 /* Macro to determine height of label window */
1726 #define SLK_LINES(fmt)  (SLK_STDFMT(fmt) ? 1 : ((fmt) - 2))
1727 
1728 #define MAX_SKEY(fmt)     (SLK_STDFMT(fmt)? MAX_SKEY_OLD : MAX_SKEY_PC)
1729 #define MAX_SKEY_LEN(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_LEN_OLD : MAX_SKEY_LEN_PC)
1730 
1731 extern NCURSES_EXPORT(int) _nc_ripoffline (int line, int (*init)(WINDOW *,int));
1732 
1733 /*
1734  * Common error messages
1735  */
1736 #define MSG_NO_MEMORY "Out of memory"
1737 #define MSG_NO_INPUTS "Premature EOF"
1738 
1739 #ifdef __cplusplus
1740 }
1741 #endif
1742 
1743 #endif /* CURSES_PRIV_H */
1744