xref: /openbsd-src/lib/libcurses/curses.priv.h (revision 46035553bfdd96e63c94e32da0210227ec2e3cf1)
1 /* $OpenBSD: curses.priv.h,v 1.34 2010/09/06 17:26:17 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.34 2010/09/06 17:26:17 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 #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 #endif
899 
900 	/*
901 	 * These are data that support the proper handling of the panel stack on an
902 	 * per screen basis.
903 	 */
904 	struct panelhook _panelHook;
905 
906 	bool		_sig_winch;
907 	SCREEN		*_next_screen;
908 
909 	/* hashes for old and new lines */
910 	unsigned long	*oldhash, *newhash;
911 	HASHMAP		*hashtab;
912 	int		hashtab_len;
913 	int		*_oldnum_list;
914 	int		_oldnum_size;
915 
916 	bool		_cleanup;	/* cleanup after int/quit signal */
917 	int		(*_outch)(int); /* output handler if not putc */
918 
919 	int		_legacy_coding;	/* see use_legacy_coding() */
920 
921 #if USE_REENTRANT
922 	char		_ttytype[NAMESIZE];
923 	int		_ESCDELAY;
924 	int		_TABSIZE;
925 	int		_LINES;
926 	int		_COLS;
927 #ifdef TRACE
928 	long		_outchars;
929 	const char	*_tputs_trace;
930 #endif
931 #endif
932 
933 #ifdef TRACE
934 #define _nc_screen_tracechr_buf_size 40
935 	char		tracechr_buf[_nc_screen_tracechr_buf_size];
936 	char		tracemse_buf[TRACEMSE_MAX];
937 #endif
938 	/*
939 	 * ncurses/ncursesw are the same up to this point.
940 	 */
941 #if USE_WIDEC_SUPPORT
942 	/* recent versions of 'screen' have partially-working support for
943 	 * UTF-8, but do not permit ACS at the same time (see tty_update.c).
944 	 */
945 	bool		_screen_acs_fix;
946 #endif
947 };
948 
949 extern NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain;
950 extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
951 
952 	WINDOWLIST {
953 	WINDOW	win;		/* first, so WINDOW_EXT() works */
954 	WINDOWLIST *next;
955 	SCREEN *screen;		/* screen containing the window */
956 #ifdef _XOPEN_SOURCE_EXTENDED
957 	char addch_work[(MB_LEN_MAX * 9) + 1];
958 	unsigned addch_used;	/* number of bytes in addch_work[] */
959 	int addch_x;		/* x-position for addch_work[] */
960 	int addch_y;		/* y-position for addch_work[] */
961 #endif
962 };
963 
964 #define WINDOW_EXT(win,field) (((WINDOWLIST *)(win))->field)
965 
966 /* usually in <limits.h> */
967 #ifndef UCHAR_MAX
968 #define UCHAR_MAX 255
969 #endif
970 
971 /* The terminfo source is assumed to be 7-bit ASCII */
972 #define is7bits(c)	((unsigned)(c) < 128)
973 
974 /* Checks for isprint() should be done on 8-bit characters (non-wide) */
975 #define is8bits(c)	((unsigned)(c) <= UCHAR_MAX)
976 
977 #ifndef min
978 #define min(a,b)	((a) > (b)  ?  (b)  :  (a))
979 #endif
980 
981 #ifndef max
982 #define max(a,b)	((a) < (b)  ?  (b)  :  (a))
983 #endif
984 
985 /* usually in <unistd.h> */
986 #ifndef STDIN_FILENO
987 #define STDIN_FILENO 0
988 #endif
989 
990 #ifndef STDOUT_FILENO
991 #define STDOUT_FILENO 1
992 #endif
993 
994 #ifndef STDERR_FILENO
995 #define STDERR_FILENO 2
996 #endif
997 
998 #ifndef EXIT_SUCCESS
999 #define EXIT_SUCCESS 0
1000 #endif
1001 
1002 #ifndef EXIT_FAILURE
1003 #define EXIT_FAILURE 1
1004 #endif
1005 
1006 #ifndef R_OK
1007 #define	R_OK	4		/* Test for read permission.  */
1008 #endif
1009 #ifndef W_OK
1010 #define	W_OK	2		/* Test for write permission.  */
1011 #endif
1012 #ifndef X_OK
1013 #define	X_OK	1		/* Test for execute permission.  */
1014 #endif
1015 #ifndef F_OK
1016 #define	F_OK	0		/* Test for existence.  */
1017 #endif
1018 
1019 #if HAVE_FCNTL_H
1020 #include <fcntl.h>		/* may define O_BINARY	*/
1021 #endif
1022 
1023 #ifndef O_BINARY
1024 #define O_BINARY 0
1025 #endif
1026 
1027 #ifdef TRACE
1028 #if USE_REENTRANT
1029 #define COUNT_OUTCHARS(n) _nc_count_outchars(n);
1030 #else
1031 #define COUNT_OUTCHARS(n) _nc_outchars += (n);
1032 #endif
1033 #else
1034 #define COUNT_OUTCHARS(n) /* nothing */
1035 #endif
1036 
1037 #define RESET_OUTCHARS() COUNT_OUTCHARS(-_nc_outchars)
1038 
1039 #define UChar(c)	((unsigned char)(c))
1040 #define ChCharOf(c)	((c) & (chtype)A_CHARTEXT)
1041 #define ChAttrOf(c)	((c) & (chtype)A_ATTRIBUTES)
1042 
1043 #ifndef MB_LEN_MAX
1044 #define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */
1045 #endif
1046 
1047 #if USE_WIDEC_SUPPORT /* { */
1048 #define isEILSEQ(status) (((size_t)status == (size_t)-1) && (errno == EILSEQ))
1049 
1050 #define init_mb(state)	memset(&state, 0, sizeof(state))
1051 
1052 #if NCURSES_EXT_COLORS
1053 #define NulColor	, 0
1054 #else
1055 #define NulColor	/* nothing */
1056 #endif
1057 
1058 #define NulChar		0,0,0,0	/* FIXME: see CCHARW_MAX */
1059 #define CharOf(c)	((c).chars[0])
1060 #define AttrOf(c)	((c).attr)
1061 
1062 #define AddAttr(c,a)	AttrOf(c) |=  ((a) & A_ATTRIBUTES)
1063 #define RemAttr(c,a)	AttrOf(c) &= ~((a) & A_ATTRIBUTES)
1064 #define SetAttr(c,a)	AttrOf(c) =   ((a) & A_ATTRIBUTES) | WidecExt(c)
1065 
1066 #define NewChar2(c,a)	{ a, { c, NulChar } NulColor }
1067 #define NewChar(ch)	NewChar2(ChCharOf(ch), ChAttrOf(ch))
1068 
1069 #if CCHARW_MAX == 5
1070 #define CharEq(a,b)	(((a).attr == (b).attr) \
1071 		       && (a).chars[0] == (b).chars[0] \
1072 		       && (a).chars[1] == (b).chars[1] \
1073 		       && (a).chars[2] == (b).chars[2] \
1074 		       && (a).chars[3] == (b).chars[3] \
1075 		       && (a).chars[4] == (b).chars[4] \
1076 			if_EXT_COLORS(&& (a).ext_color == (b).ext_color))
1077 #else
1078 #define CharEq(a,b)	(!memcmp(&(a), &(b), sizeof(a)))
1079 #endif
1080 
1081 #define SetChar(ch,c,a) do {							    \
1082 			    NCURSES_CH_T *_cp = &ch;				    \
1083 			    memset(_cp, 0, sizeof(ch));				    \
1084 			    _cp->chars[0] = (c);					    \
1085 			    _cp->attr = (a);					    \
1086 			    if_EXT_COLORS(SetPair(ch, PAIR_NUMBER(a)));		    \
1087 			} while (0)
1088 #define CHREF(wch)	(&wch)
1089 #define CHDEREF(wch)	(*wch)
1090 #define ARG_CH_T	NCURSES_CH_T *
1091 #define CARG_CH_T	const NCURSES_CH_T *
1092 #define PUTC_DATA	char PUTC_buf[MB_LEN_MAX]; int PUTC_i, PUTC_n; \
1093 			mbstate_t PUT_st; wchar_t PUTC_ch
1094 #define PUTC_INIT	init_mb (PUT_st)
1095 #define PUTC(ch,b)	do { if(!isWidecExt(ch)) {				    \
1096 			if (Charable(ch)) {					    \
1097 			    fputc(CharOf(ch), b);				    \
1098 			    COUNT_OUTCHARS(1);					    \
1099 			} else {						    \
1100 			    PUTC_INIT;						    \
1101 			    for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {	    \
1102 				PUTC_ch = (ch).chars[PUTC_i];			    \
1103 				if (PUTC_ch == L'\0')				    \
1104 				    break;					    \
1105 				PUTC_n = wcrtomb(PUTC_buf,			    \
1106 						 (ch).chars[PUTC_i], &PUT_st);	    \
1107 				if (PUTC_n <= 0) {				    \
1108 				    if (PUTC_ch && is8bits(PUTC_ch) && PUTC_i == 0) \
1109 					putc(PUTC_ch,b);			    \
1110 				    break;					    \
1111 				}						    \
1112 				fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b);	    \
1113 			    }							    \
1114 			    COUNT_OUTCHARS(PUTC_i);				    \
1115 			} } } while (0)
1116 
1117 #define BLANK		NewChar2(' ', WA_NORMAL)
1118 #define ZEROS		NewChar2('\0', WA_NORMAL)
1119 #define ISBLANK(ch)	((ch).chars[0] == L' ' && (ch).chars[1] == L'\0')
1120 
1121 	/*
1122 	 * Wide characters cannot be represented in the A_CHARTEXT mask of
1123 	 * attr_t's but an application might have set a narrow character there.
1124 	 * But even in that case, it would only be a printable character, or
1125 	 * zero.  Otherwise we can use those bits to tell if a cell is the
1126 	 * first or extension part of a wide character.
1127 	 */
1128 #define WidecExt(ch)	(AttrOf(ch) & A_CHARTEXT)
1129 #define isWidecBase(ch)	(WidecExt(ch) == 1)
1130 #define isWidecExt(ch)	(WidecExt(ch) > 1 && WidecExt(ch) < 32)
1131 #define SetWidecExt(dst, ext)	AttrOf(dst) &= ~A_CHARTEXT,		\
1132 				AttrOf(dst) |= (ext + 1)
1133 
1134 #define if_WIDEC(code)  code
1135 #define Charable(ch)	((SP != 0 && SP->_legacy_coding)		\
1136 			 || (AttrOf(ch) & A_ALTCHARSET)			\
1137 			 || (!isWidecExt(ch) &&				\
1138 			     (ch).chars[1] == L'\0' &&			\
1139 			     _nc_is_charable(CharOf(ch))))
1140 
1141 #define L(ch)		L ## ch
1142 #else /* }{ */
1143 #define CharOf(c)	ChCharOf(c)
1144 #define AttrOf(c)	ChAttrOf(c)
1145 #define AddAttr(c,a)	c |= (a)
1146 #define RemAttr(c,a)	c &= ~((a) & A_ATTRIBUTES)
1147 #define SetAttr(c,a)	c = ((c) & ~A_ATTRIBUTES) | (a)
1148 #define NewChar(ch)	(ch)
1149 #define NewChar2(c,a)	((c) | (a))
1150 #define CharEq(a,b)	((a) == (b))
1151 #define SetChar(ch,c,a)	ch = (c) | (a)
1152 #define CHREF(wch)	wch
1153 #define CHDEREF(wch)	wch
1154 #define ARG_CH_T	NCURSES_CH_T
1155 #define CARG_CH_T	NCURSES_CH_T
1156 #define PUTC_DATA	int data = 0
1157 #define PUTC(ch,b)	do { data = CharOf(ch); putc(data,b); } while (0)
1158 
1159 #define BLANK		(' '|A_NORMAL)
1160 #define ZEROS		('\0'|A_NORMAL)
1161 #define ISBLANK(ch)	(CharOf(ch) == ' ')
1162 
1163 #define isWidecExt(ch)	(0)
1164 #define if_WIDEC(code) /* nothing */
1165 
1166 #define L(ch)		ch
1167 #endif /* } */
1168 
1169 #define AttrOfD(ch)	AttrOf(CHDEREF(ch))
1170 #define CharOfD(ch)	CharOf(CHDEREF(ch))
1171 #define SetChar2(wch,ch)    SetChar(wch,ChCharOf(ch),ChAttrOf(ch))
1172 
1173 #define BLANK_ATTR	A_NORMAL
1174 #define BLANK_TEXT	L(' ')
1175 
1176 #define CHANGED     -1
1177 
1178 #define LEGALYX(w, y, x) \
1179 	      ((w) != 0 && \
1180 		((x) >= 0 && (x) <= (w)->_maxx && \
1181 		 (y) >= 0 && (y) <= (w)->_maxy))
1182 
1183 #define CHANGED_CELL(line,col) \
1184 	if (line->firstchar == _NOCHANGE) \
1185 		line->firstchar = line->lastchar = col; \
1186 	else if ((col) < line->firstchar) \
1187 		line->firstchar = col; \
1188 	else if ((col) > line->lastchar) \
1189 		line->lastchar = col
1190 
1191 #define CHANGED_RANGE(line,start,end) \
1192 	if (line->firstchar == _NOCHANGE \
1193 	 || line->firstchar > (start)) \
1194 		line->firstchar = start; \
1195 	if (line->lastchar == _NOCHANGE \
1196 	 || line->lastchar < (end)) \
1197 		line->lastchar = end
1198 
1199 #define CHANGED_TO_EOL(line,start,end) \
1200 	if (line->firstchar == _NOCHANGE \
1201 	 || line->firstchar > (start)) \
1202 		line->firstchar = start; \
1203 	line->lastchar = end
1204 
1205 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
1206 
1207 #define FreeIfNeeded(p)  if ((p) != 0) free(p)
1208 
1209 /* FreeAndNull() is not a comma-separated expression because some compilers
1210  * do not accept a mixture of void with values.
1211  */
1212 #define FreeAndNull(p)   free(p); p = 0
1213 
1214 #include <nc_alloc.h>
1215 
1216 /*
1217  * TTY bit definition for converting tabs to spaces.
1218  */
1219 #ifdef TAB3
1220 # define OFLAGS_TABS TAB3	/* POSIX specifies TAB3 */
1221 #else
1222 # ifdef XTABS
1223 #  define OFLAGS_TABS XTABS	/* XTABS is usually the "same" */
1224 # else
1225 #  ifdef OXTABS
1226 #   define OFLAGS_TABS OXTABS	/* the traditional BSD equivalent */
1227 #  else
1228 #   define OFLAGS_TABS 0
1229 #  endif
1230 # endif
1231 #endif
1232 
1233 /*
1234  * Standardize/simplify common loops
1235  */
1236 #define each_screen(p) p = _nc_screen_chain; p != 0; p = (p)->_next_screen
1237 #define each_window(p) p = _nc_windows; p != 0; p = (p)->next
1238 #define each_ripoff(p) p = ripoff_stack; (p - ripoff_stack) < N_RIPS; ++p
1239 
1240 /*
1241  * Prefixes for call/return points of library function traces.  We use these to
1242  * instrument the public functions so that the traces can be easily transformed
1243  * into regression scripts.
1244  */
1245 #define T_CALLED(fmt) "called {" fmt
1246 #define T_CREATE(fmt) "create :" fmt
1247 #define T_RETURN(fmt) "return }" fmt
1248 
1249 #ifdef TRACE
1250 
1251 #if USE_REENTRANT
1252 #define TPUTS_TRACE(s)	_nc_set_tputs_trace(s);
1253 #else
1254 #define TPUTS_TRACE(s)	_nc_tputs_trace = s;
1255 #endif
1256 
1257 #define START_TRACE() \
1258 	if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
1259 	    int t = _nc_getenv_num("NCURSES_TRACE"); \
1260 	    if (t >= 0) \
1261 		trace((unsigned) t); \
1262 	}
1263 
1264 /*
1265  * Many of the _tracef() calls use static buffers; lock the trace state before
1266  * trying to fill them.
1267  */
1268 #if USE_REENTRANT
1269 #define USE_TRACEF(mask) _nc_use_tracef(mask)
1270 extern NCURSES_EXPORT(int)	_nc_use_tracef (unsigned);
1271 extern NCURSES_EXPORT(void)	_nc_locked_tracef (const char *, ...) GCC_PRINTFLIKE(1,2);
1272 #else
1273 #define USE_TRACEF(mask) (_nc_tracing & (mask))
1274 #define _nc_locked_tracef _tracef
1275 #endif
1276 
1277 #define TR(n, a)	if (USE_TRACEF(n)) _nc_locked_tracef a
1278 #define T(a)		TR(TRACE_CALLS, a)
1279 #define TRACE_RETURN(value,type) return _nc_retrace_##type(value)
1280 
1281 #define returnAttr(code)	TRACE_RETURN(code,attr_t)
1282 #define returnBits(code)	TRACE_RETURN(code,unsigned)
1283 #define returnBool(code)	TRACE_RETURN(code,bool)
1284 #define returnCPtr(code)	TRACE_RETURN(code,cptr)
1285 #define returnCVoidPtr(code)	TRACE_RETURN(code,cvoid_ptr)
1286 #define returnChar(code)	TRACE_RETURN(code,chtype)
1287 #define returnCode(code)	TRACE_RETURN(code,int)
1288 #define returnPtr(code)		TRACE_RETURN(code,ptr)
1289 #define returnSP(code)		TRACE_RETURN(code,sp)
1290 #define returnVoid		T((T_RETURN(""))); return
1291 #define returnVoidPtr(code)	TRACE_RETURN(code,void_ptr)
1292 #define returnWin(code)		TRACE_RETURN(code,win)
1293 
1294 extern NCURSES_EXPORT(NCURSES_BOOL)     _nc_retrace_bool (NCURSES_BOOL);
1295 extern NCURSES_EXPORT(NCURSES_CONST void *) _nc_retrace_cvoid_ptr (NCURSES_CONST void *);
1296 extern NCURSES_EXPORT(SCREEN *)         _nc_retrace_sp (SCREEN *);
1297 extern NCURSES_EXPORT(WINDOW *)         _nc_retrace_win (WINDOW *);
1298 extern NCURSES_EXPORT(attr_t)           _nc_retrace_attr_t (attr_t);
1299 extern NCURSES_EXPORT(char *)           _nc_retrace_ptr (char *);
1300 extern NCURSES_EXPORT(char *)           _nc_trace_ttymode(TTY *tty);
1301 extern NCURSES_EXPORT(char *)           _nc_varargs (const char *, va_list);
1302 extern NCURSES_EXPORT(chtype)           _nc_retrace_chtype (chtype);
1303 extern NCURSES_EXPORT(const char *)     _nc_altcharset_name(attr_t, chtype);
1304 extern NCURSES_EXPORT(const char *)     _nc_retrace_cptr (const char *);
1305 extern NCURSES_EXPORT(int)              _nc_retrace_int (int);
1306 extern NCURSES_EXPORT(unsigned)         _nc_retrace_unsigned (unsigned);
1307 extern NCURSES_EXPORT(void *)           _nc_retrace_void_ptr (void *);
1308 extern NCURSES_EXPORT(void)             _nc_fifo_dump (SCREEN *);
1309 
1310 #if USE_REENTRANT
1311 NCURSES_WRAPPED_VAR(long, _nc_outchars);
1312 NCURSES_WRAPPED_VAR(const char *, _nc_tputs_trace);
1313 #define _nc_outchars       NCURSES_PUBLIC_VAR(_nc_outchars())
1314 #define _nc_tputs_trace    NCURSES_PUBLIC_VAR(_nc_tputs_trace())
1315 extern NCURSES_EXPORT(void)		_nc_set_tputs_trace (const char *);
1316 extern NCURSES_EXPORT(void)		_nc_count_outchars (long);
1317 #else
1318 extern NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace;
1319 extern NCURSES_EXPORT_VAR(long)         _nc_outchars;
1320 #endif
1321 
1322 extern NCURSES_EXPORT_VAR(unsigned)     _nc_tracing;
1323 
1324 #if USE_WIDEC_SUPPORT
1325 extern NCURSES_EXPORT(const char *) _nc_viswbuf2 (int, const wchar_t *);
1326 extern NCURSES_EXPORT(const char *) _nc_viswbufn (const wchar_t *, int);
1327 #endif
1328 
1329 extern NCURSES_EXPORT(const char *) _nc_viscbuf2 (int, const NCURSES_CH_T *, int);
1330 extern NCURSES_EXPORT(const char *) _nc_viscbuf (const NCURSES_CH_T *, int);
1331 
1332 #else /* !TRACE */
1333 
1334 #define START_TRACE() /* nothing */
1335 
1336 #define T(a)
1337 #define TR(n, a)
1338 #define TPUTS_TRACE(s)
1339 
1340 #define returnAttr(code)	return code
1341 #define returnBits(code)	return code
1342 #define returnBool(code)	return code
1343 #define returnCPtr(code)	return code
1344 #define returnCVoidPtr(code)	return code
1345 #define returnChar(code)	return code
1346 #define returnCode(code)	return code
1347 #define returnPtr(code)		return code
1348 #define returnSP(code)		return code
1349 #define returnVoid		return
1350 #define returnVoidPtr(code)	return code
1351 #define returnWin(code)		return code
1352 
1353 #endif /* TRACE/!TRACE */
1354 
1355 /*
1356  * Return-codes for tgetent() and friends.
1357  */
1358 #define TGETENT_YES  1		/* entry is found */
1359 #define TGETENT_NO   0		/* entry is not found */
1360 #define TGETENT_ERR -1		/* an error occurred */
1361 
1362 extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *);
1363 extern NCURSES_EXPORT(const char *) _nc_visbufn (const char *, int);
1364 
1365 #define EMPTY_MODULE(name) \
1366 extern	NCURSES_EXPORT(void) name (void); \
1367 	NCURSES_EXPORT(void) name (void) { }
1368 
1369 #define ALL_BUT_COLOR ((chtype)~(A_COLOR))
1370 #define NONBLANK_ATTR (A_NORMAL|A_BOLD|A_DIM|A_BLINK)
1371 #define XMC_CHANGES(c) ((c) & SP->_xmc_suppress)
1372 
1373 #define toggle_attr_on(S,at) {\
1374    if (PAIR_NUMBER(at) > 0) {\
1375       (S) = ((S) & ALL_BUT_COLOR) | (at);\
1376    } else {\
1377       (S) |= (at);\
1378    }\
1379    TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
1380 
1381 
1382 #define toggle_attr_off(S,at) {\
1383    if (PAIR_NUMBER(at) > 0) {\
1384       (S) &= ~(at|A_COLOR);\
1385    } else {\
1386       (S) &= ~(at);\
1387    }\
1388    TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
1389 
1390 #define DelCharCost(count) \
1391 		((parm_dch != 0) \
1392 		? SP->_dch_cost \
1393 		: ((delete_character != 0) \
1394 			? (SP->_dch1_cost * count) \
1395 			: INFINITY))
1396 
1397 #define InsCharCost(count) \
1398 		((parm_ich != 0) \
1399 		? SP->_ich_cost \
1400 		: ((enter_insert_mode && exit_insert_mode) \
1401 		  ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) \
1402 		  : ((insert_character != 0) \
1403 		    ? ((SP->_ich1_cost + SP->_ip_cost) * count) \
1404 		    : INFINITY)))
1405 
1406 #if USE_XMC_SUPPORT
1407 #define UpdateAttrs(c)	if (!SameAttrOf(SCREEN_ATTRS(SP), c)) { \
1408 				attr_t chg = AttrOf(SCREEN_ATTRS(SP)); \
1409 				VIDATTR(AttrOf(c), GetPair(c)); \
1410 				if (magic_cookie_glitch > 0 \
1411 				 && XMC_CHANGES((chg ^ AttrOf(SCREEN_ATTRS(SP))))) { \
1412 					T(("%s @%d before glitch %d,%d", \
1413 						__FILE__, __LINE__, \
1414 						SP->_cursrow, \
1415 						SP->_curscol)); \
1416 					_nc_do_xmc_glitch(chg); \
1417 				} \
1418 			}
1419 #else
1420 #define UpdateAttrs(c)	if (!SameAttrOf(SCREEN_ATTRS(SP), c)) \
1421 				VIDATTR(AttrOf(c), GetPair(c));
1422 #endif
1423 
1424 /*
1425  * Macros to make additional parameter to implement wgetch_events()
1426  */
1427 #ifdef NCURSES_WGETCH_EVENTS
1428 #define EVENTLIST_0th(param) param
1429 #define EVENTLIST_1st(param) param
1430 #define EVENTLIST_2nd(param) , param
1431 #else
1432 #define EVENTLIST_0th(param) void
1433 #define EVENTLIST_1st(param) /* nothing */
1434 #define EVENTLIST_2nd(param) /* nothing */
1435 #endif
1436 
1437 #if NCURSES_EXPANDED && NCURSES_EXT_FUNCS
1438 
1439 #undef  toggle_attr_on
1440 #define toggle_attr_on(S,at) _nc_toggle_attr_on(&(S), at)
1441 extern NCURSES_EXPORT(void) _nc_toggle_attr_on (attr_t *, attr_t);
1442 
1443 #undef  toggle_attr_off
1444 #define toggle_attr_off(S,at) _nc_toggle_attr_off(&(S), at)
1445 extern NCURSES_EXPORT(void) _nc_toggle_attr_off (attr_t *, attr_t);
1446 
1447 #undef  DelCharCost
1448 #define DelCharCost(count) _nc_DelCharCost(count)
1449 extern NCURSES_EXPORT(int) _nc_DelCharCost (int);
1450 
1451 #undef  InsCharCost
1452 #define InsCharCost(count) _nc_InsCharCost(count)
1453 extern NCURSES_EXPORT(int) _nc_InsCharCost (int);
1454 
1455 #undef  UpdateAttrs
1456 #define UpdateAttrs(c) _nc_UpdateAttrs(c)
1457 extern NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T);
1458 
1459 #else
1460 
1461 extern NCURSES_EXPORT(void) _nc_expanded (void);
1462 
1463 #endif
1464 
1465 #if !NCURSES_EXT_FUNCS
1466 #define set_escdelay(value) ESCDELAY = value
1467 #endif
1468 
1469 #if !HAVE_GETCWD
1470 #define getcwd(buf,len) getwd(buf)
1471 #endif
1472 
1473 /* charable.c */
1474 #if USE_WIDEC_SUPPORT
1475 extern NCURSES_EXPORT(bool) _nc_is_charable(wchar_t);
1476 extern NCURSES_EXPORT(int) _nc_to_char(wint_t);
1477 extern NCURSES_EXPORT(wint_t) _nc_to_widechar(int);
1478 #endif
1479 
1480 /* comp_captab.c */
1481 typedef struct {
1482 	short	nte_name;	/* offset of name to hash on */
1483 	int	nte_type;	/* BOOLEAN, NUMBER or STRING */
1484 	short	nte_index;	/* index of associated variable in its array */
1485 	short	nte_link;	/* index in table of next hash, or -1 */
1486 } name_table_data;
1487 
1488 typedef struct
1489 {
1490 	short	from;
1491 	short	to;
1492 	short	source;
1493 } alias_table_data;
1494 
1495 /* doupdate.c */
1496 #if USE_XMC_SUPPORT
1497 extern NCURSES_EXPORT(void) _nc_do_xmc_glitch (attr_t);
1498 #endif
1499 
1500 /* hardscroll.c */
1501 #if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
1502 extern NCURSES_EXPORT(void) _nc_linedump (void);
1503 #endif
1504 
1505 /* lib_acs.c */
1506 extern NCURSES_EXPORT(void) _nc_init_acs (void);	/* corresponds to traditional 'init_acs()' */
1507 extern NCURSES_EXPORT(int) _nc_msec_cost (const char *const, int);  /* used by 'tack' program */
1508 
1509 /* lib_addch.c */
1510 #if USE_WIDEC_SUPPORT
1511 NCURSES_EXPORT(int) _nc_build_wch(WINDOW *win, ARG_CH_T ch);
1512 #endif
1513 
1514 /* lib_addstr.c */
1515 #if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
1516 extern NCURSES_EXPORT(int) _nc_wchstrlen(const cchar_t *);
1517 #endif
1518 
1519 /* lib_color.c */
1520 extern NCURSES_EXPORT(bool) _nc_reset_colors(void);
1521 
1522 /* lib_getch.c */
1523 extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, unsigned long *, int EVENTLIST_2nd(_nc_eventlist *));
1524 
1525 /* lib_insch.c */
1526 extern NCURSES_EXPORT(int) _nc_insert_ch(WINDOW *, chtype);
1527 
1528 /* lib_mvcur.c */
1529 #define INFINITY	1000000	/* cost: too high to use */
1530 
1531 extern NCURSES_EXPORT(void) _nc_mvcur_init (void);
1532 extern NCURSES_EXPORT(void) _nc_mvcur_resume (void);
1533 extern NCURSES_EXPORT(void) _nc_mvcur_wrap (void);
1534 
1535 extern NCURSES_EXPORT(int) _nc_scrolln (int, int, int, int);
1536 
1537 extern NCURSES_EXPORT(void) _nc_screen_init (void);
1538 extern NCURSES_EXPORT(void) _nc_screen_resume (void);
1539 extern NCURSES_EXPORT(void) _nc_screen_wrap (void);
1540 
1541 /* lib_mouse.c */
1542 extern NCURSES_EXPORT(int) _nc_has_mouse (void);
1543 
1544 /* lib_mvcur.c */
1545 #define INFINITY	1000000	/* cost: too high to use */
1546 #define BAUDBYTE	9	/* 9 = 7 bits + 1 parity + 1 stop */
1547 
1548 /* lib_setup.c */
1549 extern NCURSES_EXPORT(char *) _nc_get_locale(void);
1550 extern NCURSES_EXPORT(int) _nc_unicode_locale(void);
1551 extern NCURSES_EXPORT(int) _nc_locale_breaks_acs(TERMINAL *);
1552 extern NCURSES_EXPORT(int) _nc_setupterm(NCURSES_CONST char *, int, int *, bool);
1553 extern NCURSES_EXPORT(void) _nc_get_screensize(SCREEN *, int *, int *);
1554 
1555 /* lib_tstp.c */
1556 #if USE_SIGWINCH
1557 extern NCURSES_EXPORT(int) _nc_handle_sigwinch(SCREEN *);
1558 #else
1559 #define _nc_handle_sigwinch(a) /* nothing */
1560 #endif
1561 
1562 /* lib_ungetch.c */
1563 extern NCURSES_EXPORT(int) _nc_ungetch (SCREEN *, int);
1564 
1565 /* lib_wacs.c */
1566 #if USE_WIDEC_SUPPORT
1567 extern NCURSES_EXPORT(void) _nc_init_wacs(void);
1568 #endif
1569 
1570 typedef struct {
1571     char *s_head;	/* beginning of the string (may be null) */
1572     char *s_tail;	/* end of the string (may be null) */
1573     size_t s_size;	/* current remaining size available */
1574     size_t s_init;	/* total size available */
1575 } string_desc;
1576 
1577 /* strings.c */
1578 extern NCURSES_EXPORT(string_desc *) _nc_str_init (string_desc *, char *, size_t);
1579 extern NCURSES_EXPORT(string_desc *) _nc_str_null (string_desc *, size_t);
1580 extern NCURSES_EXPORT(string_desc *) _nc_str_copy (string_desc *, string_desc *);
1581 extern NCURSES_EXPORT(bool) _nc_safe_strcat (string_desc *, const char *);
1582 extern NCURSES_EXPORT(bool) _nc_safe_strcpy (string_desc *, const char *);
1583 
1584 #if !HAVE_STRSTR
1585 #define strstr _nc_strstr
1586 extern NCURSES_EXPORT(char *) _nc_strstr (const char *, const char *);
1587 #endif
1588 
1589 /* safe_sprintf.c */
1590 extern NCURSES_EXPORT(char *) _nc_printf_string (const char *, va_list);
1591 
1592 /* tries.c */
1593 extern NCURSES_EXPORT(int) _nc_add_to_try (TRIES **, const char *, unsigned);
1594 extern NCURSES_EXPORT(char *) _nc_expand_try (TRIES *, unsigned, int *, size_t);
1595 extern NCURSES_EXPORT(int) _nc_remove_key (TRIES **, unsigned);
1596 extern NCURSES_EXPORT(int) _nc_remove_string (TRIES **, const char *);
1597 
1598 /* elsewhere ... */
1599 extern NCURSES_EXPORT(ENTRY *) _nc_delink_entry (ENTRY *, TERMTYPE *);
1600 extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_keyname (SCREEN *, int);
1601 extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_unctrl (SCREEN *, chtype);
1602 extern NCURSES_EXPORT(SCREEN *) _nc_screen_of (WINDOW *);
1603 extern NCURSES_EXPORT(WINDOW *) _nc_makenew (int, int, int, int, int);
1604 extern NCURSES_EXPORT(char *) _nc_trace_buf (int, size_t);
1605 extern NCURSES_EXPORT(char *) _nc_trace_bufcat (int, const char *);
1606 extern NCURSES_EXPORT(char *) _nc_tracechar (SCREEN *, int);
1607 extern NCURSES_EXPORT(char *) _nc_tracemouse (SCREEN *, MEVENT const *);
1608 extern NCURSES_EXPORT(int) _nc_access (const char *, int);
1609 extern NCURSES_EXPORT(int) _nc_baudrate (int);
1610 extern NCURSES_EXPORT(int) _nc_freewin (WINDOW *);
1611 extern NCURSES_EXPORT(int) _nc_getenv_num (const char *);
1612 extern NCURSES_EXPORT(int) _nc_keypad (SCREEN *, bool);
1613 extern NCURSES_EXPORT(int) _nc_ospeed (int);
1614 extern NCURSES_EXPORT(int) _nc_outch (int);
1615 extern NCURSES_EXPORT(int) _nc_read_termcap_entry (const char *const, TERMTYPE *const);
1616 extern NCURSES_EXPORT(int) _nc_setupscreen (int, int, FILE *, bool, int);
1617 extern NCURSES_EXPORT(int) _nc_timed_wait (SCREEN *, int, int, int * EVENTLIST_2nd(_nc_eventlist *));
1618 extern NCURSES_EXPORT(void) _nc_do_color (short, short, bool, int (*)(int));
1619 extern NCURSES_EXPORT(void) _nc_flush (void);
1620 extern NCURSES_EXPORT(void) _nc_free_and_exit (int);
1621 extern NCURSES_EXPORT(void) _nc_free_entry (ENTRY *, TERMTYPE *);
1622 extern NCURSES_EXPORT(void) _nc_freeall (void);
1623 extern NCURSES_EXPORT(void) _nc_hash_map (void);
1624 extern NCURSES_EXPORT(void) _nc_init_keytry (SCREEN *);
1625 extern NCURSES_EXPORT(void) _nc_keep_tic_dir (const char *);
1626 extern NCURSES_EXPORT(void) _nc_make_oldhash (int i);
1627 extern NCURSES_EXPORT(void) _nc_scroll_oldhash (int n, int top, int bot);
1628 extern NCURSES_EXPORT(void) _nc_scroll_optimize (void);
1629 extern NCURSES_EXPORT(void) _nc_set_buffer (FILE *, bool);
1630 extern NCURSES_EXPORT(void) _nc_signal_handler (bool);
1631 extern NCURSES_EXPORT(void) _nc_synchook (WINDOW *);
1632 extern NCURSES_EXPORT(void) _nc_trace_tries (TRIES *);
1633 
1634 #if NO_LEAKS
1635 extern NCURSES_EXPORT(void) _nc_alloc_entry_leaks(void);
1636 extern NCURSES_EXPORT(void) _nc_captoinfo_leaks(void);
1637 extern NCURSES_EXPORT(void) _nc_codes_leaks(void);
1638 extern NCURSES_EXPORT(void) _nc_comp_captab_leaks(void);
1639 extern NCURSES_EXPORT(void) _nc_comp_scan_leaks(void);
1640 extern NCURSES_EXPORT(void) _nc_keyname_leaks(void);
1641 extern NCURSES_EXPORT(void) _nc_names_leaks(void);
1642 extern NCURSES_EXPORT(void) _nc_tgetent_leaks(void);
1643 #endif
1644 
1645 #ifndef USE_TERMLIB
1646 extern NCURSES_EXPORT(NCURSES_CH_T) _nc_render (WINDOW *, NCURSES_CH_T);
1647 extern NCURSES_EXPORT(int) _nc_waddch_nosync (WINDOW *, const NCURSES_CH_T);
1648 extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, NCURSES_SIZE_T const, NCURSES_SIZE_T const, NCURSES_CH_T);
1649 #endif
1650 
1651 #if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
1652 extern NCURSES_EXPORT(size_t) _nc_wcrtomb (char *, wchar_t, mbstate_t *);
1653 #endif
1654 
1655 #if USE_SIZECHANGE
1656 extern NCURSES_EXPORT(void) _nc_update_screensize (SCREEN *);
1657 #endif
1658 
1659 #if HAVE_RESIZETERM
1660 extern NCURSES_EXPORT(void) _nc_resize_margins (WINDOW *);
1661 #else
1662 #define _nc_resize_margins(wp) /* nothing */
1663 #endif
1664 
1665 #ifdef NCURSES_WGETCH_EVENTS
1666 extern NCURSES_EXPORT(int) _nc_eventlist_timeout(_nc_eventlist *);
1667 #else
1668 #define wgetch_events(win, evl) wgetch(win)
1669 #define wgetnstr_events(win, str, maxlen, evl) wgetnstr(win, str, maxlen)
1670 #endif
1671 
1672 /*
1673  * Not everyone has vsscanf(), but we'd like to use it for scanw().
1674  */
1675 #if !HAVE_VSSCANF
1676 extern int vsscanf(const char *str, const char *format, va_list __arg);
1677 #endif
1678 
1679 /* scroll indices */
1680 extern NCURSES_EXPORT_VAR(int *) _nc_oldnums;
1681 
1682 #define USE_SETBUF_0 0
1683 
1684 #define NC_BUFFERED(flag) _nc_set_buffer(SP->_ofp, flag)
1685 
1686 #define NC_OUTPUT ((SP != 0) ? SP->_ofp : stdout)
1687 
1688 /*
1689  * On systems with a broken linker, define 'SP' as a function to force the
1690  * linker to pull in the data-only module with 'SP'.
1691  */
1692 #if BROKEN_LINKER
1693 #define SP _nc_screen()
1694 extern NCURSES_EXPORT(SCREEN *) _nc_screen (void);
1695 extern NCURSES_EXPORT(int) _nc_alloc_screen (void);
1696 extern NCURSES_EXPORT(void) _nc_set_screen (SCREEN *);
1697 #else
1698 /* current screen is private data; avoid possible linking conflicts too */
1699 extern NCURSES_EXPORT_VAR(SCREEN *) SP;
1700 #define _nc_alloc_screen() ((SP = typeCalloc(SCREEN, 1)) != 0)
1701 #define _nc_set_screen(sp) SP = sp
1702 #endif
1703 
1704 /*
1705  * We don't want to use the lines or columns capabilities internally, because
1706  * if the application is running multiple screens under X, it's quite possible
1707  * they could all have type xterm but have different sizes!  So...
1708  */
1709 #define screen_lines	SP->_lines
1710 #define screen_columns	SP->_columns
1711 
1712 extern NCURSES_EXPORT(int) _nc_slk_initialize (WINDOW *, int);
1713 
1714 /*
1715  * Some constants related to SLK's
1716  */
1717 #define MAX_SKEY_OLD	   8	/* count of soft keys */
1718 #define MAX_SKEY_LEN_OLD   8	/* max length of soft key text */
1719 #define MAX_SKEY_PC       12    /* This is what most PC's have */
1720 #define MAX_SKEY_LEN_PC    5
1721 
1722 /* Macro to check whether or not we use a standard format */
1723 #define SLK_STDFMT(fmt) (fmt < 3)
1724 /* Macro to determine height of label window */
1725 #define SLK_LINES(fmt)  (SLK_STDFMT(fmt) ? 1 : ((fmt) - 2))
1726 
1727 #define MAX_SKEY(fmt)     (SLK_STDFMT(fmt)? MAX_SKEY_OLD : MAX_SKEY_PC)
1728 #define MAX_SKEY_LEN(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_LEN_OLD : MAX_SKEY_LEN_PC)
1729 
1730 extern NCURSES_EXPORT(int) _nc_ripoffline (int line, int (*init)(WINDOW *,int));
1731 
1732 /*
1733  * Common error messages
1734  */
1735 #define MSG_NO_MEMORY "Out of memory"
1736 #define MSG_NO_INPUTS "Premature EOF"
1737 
1738 #ifdef __cplusplus
1739 }
1740 #endif
1741 
1742 #endif /* CURSES_PRIV_H */
1743