1 /****************************************************************************
2  * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc.              *
3  *                                                                          *
4  * Permission is hereby granted, free of charge, to any person obtaining a  *
5  * copy of this software and associated documentation files (the            *
6  * "Software"), to deal in the Software without restriction, including      *
7  * without limitation the rights to use, copy, modify, merge, publish,      *
8  * distribute, distribute with modifications, sublicense, and/or sell       *
9  * copies of the Software, and to permit persons to whom the Software is    *
10  * furnished to do so, subject to the following conditions:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22  *                                                                          *
23  * Except as contained in this notice, the name(s) of the above copyright   *
24  * holders shall not be used in advertising or otherwise to promote the     *
25  * sale, use or other dealings in this Software without prior written       *
26  * authorization.                                                           *
27  ****************************************************************************/
28 
29 /****************************************************************************
30  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32  *     and: Thomas E. Dickey                        1996-on                 *
33  ****************************************************************************/
34 
35 
36 /*
37  * $MirOS: src/lib/libncurses/src/ncurses/curses.priv.h,v 1.6 2009/09/06 13:46:35 tg Exp $
38  * $Id: curses.priv.h,v 1.286 2005/09/10 22:34:50 tom Exp $
39  *
40  *	curses.priv.h
41  *
42  *	Header file for curses library objects which are private to
43  *	the library.
44  *
45  */
46 
47 #ifndef CURSES_PRIV_H
48 #define CURSES_PRIV_H 1
49 
50 #include <ncurses_dll.h>
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
56 #include <ncurses_cfg.h>
57 
58 #if USE_RCS_IDS && !defined(MODULE_ID)
59 #ifdef __RCSID
60 #define MODULE_ID(id) __RCSID(id);
61 #else
62 #define MODULE_ID(id) static const char Ident[] = id;
63 #endif
64 #elif !defined(MODULE_ID)
65 #define MODULE_ID(id) /*nothing*/
66 #endif
67 
68 #include <stdlib.h>
69 #include <string.h>
70 #include <sys/types.h>
71 
72 #if HAVE_UNISTD_H
73 #include <unistd.h>
74 #endif
75 
76 #if HAVE_SYS_BSDTYPES_H
77 #include <sys/bsdtypes.h>	/* needed for ISC */
78 #endif
79 
80 #if HAVE_LIMITS_H
81 # include <limits.h>
82 #elif HAVE_SYS_PARAM_H
83 # include <sys/param.h>
84 #endif
85 
86 #include <assert.h>
87 #include <stdio.h>
88 
89 #include <errno.h>
90 
91 #ifndef PATH_MAX
92 # if defined(_POSIX_PATH_MAX)
93 #  define PATH_MAX _POSIX_PATH_MAX
94 # elif defined(MAXPATHLEN)
95 #  define PATH_MAX MAXPATHLEN
96 # else
97 #  define PATH_MAX 255	/* the Posix minimum path-size */
98 # endif
99 #endif
100 
101 #if DECL_ERRNO
102 extern int errno;
103 #endif
104 
105 #include <nc_panel.h>
106 
107 /* Some systems have a broken 'select()', but workable 'poll()'.  Use that */
108 #if HAVE_WORKING_POLL
109 #define USE_FUNC_POLL 1
110 #if HAVE_POLL_H
111 #include <poll.h>
112 #else
113 #include <sys/poll.h>
114 #endif
115 #else
116 #define USE_FUNC_POLL 0
117 #endif
118 
119 /* include signal.h before curses.h to work-around defect in glibc 2.1.3 */
120 #include <signal.h>
121 
122 /* Alessandro Rubini's GPM (general-purpose mouse) */
123 #if HAVE_LIBGPM && HAVE_GPM_H
124 #define USE_GPM_SUPPORT 1
125 #else
126 #define USE_GPM_SUPPORT 0
127 #endif
128 
129 /* QNX mouse support */
130 #if defined(__QNX__) && !defined(__QNXNTO__)
131 #define USE_QNX_MOUSE 1
132 #else
133 #define USE_QNX_MOUSE 0
134 #endif
135 
136 /* EMX mouse support */
137 #ifdef __EMX__
138 #define USE_EMX_MOUSE 1
139 #else
140 #define USE_EMX_MOUSE 0
141 #endif
142 
143 #define DEFAULT_MAXCLICK 166
144 #define EV_MAX		8	/* size of mouse circular event queue */
145 
146 /*
147  * If we don't have signals to support it, don't add a sigwinch handler.
148  * In any case, resizing is an extended feature.  Use it if we've got it.
149  */
150 #if !NCURSES_EXT_FUNCS
151 #undef HAVE_SIZECHANGE
152 #define HAVE_SIZECHANGE 0
153 #endif
154 
155 #if HAVE_SIZECHANGE && defined(SIGWINCH)
156 #define USE_SIZECHANGE 1
157 #else
158 #define USE_SIZECHANGE 0
159 #undef USE_SIGWINCH
160 #define USE_SIGWINCH 0
161 #endif
162 
163 /*
164  * If desired, one can configure this, disabling environment variables that
165  * point to custom terminfo/termcap locations.
166  */
167 #ifdef USE_ROOT_ENVIRON
168 #define use_terminfo_vars() 1
169 #else
170 #define use_terminfo_vars() _nc_env_access()
171 extern NCURSES_EXPORT(int) _nc_env_access (void);
172 #endif
173 
174 /*
175  * Not all platforms have memmove; some have an equivalent bcopy.  (Some may
176  * have neither).
177  */
178 #if USE_OK_BCOPY
179 #define memmove(d,s,n) bcopy(s,d,n)
180 #elif USE_MY_MEMMOVE
181 #define memmove(d,s,n) _nc_memmove(d,s,n)
182 extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t);
183 #endif
184 
185 /*
186  * Scroll hints are useless when hashmap is used
187  */
188 #if !USE_SCROLL_HINTS
189 #if !USE_HASHMAP
190 #define USE_SCROLL_HINTS 1
191 #else
192 #define USE_SCROLL_HINTS 0
193 #endif
194 #endif
195 
196 #if USE_SCROLL_HINTS
197 #define if_USE_SCROLL_HINTS(stmt) stmt
198 #else
199 #define if_USE_SCROLL_HINTS(stmt) /*nothing*/
200 #endif
201 
202 /*
203  * Note:  ht/cbt expansion flakes out randomly under Linux 1.1.47, but only
204  * when we're throwing control codes at the screen at high volume.  To see
205  * this, re-enable USE_HARD_TABS and run worm for a while.  Other systems
206  * probably don't want to define this either due to uncertainties about tab
207  * delays and expansion in raw mode.
208  */
209 
210 struct tries {
211 	struct tries    *child;     /* ptr to child.  NULL if none          */
212 	struct tries    *sibling;   /* ptr to sibling.  NULL if none        */
213 	unsigned char    ch;        /* character at this node               */
214 	unsigned short   value;     /* code of string so far.  0 if none.   */
215 };
216 
217 /*
218  * Common/troublesome character definitions
219  */
220 #define L_BRACE '{'
221 #define R_BRACE '}'
222 #define S_QUOTE '\''
223 #define D_QUOTE '"'
224 
225 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
226 
227 /*
228  * Structure for palette tables
229  */
230 
231 typedef struct
232 {
233     short red, green, blue;	/* what color_content() returns */
234     short r, g, b;		/* params to init_color() */
235     int init;			/* true if we called init_color() */
236 }
237 color_t;
238 
239 #define MAXCOLUMNS    135
240 #define MAXLINES      66
241 #define FIFO_SIZE     MAXCOLUMNS+2  /* for nocbreak mode input */
242 
243 #define ACS_LEN       128
244 
245 #define WINDOWLIST struct _win_list
246 
247 #if USE_WIDEC_SUPPORT
248 #define _nc_bkgd    _bkgrnd
249 #else
250 #undef _XOPEN_SOURCE_EXTENDED
251 #define _nc_bkgd    _bkgd
252 #define wgetbkgrnd(win, wch)	*wch = win->_bkgd
253 #define wbkgrnd	    wbkgd
254 #endif
255 
256 #include <curses.h>	/* we'll use -Ipath directive to get the right one! */
257 #include <term.h>
258 #include <term_entry.h>
259 
260 #if NCURSES_EXT_COLORS && USE_WIDEC_SUPPORT
261 #define if_EXT_COLORS(stmt)	stmt
262 #define NetPair(value,p)	(value).ext_color = (p), \
263 				AttrOf(value) &= ALL_BUT_COLOR, \
264 				AttrOf(value) |= (A_COLOR & COLOR_PAIR((p > 255) ? 255 : p))
265 #define SetPair(value,p)	(value).ext_color = (p)
266 #define GetPair(value)		(value).ext_color
267 #define unColor(n)		(AttrOf(n) & ALL_BUT_COLOR)
268 #define GET_WINDOW_PAIR(w)	(w)->_color
269 #define SET_WINDOW_PAIR(w,p)	(w)->_color = (p)
270 #define SameAttrOf(a,b)		(AttrOf(a) == AttrOf(b) && GetPair(a) == GetPair(b))
271 #define VIDATTR(attr, pair)	vid_attr(attr, pair, 0)
272 #else
273 #define if_EXT_COLORS(stmt)	/* nothing */
274 #define SetPair(value,p)	RemAttr(value, A_COLOR), \
275 				SetAttr(value, AttrOf(value) | (A_COLOR & COLOR_PAIR(p)))
276 #define GetPair(value)		PAIR_NUMBER(AttrOf(value))
277 #define unColor(n)		(AttrOf(n) & ALL_BUT_COLOR)
278 #define GET_WINDOW_PAIR(w)	PAIR_NUMBER((w)->_attrs)
279 #define SET_WINDOW_PAIR(w,p)	(w)->_attrs &= ALL_BUT_COLOR, \
280 				(w)->_attrs |= (A_COLOR & COLOR_PAIR(p))
281 #define SameAttrOf(a,b)		(AttrOf(a) == AttrOf(b))
282 #define VIDATTR(attr, pair)	vidattr(attr)
283 #endif
284 
285 #define SCREEN_ATTRS(s)		(*((s)->_current_attr))
286 #define GET_SCREEN_PAIR(s)	GetPair(SCREEN_ATTRS(s))
287 #define SET_SCREEN_PAIR(s,p)	SetPair(SCREEN_ATTRS(s), p)
288 
289 /*
290  * Definitions for color pairs
291  */
292 typedef unsigned colorpair_t;	/* type big enough to store PAIR_OF() */
293 #define C_SHIFT 9		/* we need more bits than there are colors */
294 #define C_MASK			((1 << C_SHIFT) - 1)
295 #define PAIR_OF(fg, bg)		((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK))
296 #define isDefaultColor(c)	((c) >= COLOR_DEFAULT || (c) < 0)
297 
298 #define COLOR_DEFAULT		C_MASK
299 
300 #ifdef USE_TERMLIB
301 
302 #undef NCURSES_CH_T		/* this is not a termlib feature */
303 #define NCURSES_CH_T void	/* ...but we need a pointer in SCREEN */
304 
305 #endif	/* USE_TERMLIB */
306 
307 #ifndef USE_TERMLIB
308 struct ldat
309 {
310 	NCURSES_CH_T	*text;		/* text of the line */
311 	NCURSES_SIZE_T	firstchar;	/* first changed character in the line */
312 	NCURSES_SIZE_T	lastchar;	/* last changed character in the line */
313 	NCURSES_SIZE_T	oldindex;	/* index of the line at last update */
314 };
315 #endif	/* USE_TERMLIB */
316 
317 typedef enum {
318 	M_XTERM	= -1		/* use xterm's mouse tracking? */
319 	,M_NONE = 0		/* no mouse device */
320 #if USE_GPM_SUPPORT
321 	,M_GPM			/* use GPM */
322 #endif
323 #if USE_SYSMOUSE
324 	,M_SYSMOUSE		/* FreeBSD sysmouse on console */
325 #endif
326 } MouseType;
327 
328 /*
329  * Structures for scrolling.
330  */
331 
332 typedef struct {
333 	unsigned long hashval;
334 	int oldcount, newcount;
335 	int oldindex, newindex;
336 } HASHMAP;
337 
338 /*
339  * Structures for soft labels.
340  */
341 
342 struct _SLK;
343 
344 #ifndef USE_TERMLIB
345 
346 typedef struct
347 {
348 	char *ent_text;         /* text for the label */
349 	char *form_text;        /* formatted text (left/center/...) */
350 	int ent_x;              /* x coordinate of this field */
351 	char dirty;             /* this label has changed */
352 	char visible;           /* field is visible */
353 } slk_ent;
354 
355 typedef struct _SLK {
356 	char dirty;             /* all labels have changed */
357 	char hidden;            /* soft labels are hidden */
358 	WINDOW *win;
359 	slk_ent *ent;
360 	short  maxlab;          /* number of available labels */
361 	short  labcnt;          /* number of allocated labels */
362 	short  maxlen;          /* length of labels */
363 	NCURSES_CH_T attr;      /* soft label attribute */
364 } SLK;
365 
366 #endif	/* USE_TERMLIB */
367 
368 typedef	struct {
369 	int	line;           /* lines to take, < 0 => from bottom*/
370 	int	(*hook)(WINDOW *, int); /* callback for user        */
371 	WINDOW *w;              /* maybe we need this for cleanup   */
372 } ripoff_t;
373 
374 /*
375  * The SCREEN structure.
376  */
377 
378 struct screen {
379 	int             _ifd;           /* input file ptr for screen        */
380 	FILE            *_ofp;          /* output file ptr for screen       */
381 	char            *_setbuf;       /* buffered I/O for output          */
382 	int		_buffered;      /* setvbuf uses _setbuf data        */
383 	int             _checkfd;       /* filedesc for typeahead check     */
384 	TERMINAL        *_term;         /* terminal type information        */
385 	short           _lines;         /* screen lines                     */
386 	short           _columns;       /* screen columns                   */
387 
388 	short           _lines_avail;   /* lines available for stdscr       */
389 	short           _topstolen;     /* lines stolen from top            */
390 	ripoff_t	_rippedoff[5];	/* list of lines stolen		    */
391 	int		_rip_count;	/* ...and total lines stolen	    */
392 
393 	WINDOW          *_curscr;       /* current screen                   */
394 	WINDOW          *_newscr;       /* virtual screen to be updated to  */
395 	WINDOW          *_stdscr;       /* screen's full-window context     */
396 
397 	struct tries    *_keytry;       /* "Try" for use with keypad mode   */
398 	struct tries    *_key_ok;       /* Disabled keys via keyok(,FALSE)  */
399 	bool            _tried;         /* keypad mode was initialized      */
400 	bool            _keypad_on;     /* keypad mode is currently on      */
401 
402 	bool		_called_wgetch;	/* check for recursion in wgetch()  */
403 	int		_fifo[FIFO_SIZE];	/* input push-back buffer   */
404 	short           _fifohead,      /* head of fifo queue               */
405 	                _fifotail,      /* tail of fifo queue               */
406 	                _fifopeek,      /* where to peek for next char      */
407 	                _fifohold;      /* set if breakout marked           */
408 
409 	int             _endwin;        /* are we out of window mode?       */
410 	NCURSES_CH_T	*_current_attr; /* holds current attributes set     */
411 	int             _coloron;       /* is color enabled?                */
412 	int		_color_defs;	/* are colors modified		    */
413 	int             _cursor;        /* visibility of the cursor         */
414 	int             _cursrow;       /* physical cursor row              */
415 	int             _curscol;       /* physical cursor column           */
416 	bool		_notty;		/* true if we cannot switch non-tty */
417 	int             _nl;            /* True if NL -> CR/NL is on        */
418 	int             _raw;           /* True if in raw mode              */
419 	int             _cbreak;        /* 1 if in cbreak mode              */
420 	                                /* > 1 if in halfdelay mode         */
421 	int             _echo;          /* True if echo on                  */
422 	int             _use_meta;      /* use the meta key?                */
423 	struct _SLK     *_slk;          /* ptr to soft key struct / NULL    */
424         int             slk_format;     /* selected format for this screen  */
425 	/* cursor movement costs; units are 10ths of milliseconds */
426 #if NCURSES_NO_PADDING
427 	int             _no_padding;    /* flag to set if padding disabled  */
428 #endif
429 	int             _char_padding;  /* cost of character put            */
430 	int             _cr_cost;       /* cost of (carriage_return)        */
431 	int             _cup_cost;      /* cost of (cursor_address)         */
432 	int             _home_cost;     /* cost of (cursor_home)            */
433 	int             _ll_cost;       /* cost of (cursor_to_ll)           */
434 #if USE_HARD_TABS
435 	int             _ht_cost;       /* cost of (tab)                    */
436 	int             _cbt_cost;      /* cost of (backtab)                */
437 #endif /* USE_HARD_TABS */
438 	int             _cub1_cost;     /* cost of (cursor_left)            */
439 	int             _cuf1_cost;     /* cost of (cursor_right)           */
440 	int             _cud1_cost;     /* cost of (cursor_down)            */
441 	int             _cuu1_cost;     /* cost of (cursor_up)              */
442 	int             _cub_cost;      /* cost of (parm_cursor_left)       */
443 	int             _cuf_cost;      /* cost of (parm_cursor_right)      */
444 	int             _cud_cost;      /* cost of (parm_cursor_down)       */
445 	int             _cuu_cost;      /* cost of (parm_cursor_up)         */
446 	int             _hpa_cost;      /* cost of (column_address)         */
447 	int             _vpa_cost;      /* cost of (row_address)            */
448 	/* used in tty_update.c, must be chars */
449 	int             _ed_cost;       /* cost of (clr_eos)                */
450 	int             _el_cost;       /* cost of (clr_eol)                */
451 	int             _el1_cost;      /* cost of (clr_bol)                */
452 	int             _dch1_cost;     /* cost of (delete_character)       */
453 	int             _ich1_cost;     /* cost of (insert_character)       */
454 	int             _dch_cost;      /* cost of (parm_dch)               */
455 	int             _ich_cost;      /* cost of (parm_ich)               */
456 	int             _ech_cost;      /* cost of (erase_chars)            */
457 	int             _rep_cost;      /* cost of (repeat_char)            */
458 	int             _hpa_ch_cost;   /* cost of (column_address)         */
459 	int             _cup_ch_cost;   /* cost of (cursor_address)         */
460 	int             _cuf_ch_cost;   /* cost of (parm_cursor_right)      */
461 	int             _inline_cost;   /* cost of inline-move              */
462 	int             _smir_cost;	/* cost of (enter_insert_mode)      */
463 	int             _rmir_cost;	/* cost of (exit_insert_mode)       */
464 	int             _ip_cost;       /* cost of (insert_padding)         */
465 	/* used in lib_mvcur.c */
466 	char *          _address_cursor;
467 	/* used in tty_update.c */
468 	int             _scrolling;     /* 1 if terminal's smart enough to  */
469 
470 	/* used in lib_color.c */
471 	color_t         *_color_table;  /* screen's color palette            */
472 	int             _color_count;   /* count of colors in palette        */
473 	colorpair_t     *_color_pairs;  /* screen's color pair list          */
474 	int             _pair_count;    /* count of color pairs              */
475 #if NCURSES_EXT_FUNCS
476 	bool            _default_color; /* use default colors                */
477 	bool            _has_sgr_39_49; /* has ECMA default color support    */
478 	int             _default_fg;    /* assumed default foreground        */
479 	int             _default_bg;    /* assumed default background        */
480 #endif
481 	chtype          _xmc_suppress;  /* attributes to suppress if xmc     */
482 	chtype          _xmc_triggers;  /* attributes to process if xmc      */
483 	chtype          _acs_map[ACS_LEN]; /* the real alternate-charset map */
484 
485 	/* used in lib_vidattr.c */
486 	bool            _use_rmso;	/* true if we may use 'rmso'         */
487 	bool            _use_rmul;	/* true if we may use 'rmul'         */
488 
489 	/*
490 	 * These data correspond to the state of the idcok() and idlok()
491 	 * functions.  A caveat is in order here:  the XSI and SVr4
492 	 * documentation specify that these functions apply to the window which
493 	 * is given as an argument.  However, ncurses implements this logic
494 	 * only for the newscr/curscr update process, _not_ per-window.
495 	 */
496 	bool            _nc_sp_idlok;
497 	bool            _nc_sp_idcok;
498 #define _nc_idlok SP->_nc_sp_idlok
499 #define _nc_idcok SP->_nc_sp_idcok
500 
501 	/*
502 	 * These are the data that support the mouse interface.
503 	 */
504 	MouseType	_mouse_type;
505 	int             _maxclick;
506 	bool            (*_mouse_event) (SCREEN *);
507 	bool            (*_mouse_inline)(SCREEN *);
508 	bool            (*_mouse_parse) (int);
509 	void            (*_mouse_resume)(SCREEN *);
510 	void            (*_mouse_wrap)  (SCREEN *);
511 	int             _mouse_fd;      /* file-descriptor, if any */
512 	bool		_mouse_active;	/* true if initialized */
513 	NCURSES_CONST char *_mouse_xtermcap; /* string to enable/disable mouse */
514 #if USE_SYSMOUSE
515 	MEVENT		_sysmouse_fifo[FIFO_SIZE];
516 	int		_sysmouse_head;
517 	int		_sysmouse_tail;
518 	int		_sysmouse_char_width;	/* character width */
519 	int		_sysmouse_char_height;	/* character height */
520 	int		_sysmouse_old_buttons;
521 	int		_sysmouse_new_buttons;
522 #endif
523 
524 	/*
525 	 * This supports automatic resizing
526 	 */
527 #if USE_SIZECHANGE
528 	int		(*_resize)(int,int);
529 #endif
530 
531         /*
532 	 * These are data that support the proper handling of the panel stack on an
533 	 * per screen basis.
534 	 */
535         struct panelhook _panelHook;
536 	/*
537 	 * Linked-list of all windows, to support '_nc_resizeall()' and
538 	 * '_nc_freeall()'
539 	 */
540 	WINDOWLIST      *_nc_sp_windows;
541 #define _nc_windows SP->_nc_sp_windows
542 
543 	bool            _sig_winch;
544 	SCREEN          *_next_screen;
545 
546 	/* hashes for old and new lines */
547 	unsigned long	*oldhash, *newhash;
548 	HASHMAP		*hashtab;
549 	int		hashtab_len;
550 
551 	bool            _cleanup;	/* cleanup after int/quit signal */
552 	int             (*_outch)(int);	/* output handler if not putc */
553 
554 	/* recent versions of 'screen' have partially-working support for
555 	 * UTF-8, but do not permit ACS at the same time (see tty_update.c).
556 	 */
557 #if USE_WIDEC_SUPPORT
558 	bool		_legacy_coding;
559 	bool		_screen_acs_fix;
560 #endif
561 	bool		_screen_acs_map[ACS_LEN];
562 };
563 
564 extern NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain;
565 
566 #if NCURSES_NOMACROS
567 #include <nomacros.h>
568 #endif
569 
570 	WINDOWLIST {
571 	WINDOW	win;	/* first, so WINDOW_EXT() works */
572 	WINDOWLIST *next;
573 #ifdef _XOPEN_SOURCE_EXTENDED
574 	char addch_work[(MB_LEN_MAX * 9) + 1];
575 	unsigned addch_used;	/* number of bytes in addch_work[] */
576 	int addch_x;		/* x-position for addch_work[] */
577 	int addch_y;		/* y-position for addch_work[] */
578 #endif
579 };
580 
581 #define WINDOW_EXT(win,field) (((WINDOWLIST *)(win))->field)
582 
583 /* usually in <limits.h> */
584 #ifndef UCHAR_MAX
585 #define UCHAR_MAX 255
586 #endif
587 
588 /* The terminfo source is assumed to be 7-bit ASCII */
589 #define is7bits(c)	((unsigned)(c) < 128)
590 
591 /* Checks for isprint() should be done on 8-bit characters (non-wide) */
592 #define is8bits(c)	((unsigned)(c) <= UCHAR_MAX)
593 
594 #ifndef min
595 #define min(a,b)	((a) > (b)  ?  (b)  :  (a))
596 #endif
597 
598 #ifndef max
599 #define max(a,b)	((a) < (b)  ?  (b)  :  (a))
600 #endif
601 
602 /* usually in <unistd.h> */
603 #ifndef STDIN_FILENO
604 #define STDIN_FILENO 0
605 #endif
606 
607 #ifndef STDOUT_FILENO
608 #define STDOUT_FILENO 1
609 #endif
610 
611 #ifndef STDERR_FILENO
612 #define STDERR_FILENO 2
613 #endif
614 
615 #ifndef EXIT_SUCCESS
616 #define EXIT_SUCCESS 0
617 #endif
618 
619 #ifndef EXIT_FAILURE
620 #define EXIT_FAILURE 1
621 #endif
622 
623 #ifndef R_OK
624 #define	R_OK	4		/* Test for read permission.  */
625 #endif
626 #ifndef W_OK
627 #define	W_OK	2		/* Test for write permission.  */
628 #endif
629 #ifndef X_OK
630 #define	X_OK	1		/* Test for execute permission.  */
631 #endif
632 #ifndef F_OK
633 #define	F_OK	0		/* Test for existence.  */
634 #endif
635 
636 #if HAVE_FCNTL_H
637 #include <fcntl.h>		/* may define O_BINARY	*/
638 #endif
639 
640 #ifndef O_BINARY
641 #define O_BINARY 0
642 #endif
643 
644 #ifdef TRACE
645 #define TRACE_OUTCHARS(n) _nc_outchars += (n);
646 #else
647 #define TRACE_OUTCHARS(n) /* nothing */
648 #endif
649 
650 #define UChar(c)	((unsigned char)(c))
651 #define ChCharOf(c)	((c) & (chtype)A_CHARTEXT)
652 #define ChAttrOf(c)     ((c) & (chtype)A_ATTRIBUTES)
653 
654 #ifndef MB_LEN_MAX
655 #define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */
656 #endif
657 
658 #if USE_WIDEC_SUPPORT /* { */
659 #define isEILSEQ(status) ((status == (size_t)-1) && (errno == EILSEQ))
660 
661 #define init_mb(state)	memset(&state, 0, sizeof(state))
662 
663 #if NCURSES_EXT_COLORS
664 #define NulColor	, 0
665 #else
666 #define NulColor	/* nothing */
667 #endif
668 
669 #define NulChar		0,0,0,0	/* FIXME: see CCHARW_MAX */
670 #define CharOf(c)	((c).chars[0])
671 #define AttrOf(c)	((c).attr)
672 #define AddAttr(c,a)	AttrOf(c) |= a
673 #define RemAttr(c,a)	AttrOf(c) &= ~(a)
674 #define SetAttr(c,a)	AttrOf(c) = a
675 #define NewChar(ch)	{ ChAttrOf(ch), { ChCharOf(ch), NulChar } NulColor }
676 #define NewChar2(c,a)	{ a, { c, NulChar } NulColor }
677 #define CharEq(a,b)	(!memcmp(&a, &b, sizeof(a)))
678 #define SetChar(ch,c,a) do {							    \
679 			    NCURSES_CH_T *_cp = &ch;				    \
680 			    memset(_cp, 0, sizeof(ch));				    \
681 			    _cp->chars[0] = c;					    \
682 			    _cp->attr = a;					    \
683 			    if_EXT_COLORS(SetPair(ch, PAIR_NUMBER(a)));		    \
684 			} while (0)
685 #define CHREF(wch)	(&wch)
686 #define CHDEREF(wch)	(*wch)
687 #define ARG_CH_T	NCURSES_CH_T *
688 #define CARG_CH_T	const NCURSES_CH_T *
689 #define PUTC_DATA	char PUTC_buf[MB_LEN_MAX]; int PUTC_i, PUTC_n; \
690 			mbstate_t PUT_st; wchar_t PUTC_ch
691 #define PUTC_INIT	init_mb (PUT_st);					    \
692 			PUTC_i = 0
693 #define PUTC(ch,b)	do { if(!isWidecExt(ch)) {				    \
694 			if (Charable(ch)) {					    \
695 			    fputc(CharOf(ch), b);				    \
696 			    TRACE_OUTCHARS(1);					    \
697 			} else {						    \
698 			    PUTC_INIT;						    \
699 			    do {						    \
700 				PUTC_ch = PUTC_i < CCHARW_MAX ?			    \
701 					    (ch).chars[PUTC_i] : L'\0';		    \
702 				PUTC_n = wcrtomb(PUTC_buf,			    \
703 						 (ch).chars[PUTC_i], &PUT_st);	    \
704 				if (PUTC_ch == L'\0')				    \
705 				    --PUTC_n;					    \
706 				if (PUTC_n <= 0)				    \
707 				    break;					    \
708 				fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b);	    \
709 				++PUTC_i;					    \
710 			    } while (PUTC_ch != L'\0');				    \
711 			    TRACE_OUTCHARS(PUTC_i);				    \
712 			} } } while (0)
713 
714 #define BLANK		{ WA_NORMAL, {' '} NulColor }
715 #define ZEROS		{ WA_NORMAL, {'\0'} NulColor }
716 #define ISBLANK(ch)	((ch).chars[0] == L' ' && (ch).chars[1] == L'\0')
717 
718 	/*
719 	 * Wide characters cannot be represented in the A_CHARTEXT mask of
720 	 * attr_t's but an application might have set a narrow character there.
721 	 * But even in that case, it would only be a printable character, or
722 	 * zero.  Otherwise we can use those bits to tell if a cell is the
723 	 * first or extension part of a wide character.
724 	 */
725 #define WidecExt(ch)	(AttrOf(ch) & A_CHARTEXT)
726 #define isWidecBase(ch)	(WidecExt(ch) == 1)
727 #define isWidecExt(ch)	(WidecExt(ch) > 1 && WidecExt(ch) < 32)
728 #define SetWidecExt(dst, ext)	AttrOf(dst) &= ~A_CHARTEXT,		\
729 				AttrOf(dst) |= (ext + 1)
730 
731 #define if_WIDEC(code)  code
732 #define Charable(ch)	((SP != 0 && SP->_legacy_coding)		\
733 			 || (AttrOf(ch) & A_ALTCHARSET)			\
734 			 || (!isWidecExt(ch) &&				\
735 			     (ch).chars[1] == L'\0' &&			\
736                              _nc_is_charable(CharOf(ch))))
737 
738 #define L(ch)		L ## ch
739 #else /* }{ */
740 #define CharOf(c)	ChCharOf(c)
741 #define AttrOf(c)	ChAttrOf(c)
742 #define AddAttr(c,a)	c |= a
743 #define RemAttr(c,a)	c &= ~(a & A_ATTRIBUTES)
744 #define SetAttr(c,a)	c = (c & ~A_ATTRIBUTES) | a
745 #define NewChar(ch)	(ch)
746 #define NewChar2(c,a)	(c | a)
747 #define CharEq(a,b)	(a == b)
748 #define SetChar(ch,c,a)	ch = c | a
749 #define CHREF(wch)	wch
750 #define CHDEREF(wch)	wch
751 #define ARG_CH_T	NCURSES_CH_T
752 #define CARG_CH_T	NCURSES_CH_T
753 #define PUTC_DATA	int data = 0
754 #define PUTC(a,b)	do { data = CharOf(ch); putc(data,b); } while (0)
755 
756 #define BLANK		(' '|A_NORMAL)
757 #define ZEROS		('\0'|A_NORMAL)
758 #define ISBLANK(ch)	(CharOf(ch) == ' ')
759 
760 #define isWidecExt(ch)	(0)
761 #define if_WIDEC(code) /* nothing */
762 
763 #define L(ch)		ch
764 #endif /* } */
765 
766 #define AttrOfD(ch)	AttrOf(CHDEREF(ch))
767 #define CharOfD(ch)	CharOf(CHDEREF(ch))
768 #define SetChar2(wch,ch)    SetChar(wch,ChCharOf(ch),ChAttrOf(ch))
769 
770 #define BLANK_ATTR	A_NORMAL
771 #define BLANK_TEXT	L(' ')
772 
773 #define CHANGED     -1
774 
775 #define LEGALYX(w, y, x) \
776 	      ((w) != 0 && \
777 		((x) >= 0 && (x) <= (w)->_maxx && \
778 		 (y) >= 0 && (y) <= (w)->_maxy))
779 
780 #define CHANGED_CELL(line,col) \
781 	if (line->firstchar == _NOCHANGE) \
782 		line->firstchar = line->lastchar = col; \
783 	else if ((col) < line->firstchar) \
784 		line->firstchar = col; \
785 	else if ((col) > line->lastchar) \
786 		line->lastchar = col
787 
788 #define CHANGED_RANGE(line,start,end) \
789 	if (line->firstchar == _NOCHANGE \
790 	 || line->firstchar > (start)) \
791 		line->firstchar = start; \
792 	if (line->lastchar == _NOCHANGE \
793 	 || line->lastchar < (end)) \
794 		line->lastchar = end
795 
796 #define CHANGED_TO_EOL(line,start,end) \
797 	if (line->firstchar == _NOCHANGE \
798 	 || line->firstchar > (start)) \
799 		line->firstchar = start; \
800 	line->lastchar = end
801 
802 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
803 
804 #define FreeIfNeeded(p)  if ((p) != 0) free(p)
805 
806 /* FreeAndNull() is not a comma-separated expression because some compilers
807  * do not accept a mixture of void with values.
808  */
809 #define FreeAndNull(p)   free(p); p = 0
810 
811 #include <nc_alloc.h>
812 
813 /*
814  * Prefixes for call/return points of library function traces.  We use these to
815  * instrument the public functions so that the traces can be easily transformed
816  * into regression scripts.
817  */
818 #define T_CALLED(fmt) "called {" fmt
819 #define T_CREATE(fmt) "create :" fmt
820 #define T_RETURN(fmt) "return }" fmt
821 
822 #ifdef TRACE
823 
824 #define START_TRACE() \
825 	if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
826 	    int t = _nc_getenv_num("NCURSES_TRACE"); \
827 	    if (t >= 0) \
828 		trace((unsigned) t); \
829 	}
830 
831 #define TR(n, a)	if (_nc_tracing & (n)) _tracef a
832 #define T(a)		TR(TRACE_CALLS, a)
833 #define TPUTS_TRACE(s)	_nc_tputs_trace = s;
834 #define TRACE_RETURN(value,type) return _nc_retrace_##type(value)
835 
836 #define returnAttr(code)	TRACE_RETURN(code,attr_t)
837 #define returnBits(code)	TRACE_RETURN(code,unsigned)
838 #define returnBool(code)	TRACE_RETURN(code,bool)
839 #define returnCPtr(code)	TRACE_RETURN(code,cptr)
840 #define returnCVoidPtr(code)	TRACE_RETURN(code,cvoid_ptr)
841 #define returnChar(code)	TRACE_RETURN(code,chtype)
842 #define returnCode(code)	TRACE_RETURN(code,int)
843 #define returnPtr(code)		TRACE_RETURN(code,ptr)
844 #define returnSP(code)		TRACE_RETURN(code,sp)
845 #define returnVoid		T((T_RETURN(""))); return
846 #define returnVoidPtr(code)	TRACE_RETURN(code,void_ptr)
847 #define returnWin(code)		TRACE_RETURN(code,win)
848 
849 extern NCURSES_EXPORT(NCURSES_BOOL)     _nc_retrace_bool (NCURSES_BOOL);
850 extern NCURSES_EXPORT(NCURSES_CONST void *) _nc_retrace_cvoid_ptr (NCURSES_CONST void *);
851 extern NCURSES_EXPORT(SCREEN *)         _nc_retrace_sp (SCREEN *);
852 extern NCURSES_EXPORT(WINDOW *)         _nc_retrace_win (WINDOW *);
853 extern NCURSES_EXPORT(attr_t)           _nc_retrace_attr_t (attr_t);
854 extern NCURSES_EXPORT(char *)           _nc_retrace_ptr (char *);
855 extern NCURSES_EXPORT(char *)           _nc_trace_ttymode(TTY *tty);
856 extern NCURSES_EXPORT(char *)           _nc_varargs (const char *, va_list);
857 extern NCURSES_EXPORT(chtype)           _nc_retrace_chtype (chtype);
858 extern NCURSES_EXPORT(const char *)     _nc_altcharset_name(attr_t, chtype);
859 extern NCURSES_EXPORT(const char *)     _nc_retrace_cptr (const char *);
860 extern NCURSES_EXPORT(int)              _nc_retrace_int (int);
861 extern NCURSES_EXPORT(unsigned)         _nc_retrace_unsigned (unsigned);
862 extern NCURSES_EXPORT(void *)           _nc_retrace_void_ptr (void *);
863 extern NCURSES_EXPORT(void)             _nc_fifo_dump (void);
864 extern NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace;
865 extern NCURSES_EXPORT_VAR(long)         _nc_outchars;
866 extern NCURSES_EXPORT_VAR(unsigned)     _nc_tracing;
867 
868 #if USE_WIDEC_SUPPORT
869 extern NCURSES_EXPORT(const char *) _nc_viswbuf2 (int, const wchar_t *);
870 extern NCURSES_EXPORT(const char *) _nc_viswbufn (const wchar_t *, int);
871 extern NCURSES_EXPORT(const char *) _nc_viscbuf2 (int, const cchar_t *, int);
872 extern NCURSES_EXPORT(const char *) _nc_viscbuf (const cchar_t *, int);
873 #endif
874 
875 #else /* !TRACE */
876 
877 #define START_TRACE() /* nothing */
878 
879 #define T(a)
880 #define TR(n, a)
881 #define TPUTS_TRACE(s)
882 
883 #define returnAttr(code)	return code
884 #define returnBits(code)	return code
885 #define returnBool(code)	return code
886 #define returnCPtr(code)	return code
887 #define returnCVoidPtr(code)	return code
888 #define returnChar(code)	return code
889 #define returnCode(code)	return code
890 #define returnPtr(code)		return code
891 #define returnSP(code)		return code
892 #define returnVoid		return
893 #define returnVoidPtr(code)	return code
894 #define returnWin(code)		return code
895 
896 #endif /* TRACE/!TRACE */
897 
898 extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *);
899 extern NCURSES_EXPORT(const char *) _nc_visbufn (const char *, int);
900 
901 #define empty_module(name) \
902 extern	NCURSES_EXPORT(void) name (void); \
903 	NCURSES_EXPORT(void) name (void) { }
904 
905 #define ALL_BUT_COLOR ((chtype)~(A_COLOR))
906 #define NONBLANK_ATTR (A_NORMAL|A_BOLD|A_DIM|A_BLINK)
907 #define XMC_CHANGES(c) ((c) & SP->_xmc_suppress)
908 
909 #define toggle_attr_on(S,at) {\
910    if (PAIR_NUMBER(at) > 0) {\
911       (S) = ((S) & ALL_BUT_COLOR) | (at);\
912    } else {\
913       (S) |= (at);\
914    }\
915    TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
916 
917 
918 #define toggle_attr_off(S,at) {\
919    if (PAIR_NUMBER(at) > 0) {\
920       (S) &= ~(at|A_COLOR);\
921    } else {\
922       (S) &= ~(at);\
923    }\
924    TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
925 
926 #define DelCharCost(count) \
927 		((parm_dch != 0) \
928 		? SP->_dch_cost \
929 		: ((delete_character != 0) \
930 			? (SP->_dch1_cost * count) \
931 			: INFINITY))
932 
933 #define InsCharCost(count) \
934 		((parm_ich != 0) \
935 		? SP->_ich_cost \
936 		: ((enter_insert_mode && exit_insert_mode) \
937 		  ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) \
938 		  : ((insert_character != 0) \
939 		    ? ((SP->_ich1_cost + SP->_ip_cost) * count) \
940 		    : INFINITY)))
941 
942 #if USE_XMC_SUPPORT
943 #define UpdateAttrs(c)	if (!SameAttrOf(SCREEN_ATTRS(SP), c)) { \
944 				attr_t chg = AttrOf(SCREEN_ATTRS(SP)); \
945 				VIDATTR(AttrOf(c), GetPair(c)); \
946 				if (magic_cookie_glitch > 0 \
947 				 && XMC_CHANGES((chg ^ AttrOf(SCREEN_ATTRS(SP))))) { \
948 					T(("%s @%d before glitch %d,%d", \
949 						__FILE__, __LINE__, \
950 						SP->_cursrow, \
951 						SP->_curscol)); \
952 					_nc_do_xmc_glitch(chg); \
953 				} \
954 			}
955 #else
956 #define UpdateAttrs(c)	if (!SameAttrOf(SCREEN_ATTRS(SP), c)) \
957 				VIDATTR(AttrOf(c), GetPair(c));
958 #endif
959 
960 /*
961  * Macros to make additional parameter to implement wgetch_events()
962  */
963 #ifdef NCURSES_WGETCH_EVENTS
964 #define EVENTLIST_0th(param) param
965 #define EVENTLIST_1st(param) param
966 #define EVENTLIST_2nd(param) , param
967 #else
968 #define EVENTLIST_0th(param) void
969 #define EVENTLIST_1st(param) /* nothing */
970 #define EVENTLIST_2nd(param) /* nothing */
971 #endif
972 
973 #if NCURSES_EXPANDED && NCURSES_EXT_FUNCS
974 
975 #undef  toggle_attr_on
976 #define toggle_attr_on(S,at) _nc_toggle_attr_on(&(S), at)
977 extern NCURSES_EXPORT(void) _nc_toggle_attr_on (attr_t *, attr_t);
978 
979 #undef  toggle_attr_off
980 #define toggle_attr_off(S,at) _nc_toggle_attr_off(&(S), at)
981 extern NCURSES_EXPORT(void) _nc_toggle_attr_off (attr_t *, attr_t);
982 
983 #undef  DelCharCost
984 #define DelCharCost(count) _nc_DelCharCost(count)
985 extern NCURSES_EXPORT(int) _nc_DelCharCost (int);
986 
987 #undef  InsCharCost
988 #define InsCharCost(count) _nc_InsCharCost(count)
989 extern NCURSES_EXPORT(int) _nc_InsCharCost (int);
990 
991 #undef  UpdateAttrs
992 #define UpdateAttrs(c) _nc_UpdateAttrs(c)
993 extern NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T);
994 
995 #else
996 
997 extern NCURSES_EXPORT(void) _nc_expanded (void);
998 
999 #endif
1000 
1001 #if !HAVE_GETCWD
1002 #define getcwd(buf,len) getwd(buf)
1003 #endif
1004 
1005 /* charable.c */
1006 #if USE_WIDEC_SUPPORT
1007 extern NCURSES_EXPORT(bool) _nc_is_charable(wchar_t);
1008 extern NCURSES_EXPORT(int) _nc_to_char(wint_t);
1009 extern NCURSES_EXPORT(wint_t) _nc_to_widechar(int);
1010 #endif
1011 
1012 /* doupdate.c */
1013 #if USE_XMC_SUPPORT
1014 extern NCURSES_EXPORT(void) _nc_do_xmc_glitch (attr_t);
1015 #endif
1016 
1017 /* hardscroll.c */
1018 #if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
1019 extern NCURSES_EXPORT(void) _nc_linedump (void);
1020 #endif
1021 
1022 /* lib_acs.c */
1023 extern NCURSES_EXPORT(void) _nc_init_acs (void);	/* corresponds to traditional 'init_acs()' */
1024 extern NCURSES_EXPORT(int) _nc_msec_cost (const char *const, int);  /* used by 'tack' program */
1025 
1026 /* lib_addch.c */
1027 #if USE_WIDEC_SUPPORT
1028 NCURSES_EXPORT(int) _nc_build_wch(WINDOW *win, ARG_CH_T ch);
1029 #endif
1030 
1031 /* lib_addstr.c */
1032 #if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
1033 extern NCURSES_EXPORT(int) _nc_wchstrlen(const cchar_t *);
1034 #endif
1035 
1036 /* lib_color.c */
1037 extern NCURSES_EXPORT(bool) _nc_reset_colors(void);
1038 
1039 /* lib_getch.c */
1040 extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, unsigned long *, int EVENTLIST_2nd(_nc_eventlist *));
1041 
1042 /* lib_insch.c */
1043 extern NCURSES_EXPORT(int) _nc_insert_ch(WINDOW *, chtype);
1044 
1045 /* lib_mvcur.c */
1046 #define INFINITY	1000000	/* cost: too high to use */
1047 
1048 extern NCURSES_EXPORT(void) _nc_mvcur_init (void);
1049 extern NCURSES_EXPORT(void) _nc_mvcur_resume (void);
1050 extern NCURSES_EXPORT(void) _nc_mvcur_wrap (void);
1051 
1052 extern NCURSES_EXPORT(int) _nc_scrolln (int, int, int, int);
1053 
1054 extern NCURSES_EXPORT(void) _nc_screen_init (void);
1055 extern NCURSES_EXPORT(void) _nc_screen_resume (void);
1056 extern NCURSES_EXPORT(void) _nc_screen_wrap (void);
1057 
1058 /* lib_mouse.c */
1059 extern NCURSES_EXPORT(int) _nc_has_mouse (void);
1060 
1061 /* lib_mvcur.c */
1062 #define INFINITY	1000000	/* cost: too high to use */
1063 #define BAUDBYTE	9	/* 9 = 7 bits + 1 parity + 1 stop */
1064 
1065 /* lib_setup.c */
1066 extern NCURSES_EXPORT(char *) _nc_get_locale(void);
1067 extern NCURSES_EXPORT(void) _nc_set_locale(char *);
1068 extern NCURSES_EXPORT(int) _nc_unicode_locale(void);
1069 extern NCURSES_EXPORT(int) _nc_overridden_locale(void);
1070 extern NCURSES_EXPORT(int) _nc_locale_breaks_acs(void);
1071 extern NCURSES_EXPORT(int) _nc_setupterm(NCURSES_CONST char *, int , int *, bool);
1072 
1073 /* lib_wacs.c */
1074 #if USE_WIDEC_SUPPORT
1075 extern NCURSES_EXPORT(void) _nc_init_wacs(void);
1076 #endif
1077 
1078 typedef struct {
1079     char *s_head;	/* beginning of the string (may be null) */
1080     char *s_tail;	/* end of the string (may be null) */
1081     size_t s_size;	/* current remaining size available */
1082     size_t s_init;	/* total size available */
1083 } string_desc;
1084 
1085 /* strings.c */
1086 extern NCURSES_EXPORT(string_desc *) _nc_str_init (string_desc *, char *, size_t);
1087 extern NCURSES_EXPORT(string_desc *) _nc_str_null (string_desc *, size_t);
1088 extern NCURSES_EXPORT(string_desc *) _nc_str_copy (string_desc *, string_desc *);
1089 extern NCURSES_EXPORT(bool) _nc_safe_strcat (string_desc *, const char *);
1090 extern NCURSES_EXPORT(bool) _nc_safe_strcpy (string_desc *, const char *);
1091 
1092 #if !HAVE_STRSTR
1093 #define strstr _nc_strstr
1094 extern NCURSES_EXPORT(char *) _nc_strstr (const char *, const char *);
1095 #endif
1096 
1097 /* safe_sprintf.c */
1098 extern NCURSES_EXPORT(char *) _nc_printf_string (const char *, va_list)
1099 		GCC_PRINTFLIKE(1,0);
1100 
1101 /* tries.c */
1102 extern NCURSES_EXPORT(void) _nc_add_to_try (struct tries **, const char *, unsigned short);
1103 extern NCURSES_EXPORT(char *) _nc_expand_try (struct tries *, unsigned short, int *, size_t);
1104 extern NCURSES_EXPORT(int) _nc_remove_key (struct tries **, unsigned short);
1105 extern NCURSES_EXPORT(int) _nc_remove_string (struct tries **, const char *);
1106 
1107 /* elsewhere ... */
1108 extern NCURSES_EXPORT(ENTRY *) _nc_delink_entry(ENTRY *, TERMTYPE *);
1109 extern NCURSES_EXPORT(WINDOW *) _nc_makenew (int, int, int, int, int);
1110 extern NCURSES_EXPORT(char *) _nc_home_terminfo (void);
1111 extern NCURSES_EXPORT(char *) _nc_trace_buf (int, size_t);
1112 extern NCURSES_EXPORT(char *) _nc_trace_bufcat (int, const char *);
1113 extern NCURSES_EXPORT(int) _nc_access (const char *, int);
1114 extern NCURSES_EXPORT(int) _nc_baudrate (int);
1115 extern NCURSES_EXPORT(int) _nc_freewin (WINDOW *);
1116 extern NCURSES_EXPORT(int) _nc_getenv_num (const char *);
1117 extern NCURSES_EXPORT(int) _nc_keypad (bool);
1118 extern NCURSES_EXPORT(int) _nc_ospeed (int);
1119 extern NCURSES_EXPORT(int) _nc_outch (int);
1120 extern NCURSES_EXPORT(int) _nc_setupscreen (short, short const, FILE *);
1121 extern NCURSES_EXPORT(int) _nc_timed_wait(int, int, int * EVENTLIST_2nd(_nc_eventlist *));
1122 extern NCURSES_EXPORT(void) _nc_do_color (int, int, bool, int (*)(int));
1123 extern NCURSES_EXPORT(void) _nc_flush (void);
1124 extern NCURSES_EXPORT(void) _nc_free_entry(ENTRY *, TERMTYPE *);
1125 extern NCURSES_EXPORT(void) _nc_freeall (void);
1126 extern NCURSES_EXPORT(void) _nc_hash_map (void);
1127 extern NCURSES_EXPORT(void) _nc_init_keytry (void);
1128 extern NCURSES_EXPORT(void) _nc_keep_tic_dir (const char *);
1129 extern NCURSES_EXPORT(void) _nc_make_oldhash (int i);
1130 extern NCURSES_EXPORT(void) _nc_scroll_oldhash (int n, int top, int bot);
1131 extern NCURSES_EXPORT(void) _nc_scroll_optimize (void);
1132 extern NCURSES_EXPORT(void) _nc_set_buffer (FILE *, bool);
1133 extern NCURSES_EXPORT(void) _nc_signal_handler (bool);
1134 extern NCURSES_EXPORT(void) _nc_synchook (WINDOW *);
1135 extern NCURSES_EXPORT(void) _nc_trace_tries (struct tries *);
1136 
1137 #if NO_LEAKS
1138 extern NCURSES_EXPORT(void) _nc_alloc_entry_leaks(void);
1139 extern NCURSES_EXPORT(void) _nc_captoinfo_leaks(void);
1140 extern NCURSES_EXPORT(void) _nc_comp_scan_leaks(void);
1141 #endif
1142 
1143 #ifndef USE_TERMLIB
1144 extern NCURSES_EXPORT(NCURSES_CH_T) _nc_render (WINDOW *, NCURSES_CH_T);
1145 extern NCURSES_EXPORT(int) _nc_waddch_nosync (WINDOW *, const NCURSES_CH_T);
1146 extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, short const, short const, NCURSES_CH_T);
1147 #endif
1148 
1149 #if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
1150 #ifdef linux
1151 extern NCURSES_EXPORT(size_t) _nc_wcrtomb (char *, wchar_t, mbstate_t *);
1152 #else
1153 #define _nc_wcrtomb(s,wc,ps) wcrtomb(s,wc,ps)
1154 #endif
1155 #endif
1156 
1157 #if USE_SIZECHANGE
1158 extern NCURSES_EXPORT(void) _nc_update_screensize (void);
1159 #endif
1160 
1161 #if HAVE_RESIZETERM
1162 extern NCURSES_EXPORT(void) _nc_resize_margins (WINDOW *);
1163 #else
1164 #define _nc_resize_margins(wp) /* nothing */
1165 #endif
1166 
1167 #ifdef NCURSES_WGETCH_EVENTS
1168 extern NCURSES_EXPORT(int) _nc_eventlist_timeout(_nc_eventlist *);
1169 #else
1170 #define wgetch_events(win, evl) wgetch(win)
1171 #define wgetnstr_events(win, str, maxlen, evl) wgetnstr(win, str, maxlen)
1172 #endif
1173 
1174 /*
1175  * Not everyone has vsscanf(), but we'd like to use it for scanw().
1176  */
1177 #if !HAVE_VSSCANF
1178 extern int vsscanf(const char *str, const char *format, va_list __arg);
1179 #endif
1180 
1181 /* scroll indices */
1182 extern NCURSES_EXPORT_VAR(int *) _nc_oldnums;
1183 
1184 #define USE_SETBUF_0 0
1185 
1186 #define NC_BUFFERED(flag) _nc_set_buffer(SP->_ofp, flag)
1187 
1188 #define NC_OUTPUT ((SP != 0) ? SP->_ofp : stdout)
1189 
1190 /*
1191  * On systems with a broken linker, define 'SP' as a function to force the
1192  * linker to pull in the data-only module with 'SP'.
1193  */
1194 #if BROKEN_LINKER
1195 #define SP _nc_screen()
1196 extern NCURSES_EXPORT(SCREEN *) _nc_screen (void);
1197 extern NCURSES_EXPORT(int) _nc_alloc_screen (void);
1198 extern NCURSES_EXPORT(void) _nc_set_screen (SCREEN *);
1199 #else
1200 /* current screen is private data; avoid possible linking conflicts too */
1201 extern NCURSES_EXPORT_VAR(SCREEN *) SP;
1202 #define _nc_alloc_screen() ((SP = typeCalloc(SCREEN, 1)) != 0)
1203 #define _nc_set_screen(sp) SP = sp
1204 #endif
1205 
1206 /*
1207  * We don't want to use the lines or columns capabilities internally, because
1208  * if the application is running multiple screens under X, it's quite possible
1209  * they could all have type xterm but have different sizes!  So...
1210  */
1211 #define screen_lines	SP->_lines
1212 #define screen_columns	SP->_columns
1213 
1214 extern NCURSES_EXPORT_VAR(int) _nc_slk_format;  /* != 0 if slk_init() called */
1215 extern NCURSES_EXPORT(int) _nc_slk_initialize (WINDOW *, int);
1216 
1217 /*
1218  * Some constants related to SLK's
1219  */
1220 #define MAX_SKEY_OLD	   8	/* count of soft keys */
1221 #define MAX_SKEY_LEN_OLD   8	/* max length of soft key text */
1222 #define MAX_SKEY_PC       12    /* This is what most PC's have */
1223 #define MAX_SKEY_LEN_PC    5
1224 
1225 /* Macro to check whether or not we use a standard format */
1226 #define SLK_STDFMT(fmt) (fmt < 3)
1227 /* Macro to determine height of label window */
1228 #define SLK_LINES(fmt)  (SLK_STDFMT(fmt) ? 1 : ((fmt) - 2))
1229 
1230 #define MAX_SKEY(fmt)     (SLK_STDFMT(fmt)? MAX_SKEY_OLD : MAX_SKEY_PC)
1231 #define MAX_SKEY_LEN(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_LEN_OLD : MAX_SKEY_LEN_PC)
1232 
1233 extern NCURSES_EXPORT(int) _nc_ripoffline (int line, int (*init)(WINDOW *,int));
1234 
1235 /*
1236  * Common error messages
1237  */
1238 #define MSG_NO_MEMORY "Out of memory"
1239 #define MSG_NO_INPUTS "Premature EOF"
1240 
1241 #ifdef __cplusplus
1242 }
1243 #endif
1244 
1245 #endif /* CURSES_PRIV_H */
1246