xref: /openbsd-src/lib/libcurses/curses.priv.h (revision 24dc1c5e148b865950fd90786c4d6bbc53d0845d)
1 /*	$OpenBSD: curses.priv.h,v 1.19 1999/06/27 08:15:19 millert Exp $	*/
2 
3 /****************************************************************************
4  * Copyright (c) 1998 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  ****************************************************************************/
35 
36 
37 /*
38  * $From: curses.priv.h,v 1.141 1999/06/26 22:00:49 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 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 #include <ncurses_cfg.h>
55 
56 #if USE_RCS_IDS
57 #define MODULE_ID(id) static const char Ident[] = id;
58 #else
59 #define MODULE_ID(id) /*nothing*/
60 #endif
61 
62 #include <stdlib.h>
63 #include <string.h>
64 #include <sys/types.h>
65 
66 #if HAVE_UNISTD_H
67 #include <unistd.h>
68 #endif
69 
70 #if HAVE_SYS_BSDTYPES_H
71 #include <sys/bsdtypes.h>	/* needed for ISC */
72 #endif
73 
74 #if HAVE_LIMITS_H
75 # include <limits.h>
76 #elif HAVE_SYS_PARAM_H
77 # include <sys/param.h>
78 #endif
79 
80 #ifndef PATH_MAX
81 # if defined(_POSIX_PATH_MAX)
82 #  define PATH_MAX _POSIX_PATH_MAX
83 # elif defined(MAXPATHLEN)
84 #  define PATH_MAX MAXPATHLEN
85 # else
86 #  define PATH_MAX 255	/* the Posix minimum path-size */
87 # endif
88 #endif
89 
90 #include <assert.h>
91 #include <stdio.h>
92 
93 #include <errno.h>
94 
95 #if DECL_ERRNO
96 extern int errno;
97 #endif
98 
99 #include <nc_panel.h>
100 
101 /* Some systems have a broken 'select()', but workable 'poll()'.  Use that */
102 #if HAVE_POLL && HAVE_SYS_STROPTS_H && HAVE_POLL_H
103 #define USE_FUNC_POLL 1
104 #else
105 #define USE_FUNC_POLL 0
106 #endif
107 
108 /* Alessandro Rubini's GPM (general-purpose mouse) */
109 #if HAVE_LIBGPM && HAVE_GPM_H
110 #define USE_GPM_SUPPORT 1
111 #else
112 #define USE_GPM_SUPPORT 0
113 #endif
114 
115 /* QNX mouse support */
116 #if defined(__QNX__) && !defined(__QNXNTO__)
117 #define USE_QNX_MOUSE 1
118 #else
119 #define USE_QNX_MOUSE 0
120 #endif
121 
122 /* EMX mouse support */
123 #ifdef __EMX__
124 #define USE_EMX_MOUSE
125 #endif
126 
127 #define DEFAULT_MAXCLICK 166
128 #define EV_MAX		8	/* size of mouse circular event queue */
129 
130 /*
131  * If we don't have signals to support it, don't add a sigwinch handler.
132  * In any case, resizing is an extended feature.  Use it if we've got it.
133  */
134 #ifndef NCURSES_EXT_FUNCS
135 #undef HAVE_SIZECHANGE
136 #endif
137 
138 #if HAVE_SIZECHANGE
139 #define USE_SIZECHANGE 1
140 #else
141 #undef USE_SIGWINCH
142 #endif
143 
144 /*
145  * Not all platforms have memmove; some have an equivalent bcopy.  (Some may
146  * have neither).
147  */
148 #if USE_OK_BCOPY
149 #define memmove(d,s,n) bcopy(s,d,n)
150 #elif USE_MY_MEMMOVE
151 #define memmove(d,s,n) _nc_memmove(d,s,n)
152 extern void * _nc_memmove(void *, const void *, size_t);
153 #endif
154 
155 /*
156  * Scroll hints are useless when hashmap is used
157  */
158 #if !USE_SCROLL_HINTS
159 #if !USE_HASHMAP
160 #define USE_SCROLL_HINTS 1
161 #else
162 #define USE_SCROLL_HINTS 0
163 #endif
164 #endif
165 
166 #if USE_SCROLL_HINTS
167 #define if_USE_SCROLL_HINTS(stmt) stmt
168 #else
169 #define if_USE_SCROLL_HINTS(stmt) /*nothing*/
170 #endif
171 
172 /*
173  * Note:  ht/cbt expansion flakes out randomly under Linux 1.1.47, but only
174  * when we're throwing control codes at the screen at high volume.  To see
175  * this, re-enable USE_HARD_TABS and run worm for a while.  Other systems
176  * probably don't want to define this either due to uncertainties about tab
177  * delays and expansion in raw mode.
178  */
179 
180 struct tries {
181 	struct tries    *child;     /* ptr to child.  NULL if none          */
182 	struct tries    *sibling;   /* ptr to sibling.  NULL if none        */
183 	unsigned char    ch;        /* character at this node               */
184 	unsigned short   value;     /* code of string so far.  0 if none.   */
185 };
186 
187 /*
188  * Definitions for color pairs
189  */
190 #define C_SHIFT 8		/* we need more bits than there are colors */
191 #define C_MASK  ((1 << C_SHIFT) - 1)
192 
193 #define PAIR_OF(fg, bg) ((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK))
194 
195 /*
196  * Common/troublesome character definitions
197  */
198 #define L_BRACE '{'
199 #define R_BRACE '}'
200 #define S_QUOTE '\''
201 
202 /*
203  * Structure for palette tables
204  */
205 
206 typedef struct
207 {
208     short red, green, blue;
209 }
210 color_t;
211 
212 #define MAXCOLUMNS    135
213 #define MAXLINES      66
214 #define FIFO_SIZE     MAXCOLUMNS+2  /* for nocbreak mode input */
215 
216 #define ACS_LEN       128
217 
218 #define WINDOWLIST struct _win_list
219 
220 #include <curses.h>	/* we'll use -Ipath directive to get the right one! */
221 
222 /*
223  * Structure for soft labels.
224  */
225 
226 typedef struct
227 {
228 	char *text;             /* text for the label */
229 	char *form_text;        /* formatted text (left/center/...) */
230 	int x;                  /* x coordinate of this field */
231 	char dirty;             /* this label has changed */
232 	char visible;           /* field is visible */
233 } slk_ent;
234 
235 typedef struct {
236 	char dirty;             /* all labels have changed */
237 	char hidden;            /* soft labels are hidden */
238 	struct _win_st *win;
239 	slk_ent *ent;
240 	char*  buffer;           /* buffer for labels */
241 	short  maxlab;           /* number of available labels */
242 	short  labcnt;           /* number of allocated labels */
243 	short  maxlen;           /* length of labels */
244         chtype attr;             /* soft label attribute */
245 } SLK;
246 
247 struct screen {
248 	int             _ifd;           /* input file ptr for screen        */
249 	FILE            *_ofp;          /* output file ptr for screen       */
250 	char            *_setbuf;       /* buffered I/O for output          */
251 	int		_buffered;      /* setvbuf uses _setbuf data        */
252 	int             _checkfd;       /* filedesc for typeahead check     */
253 	struct term     *_term;         /* terminal type information        */
254 	short           _lines;         /* screen lines                     */
255 	short           _columns;       /* screen columns                   */
256 	short           _lines_avail;   /* lines available for stdscr       */
257 	short           _topstolen;     /* lines stolen from top            */
258 
259 	WINDOW          *_curscr;       /* current screen                   */
260 	WINDOW          *_newscr;       /* virtual screen to be updated to  */
261 	WINDOW          *_stdscr;       /* screen's full-window context     */
262 
263 	struct tries    *_keytry;       /* "Try" for use with keypad mode   */
264 	struct tries    *_key_ok;       /* Disabled keys via keyok(,FALSE)  */
265 	int             _tried;         /* keypad mode was initialized      */
266 
267 	unsigned int    _fifo[FIFO_SIZE];       /* input push-back buffer   */
268 	short           _fifohead,      /* head of fifo queue               */
269 	                _fifotail,      /* tail of fifo queue               */
270 	                _fifopeek,      /* where to peek for next char      */
271 	                _fifohold;      /* set if breakout marked           */
272 
273 	int             _endwin;        /* are we out of window mode?       */
274 	unsigned long   _current_attr;  /* terminal attribute current set   */
275 	int             _coloron;       /* is color enabled?                */
276 	int             _cursor;        /* visibility of the cursor         */
277 	int             _cursrow;       /* physical cursor row              */
278 	int             _curscol;       /* physical cursor column           */
279 	int             _nl;            /* True if NL -> CR/NL is on        */
280 	int             _raw;           /* True if in raw mode              */
281 	int             _cbreak;        /* 1 if in cbreak mode              */
282 	                                /* > 1 if in halfdelay mode         */
283 	int             _echo;          /* True if echo on                  */
284 	int             _use_meta;      /* use the meta key?                */
285 	SLK             *_slk;          /* ptr to soft key struct / NULL    */
286         int             slk_format;     /* selected format for this screen  */
287 	/* cursor movement costs; units are 10ths of milliseconds */
288 #ifdef NCURSES_NO_PADDING
289 	int             _no_padding;    /* flag to set if padding disabled  */
290 #endif
291 	int             _char_padding;  /* cost of character put            */
292 	int             _cr_cost;       /* cost of (carriage_return)        */
293 	int             _cup_cost;      /* cost of (cursor_address)         */
294 	int             _home_cost;     /* cost of (cursor_home)            */
295 	int             _ll_cost;       /* cost of (cursor_to_ll)           */
296 #if USE_HARD_TABS
297 	int             _ht_cost;       /* cost of (tab)                    */
298 	int             _cbt_cost;      /* cost of (backtab)                */
299 #endif /* USE_HARD_TABS */
300 	int             _cub1_cost;     /* cost of (cursor_left)            */
301 	int             _cuf1_cost;     /* cost of (cursor_right)           */
302 	int             _cud1_cost;     /* cost of (cursor_down)            */
303 	int             _cuu1_cost;     /* cost of (cursor_up)              */
304 	int             _cub_cost;      /* cost of (parm_cursor_left)       */
305 	int             _cuf_cost;      /* cost of (parm_cursor_right)      */
306 	int             _cud_cost;      /* cost of (parm_cursor_down)       */
307 	int             _cuu_cost;      /* cost of (parm_cursor_up)         */
308 	int             _hpa_cost;      /* cost of (column_address)         */
309 	int             _vpa_cost;      /* cost of (row_address)            */
310 	/* used in lib_doupdate.c, must be chars */
311 	int             _ed_cost;       /* cost of (clr_eos)                */
312 	int             _el_cost;       /* cost of (clr_eol)                */
313 	int             _el1_cost;      /* cost of (clr_bol)                */
314 	int             _dch1_cost;     /* cost of (delete_character)       */
315 	int             _ich1_cost;     /* cost of (insert_character)       */
316 	int             _dch_cost;      /* cost of (parm_dch)               */
317 	int             _ich_cost;      /* cost of (parm_ich)               */
318 	int             _ech_cost;      /* cost of (erase_chars)            */
319 	int             _rep_cost;      /* cost of (repeat_char)            */
320 	int             _hpa_ch_cost;   /* cost of (column_address)         */
321 	int             _cup_ch_cost;   /* cost of (cursor_address)         */
322 	int             _smir_cost;	/* cost of (enter_insert_mode)      */
323 	int             _rmir_cost;	/* cost of (exit_insert_mode)       */
324 	int             _ip_cost;       /* cost of (insert_padding)         */
325 	/* used in lib_mvcur.c */
326 	char *          _address_cursor;
327 	int             _carriage_return_length;
328 	int             _cursor_home_length;
329 	int             _cursor_to_ll_length;
330 	int             _scrolling;     /* 1 if terminal's smart enough to  */
331 
332 	/* used in lib_color.c */
333 	color_t         *_color_table;  /* screen's color palette            */
334 	int             _color_count;   /* count of colors in palette        */
335 	unsigned short  *_color_pairs;  /* screen's color pair list          */
336 	int             _pair_count;    /* count of color pairs              */
337 	int             _default_color; /* use default colors                */
338 	chtype          _xmc_suppress;  /* attributes to suppress if xmc     */
339 	chtype          _xmc_triggers;  /* attributes to process if xmc      */
340 	chtype          _acs_map[ACS_LEN];
341 
342 	/* used in lib_vidattr.c */
343 	bool            _use_rmso;	/* true if we may use 'rmso'         */
344 	bool            _use_rmul;	/* true if we may use 'rmul'         */
345 
346 	/*
347 	 * These data correspond to the state of the idcok() and idlok()
348 	 * functions.  A caveat is in order here:  the XSI and SVr4
349 	 * documentation specify that these functions apply to the window which
350 	 * is given as an argument.  However, ncurses implements this logic
351 	 * only for the newscr/curscr update process, _not_ per-window.
352 	 */
353 	bool            _nc_sp_idlok;
354 	bool            _nc_sp_idcok;
355 #define _nc_idlok SP->_nc_sp_idlok
356 #define _nc_idcok SP->_nc_sp_idcok
357 
358 	/*
359 	 * These are the data that support the mouse interface.
360 	 */
361 	int             _maxclick;
362 	bool            (*_mouse_event) (SCREEN *);
363 	bool            (*_mouse_inline)(SCREEN *);
364 	bool            (*_mouse_parse) (int);
365 	void            (*_mouse_resume)(SCREEN *);
366 	void            (*_mouse_wrap)  (SCREEN *);
367 	int             _mouse_fd;      /* file-descriptor, if any */
368 
369 	/*
370 	 * This supports automatic resizing
371 	 */
372 #if USE_SIZECHANGE
373 	int		(*_resize)(int,int);
374 #endif
375 
376         /*
377 	 * These are data that support the proper handling of the panel stack on an
378 	 * per screen basis.
379 	 */
380         struct panelhook _panelHook;
381 	/*
382 	 * Linked-list of all windows, to support '_nc_resizeall()' and
383 	 * '_nc_freeall()'
384 	 */
385 	WINDOWLIST      *_nc_sp_windows;
386 #define _nc_windows SP->_nc_sp_windows
387 
388 	bool            _sig_winch;
389 	SCREEN          *_next_screen;
390 
391 	/* hashes for old and new lines */
392 	unsigned long	*oldhash, *newhash;
393 };
394 
395 extern SCREEN *_nc_screen_chain;
396 
397 #ifdef NCURSES_NOMACROS
398 #include <nomacros.h>
399 #endif
400 
401 	WINDOWLIST {
402 	WINDOWLIST *next;
403 	WINDOW	*win;
404 };
405 
406 typedef	struct {
407 	int	line;                   /* lines to take, < 0 => from bottom*/
408 	int	(*hook)(struct _win_st *, int); /* callback for user        */
409 	struct _win_st *w;              /* maybe we need this for cleanup   */
410 } ripoff_t;
411 
412 /* The terminfo source is assumed to be 7-bit ASCII */
413 #define is7bits(c)	((unsigned)(c) < 128)
414 
415 #ifndef min
416 #define min(a,b)	((a) > (b)  ?  (b)  :  (a))
417 #endif
418 
419 #ifndef max
420 #define max(a,b)	((a) < (b)  ?  (b)  :  (a))
421 #endif
422 
423 /* usually in <unistd.h> */
424 #ifndef STDOUT_FILENO
425 #define STDOUT_FILENO 1
426 #endif
427 
428 #ifndef STDERR_FILENO
429 #define STDERR_FILENO 2
430 #endif
431 
432 #ifndef EXIT_SUCCESS
433 #define EXIT_SUCCESS 0
434 #endif
435 
436 #ifndef EXIT_FAILURE
437 #define EXIT_FAILURE 1
438 #endif
439 
440 #ifndef R_OK
441 #define	R_OK	4		/* Test for read permission.  */
442 #endif
443 #ifndef W_OK
444 #define	W_OK	2		/* Test for write permission.  */
445 #endif
446 #ifndef X_OK
447 #define	X_OK	1		/* Test for execute permission.  */
448 #endif
449 #ifndef F_OK
450 #define	F_OK	0		/* Test for existence.  */
451 #endif
452 
453 #define TextOf(c)    ((c) & (chtype)A_CHARTEXT)
454 #define AttrOf(c)    ((c) & (chtype)A_ATTRIBUTES)
455 
456 #define BLANK        (' '|A_NORMAL)
457 
458 #define CHANGED     -1
459 
460 #define CHANGED_CELL(line,col) \
461 	if (line->firstchar == _NOCHANGE) \
462 		line->firstchar = line->lastchar = col; \
463 	else if ((col) < line->firstchar) \
464 		line->firstchar = col; \
465 	else if ((col) > line->lastchar) \
466 		line->lastchar = col
467 
468 #define CHANGED_RANGE(line,start,end) \
469 	if (line->firstchar == _NOCHANGE \
470 	 || line->firstchar > (start)) \
471 		line->firstchar = start; \
472 	if (line->lastchar == _NOCHANGE \
473 	 || line->lastchar < (end)) \
474 		line->lastchar = end
475 
476 #define CHANGED_TO_EOL(line,start,end) \
477 	if (line->firstchar == _NOCHANGE \
478 	 || line->firstchar > (start)) \
479 		line->firstchar = start; \
480 	line->lastchar = end
481 
482 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
483 #define typeMalloc(type,elts) (type *)malloc((elts)*sizeof(type))
484 #define typeCalloc(type,elts) (type *)calloc((elts),sizeof(type))
485 #define typeRealloc(type,elts,ptr) (type *)_nc_doalloc(ptr, (elts)*sizeof(type))
486 #define FreeIfNeeded(p)  if(p != 0) free(p)
487 #define FreeAndNull(p)   free(p); p = 0
488 
489 #include <nc_alloc.h>
490 
491 /*
492  * Prefixes for call/return points of library function traces.  We use these to
493  * instrument the public functions so that the traces can be easily transformed
494  * into regression scripts.
495  */
496 #define T_CALLED(fmt) "called " fmt
497 #define T_CREATE(fmt) "create " fmt
498 #define T_RETURN(fmt) "return " fmt
499 
500 #ifdef TRACE
501 #define TR(n, a)	if (_nc_tracing & (n)) _tracef a
502 #define T(a)		TR(TRACE_CALLS, a)
503 #define TPUTS_TRACE(s)	_nc_tputs_trace = s;
504 #define TRACE_RETURN(value,type) return _nc_retrace_##type(value)
505 #define returnAttr(code) TRACE_RETURN(code,attr_t)
506 #define returnCode(code) TRACE_RETURN(code,int)
507 #define returnPtr(code)  TRACE_RETURN(code,ptr)
508 #define returnVoid       T((T_RETURN(""))); return
509 #define returnWin(code)  TRACE_RETURN(code,win)
510 extern WINDOW * _nc_retrace_win(WINDOW *);
511 extern attr_t _nc_retrace_attr_t(attr_t);
512 extern char *_nc_retrace_ptr(char *);
513 extern const char *_nc_tputs_trace;
514 extern int _nc_retrace_int(int);
515 extern long _nc_outchars;
516 extern void _nc_fifo_dump(void);
517 #else
518 #define T(a)
519 #define TR(n, a)
520 #define TPUTS_TRACE(s)
521 #define returnAttr(code) return code
522 #define returnCode(code) return code
523 #define returnPtr(code)  return code
524 #define returnVoid       return
525 #define returnWin(code)  return code
526 #endif
527 
528 extern unsigned _nc_tracing;
529 extern const char *_nc_visbuf2(int, const char *);
530 
531 #define _trace_key(ch) ((ch > KEY_MIN) ? keyname(ch) : _tracechar((unsigned char)ch))
532 
533 #define ALL_BUT_COLOR ((chtype)~(A_COLOR))
534 #define IGNORE_COLOR_OFF FALSE
535 #define NONBLANK_ATTR (A_BOLD|A_DIM|A_BLINK)
536 #define XMC_CHANGES(c) ((c) & SP->_xmc_suppress)
537 
538 
539 #define toggle_attr_on(S,at) \
540    if (PAIR_NUMBER(at) > 0)\
541       (S) = ((S) & ALL_BUT_COLOR) | (at);\
542    else\
543       (S) |= (at);\
544    T(("new attribute is %s", _traceattr((S))))
545 
546 
547 #define toggle_attr_off(S,at) \
548    if (IGNORE_COLOR_OFF == TRUE) {\
549       if (PAIR_NUMBER(at) == 0xff) /* turn off color */\
550 	 (S) &= ~(at);\
551       else /* leave color alone */\
552 	 (S) &= ~((at)&ALL_BUT_COLOR);\
553    } else {\
554       if (PAIR_NUMBER(at) > 0x00) /* turn off color */\
555 	 (S) &= ~(at|A_COLOR);\
556       else /* leave color alone */\
557 	 (S) &= ~(at);\
558    }\
559    T(("new attribute is %s", _traceattr((S))));
560 
561 #define DelCharCost(count) \
562 		((parm_dch != 0) \
563 		? SP->_dch_cost \
564 		: ((delete_character != 0) \
565 			? (SP->_dch1_cost * count) \
566 			: INFINITY))
567 
568 #define InsCharCost(count) \
569 		((parm_ich != 0) \
570 		? SP->_ich_cost \
571 		: ((enter_insert_mode && exit_insert_mode) \
572 		  ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) \
573 		  : ((insert_character != 0) \
574 		    ? (SP->_ich1_cost * count) \
575 		    : INFINITY)))
576 
577 #if USE_XMC_SUPPORT
578 #define UpdateAttrs(c)	if (SP->_current_attr != AttrOf(c)) { \
579 				attr_t chg = SP->_current_attr; \
580 				vidattr(AttrOf(c)); \
581 				if (magic_cookie_glitch > 0 \
582 				 && XMC_CHANGES((chg ^ SP->_current_attr))) { \
583 					T(("%s @%d before glitch %d,%d", \
584 						__FILE__, __LINE__, \
585 						SP->_cursrow, \
586 						SP->_curscol)); \
587 					_nc_do_xmc_glitch(chg); \
588 				} \
589 			}
590 #else
591 #define UpdateAttrs(c)	if (SP->_current_attr != AttrOf(c)) \
592 				vidattr(AttrOf(c));
593 #endif
594 
595 /*
596  * Check whether the given character can be output by clearing commands.  This
597  * includes test for being a space and not including any 'bad' attributes, such
598  * as A_REVERSE.  All attribute flags which don't affect appearance of a space
599  * or can be output by clearing (A_COLOR in case of bce-terminal) are excluded.
600  */
601 #define can_clear_with(ch) \
602 	((ch & ~(NONBLANK_ATTR|(back_color_erase ? A_COLOR:0))) == BLANK)
603 
604 #ifdef NCURSES_EXPANDED
605 
606 #undef  toggle_attr_on
607 #define toggle_attr_on(S,at) _nc_toggle_attr_on(&(S), at)
608 extern void _nc_toggle_attr_on(attr_t *, attr_t);
609 
610 #undef  toggle_attr_off
611 #define toggle_attr_off(S,at) _nc_toggle_attr_off(&(S), at)
612 extern void _nc_toggle_attr_off(attr_t *, attr_t);
613 
614 #undef  can_clear_with
615 #define can_clear_with(ch) _nc_can_clear_with(ch)
616 extern int _nc_can_clear_with(chtype);
617 
618 #undef  DelCharCost
619 #define DelCharCost(count) _nc_DelCharCost(count)
620 extern int _nc_DelCharCost(int);
621 
622 #undef  InsCharCost
623 #define InsCharCost(count) _nc_InsCharCost(count)
624 extern int _nc_InsCharCost(int);
625 
626 #undef  UpdateAttrs
627 #define UpdateAttrs(c) _nc_UpdateAttrs(c)
628 extern void _nc_UpdateAttrs(chtype);
629 
630 #else
631 
632 extern void _nc_expanded(void);
633 
634 #endif
635 
636 #if !HAVE_GETCWD
637 #define getcwd(buf,len) getwd(buf)
638 #endif
639 
640 /* doalloc.c */
641 extern void *_nc_doalloc(void *, size_t);
642 #if !HAVE_STRDUP
643 #define strdup _nc_strdup
644 extern char *_nc_strdup(const char *);
645 #endif
646 
647 /* doupdate.c */
648 #if USE_XMC_SUPPORT
649 extern void _nc_do_xmc_glitch(attr_t);
650 #endif
651 
652 /* hardscroll.c */
653 #if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
654 extern void _nc_linedump(void);
655 #endif
656 
657 /* lib_acs.c */
658 extern void _nc_init_acs(void);	/* corresponds to traditional 'init_acs()' */
659 extern int _nc_msec_cost(const char *const, int);  /* used by 'tack' program */
660 
661 /* lib_mvcur.c */
662 #define INFINITY	1000000	/* cost: too high to use */
663 
664 extern void _nc_mvcur_init(void);
665 extern void _nc_mvcur_resume(void);
666 extern void _nc_mvcur_wrap(void);
667 
668 extern int _nc_scrolln(int, int, int, int);
669 
670 extern void _nc_screen_init(void);
671 extern void _nc_screen_resume(void);
672 extern void _nc_screen_wrap(void);
673 
674 #if !HAVE_STRSTR
675 #define strstr _nc_strstr
676 extern char *_nc_strstr(const char *, const char *);
677 #endif
678 
679 /* lib_mouse.c */
680 extern int _nc_has_mouse(void);
681 
682 /* safe_sprintf.c */
683 extern char * _nc_printf_string(const char *fmt, va_list ap);
684 
685 /* tries.c */
686 extern void _nc_add_to_try(struct tries **tree, char *str, unsigned short code);
687 extern char *_nc_expand_try(struct tries *tree, unsigned short code, int *count, size_t len);
688 extern int _nc_remove_key(struct tries **tree, unsigned short code);
689 extern int _nc_remove_string(struct tries **tree, char *string);
690 
691 /* elsewhere ... */
692 extern WINDOW *_nc_makenew(int, int, int, int, int);
693 extern char *_nc_home_terminfo(void);
694 extern char *_nc_trace_buf(int, size_t);
695 extern chtype _nc_background(WINDOW *);
696 extern chtype _nc_render(WINDOW *, chtype);
697 extern int _nc_access(const char *, int);
698 extern int _nc_baudrate(int);
699 extern int _nc_getenv_num(const char *);
700 extern int _nc_keypad(bool);
701 extern int _nc_ospeed(int);
702 extern int _nc_outch(int);
703 extern int _nc_setupscreen(short, short const, FILE *);
704 extern int _nc_timed_wait(int, int, int *);
705 extern int _nc_waddch_nosync(WINDOW *, const chtype);
706 extern void _nc_do_color(int, bool, int (*)(int));
707 extern void _nc_freeall(void);
708 extern void _nc_freewin(WINDOW *win);
709 extern void _nc_hash_map(void);
710 extern void _nc_init_keytry(void);
711 extern void _nc_keep_tic_dir(const char *);
712 extern void _nc_make_oldhash(int i);
713 extern void _nc_outstr(const char *str);
714 extern void _nc_scroll_oldhash(int n, int top, int bot);
715 extern void _nc_scroll_optimize(void);
716 extern void _nc_scroll_window(WINDOW *, int const, short const, short const, chtype);
717 extern void _nc_set_buffer(FILE *ofp, bool buffered);
718 extern void _nc_signal_handler(bool);
719 extern void _nc_synchook(WINDOW *win);
720 extern void _nc_trace_tries(struct tries *tree);
721 
722 #if USE_SIZECHANGE
723 extern void _nc_update_screensize(void);
724 #endif
725 
726 /* scroll indices */
727 extern int *_nc_oldnums;
728 
729 #define USE_SETBUF_0 0
730 
731 #define NC_BUFFERED(flag) \
732 	if ((SP->_buffered != 0) != flag) \
733 		_nc_set_buffer(SP->_ofp, flag)
734 
735 /*
736  * On systems with a broken linker, define 'SP' as a function to force the
737  * linker to pull in the data-only module with 'SP'.
738  */
739 #ifndef BROKEN_LINKER
740 #define BROKEN_LINKER 0
741 #endif
742 
743 #if BROKEN_LINKER
744 #define SP _nc_screen()
745 extern SCREEN *_nc_screen(void);
746 extern int _nc_alloc_screen(void);
747 extern void _nc_set_screen(SCREEN *);
748 #else
749 /* current screen is private data; avoid possible linking conflicts too */
750 extern SCREEN *SP;
751 #define _nc_alloc_screen() ((SP = typeCalloc(SCREEN, 1)) != 0)
752 #define _nc_set_screen(sp) SP = sp
753 #endif
754 
755 /*
756  * We don't want to use the lines or columns capabilities internally,
757  * because if the application is running multiple screens under
758  * X windows, it's quite possible they could all have type xterm
759  * but have different sizes!  So...
760  */
761 #define screen_lines	SP->_lines
762 #define screen_columns	SP->_columns
763 
764 extern int _nc_slk_format;  /* != 0 if slk_init() called */
765 extern int _nc_slk_initialize(WINDOW *, int);
766 
767 /*
768  * Some constants related to SLK's
769  */
770 #define MAX_SKEY_OLD	   8	/* count of soft keys */
771 #define MAX_SKEY_LEN_OLD   8	/* max length of soft key text */
772 #define MAX_SKEY_PC       12    /* This is what most PC's have */
773 #define MAX_SKEY_LEN_PC    5
774 
775 /* Macro to check whether or not we use a standard format */
776 #define SLK_STDFMT(fmt) (fmt < 3)
777 /* Macro to determine height of label window */
778 #define SLK_LINES(fmt)  (SLK_STDFMT(fmt) ? 1 : ((fmt) - 2))
779 
780 #define MAX_SKEY(fmt)     (SLK_STDFMT(fmt)? MAX_SKEY_OLD : MAX_SKEY_PC)
781 #define MAX_SKEY_LEN(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_LEN_OLD : MAX_SKEY_LEN_PC)
782 
783 extern int _nc_ripoffline(int line, int (*init)(WINDOW *,int));
784 
785 #ifdef __cplusplus
786 }
787 #endif
788 
789 #endif /* CURSES_PRIV_H */
790