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