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