1 /****************************************************************************
2 * Copyright (c) 1998-2008,2009 Free Software Foundation, Inc. *
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: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
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. *
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 *
27 ****************************************************************************/
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 * and: Juergen Pfeifer *
34 ****************************************************************************/
38 * $Id: curses.priv.h,v 1.408 2009/04/19 14:32:33 tom Exp $
42 * Header file for curses library objects which are private to
48 #define CURSES_PRIV_H 1
50 #include <ncurses_dll.h>
56 #include <ncurses_cfg.h>
59 #define MODULE_ID(id) static const char Ident[] = id;
61 #define MODULE_ID(id) /*nothing*/
66 #include <sys/types.h>
72 #if HAVE_SYS_BSDTYPES_H
73 #include <sys/bsdtypes.h> /* needed for ISC */
78 #elif HAVE_SYS_PARAM_H
79 # include <sys/param.h>
88 # if defined(_POSIX_PATH_MAX)
89 # define PATH_MAX _POSIX_PATH_MAX
90 # elif defined(MAXPATHLEN)
91 # define PATH_MAX MAXPATHLEN
93 # define PATH_MAX 255 /* the Posix minimum path-size */
101 /* Some systems have a broken 'select()', but workable 'poll()'. Use that */
102 #if HAVE_WORKING_POLL
103 #define USE_FUNC_POLL 1
107 #include <sys/poll.h>
110 #define USE_FUNC_POLL 0
113 /* include signal.h before curses.h to work-around defect in glibc 2.1.3 */
116 /* Alessandro Rubini's GPM (general-purpose mouse) */
117 #if HAVE_LIBGPM && HAVE_GPM_H
118 #define USE_GPM_SUPPORT 1
120 #define USE_GPM_SUPPORT 0
123 /* QNX mouse support */
124 #if defined(__QNX__) && !defined(__QNXNTO__)
125 #define USE_QNX_MOUSE 1
127 #define USE_QNX_MOUSE 0
130 /* EMX mouse support */
132 #define USE_EMX_MOUSE 1
134 #define USE_EMX_MOUSE 0
137 #define DEFAULT_MAXCLICK 166
138 #define EV_MAX 8 /* size of mouse circular event queue */
141 * If we don't have signals to support it, don't add a sigwinch handler.
142 * In any case, resizing is an extended feature. Use it if we've got it.
144 #if !NCURSES_EXT_FUNCS
145 #undef HAVE_SIZECHANGE
146 #define HAVE_SIZECHANGE 0
149 #if HAVE_SIZECHANGE && USE_SIGWINCH && defined(SIGWINCH)
150 #define USE_SIZECHANGE 1
152 #define USE_SIZECHANGE 0
154 #define USE_SIGWINCH 0
158 * If desired, one can configure this, disabling environment variables that
159 * point to custom terminfo/termcap locations.
161 #ifdef USE_ROOT_ENVIRON
162 #define use_terminfo_vars() 1
164 #define use_terminfo_vars() _nc_env_access()
165 extern NCURSES_EXPORT(int) _nc_env_access (void);
169 * Not all platforms have memmove; some have an equivalent bcopy. (Some may
173 #define memmove(d,s,n) bcopy(s,d,n)
175 #define memmove(d,s,n) _nc_memmove(d,s,n)
176 extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t);
180 * Scroll hints are useless when hashmap is used
182 #if !USE_SCROLL_HINTS
184 #define USE_SCROLL_HINTS 1
186 #define USE_SCROLL_HINTS 0
191 #define if_USE_SCROLL_HINTS(stmt) stmt
193 #define if_USE_SCROLL_HINTS(stmt) /*nothing*/
197 * Note: ht/cbt expansion flakes out randomly under Linux 1.1.47, but only
198 * when we're throwing control codes at the screen at high volume. To see
199 * this, re-enable USE_HARD_TABS and run worm for a while. Other systems
200 * probably don't want to define this either due to uncertainties about tab
201 * delays and expansion in raw mode.
204 #define TRIES struct tries
206 TRIES *child; /* ptr to child. NULL if none */
207 TRIES *sibling; /* ptr to sibling. NULL if none */
208 unsigned char ch; /* character at this node */
209 unsigned short value; /* code of string so far. 0 if none. */
214 * Common/troublesome character definitions
216 #define StringOf(ch) {ch, 0}
223 #define VT_ACSC "``aaffggiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~"
226 * Structure for palette tables
231 short red, green, blue; /* what color_content() returns */
232 short r, g, b; /* params to init_color() */
233 int init; /* true if we called init_color() */
237 #define MAXCOLUMNS 135
239 #define FIFO_SIZE MAXCOLUMNS+2 /* for nocbreak mode input */
243 #define WINDOWLIST struct _win_list
245 #if USE_WIDEC_SUPPORT
246 #define _nc_bkgd _bkgrnd
248 #undef _XOPEN_SOURCE_EXTENDED
249 #define _nc_bkgd _bkgd
250 #define wgetbkgrnd(win, wch) *wch = win->_bkgd
251 #define wbkgrnd wbkgd
254 #undef NCURSES_OPAQUE
255 #define NCURSES_INTERNALS 1
256 #define NCURSES_OPAQUE 0
258 #include <curses.h> /* we'll use -Ipath directive to get the right one! */
261 * If curses.h did not expose the SCREEN-functions, then we do not need the
262 * parameter in the corresponding unextended functions.
265 #define SP_PARM sp /* use parameter */
266 #define NCURSES_SP_ARG SP_PARM
267 #define NCURSES_SP_DCL SCREEN *NCURSES_SP_ARG
268 #define NCURSES_SP_DCL0 NCURSES_SP_DCL
269 #define NCURSES_SP_ARGx NCURSES_SP_ARG,
270 #define NCURSES_SP_DCLx SCREEN *NCURSES_SP_ARGx
272 #define SP_PARM SP /* use global variable */
273 #define NCURSES_SP_ARG
274 #define NCURSES_SP_DCL
275 #define NCURSES_SP_DCL0 void
276 #define NCURSES_SP_ARGx
277 #define NCURSES_SP_DCLx
280 #include <nc_panel.h>
282 #define IsPreScreen(sp) (((sp)!=0) && sp->_prescreen)
283 #define HasTerminal(sp) (((sp)!=0) && (0!=((sp)->_term)))
284 #define IsValidScreen(sp) (HasTerminal(sp) && !sp->_prescreen)
285 #if BROKEN_LINKER || USE_REENTRANT
286 #define TerminalOf(sp) ((sp)?((sp)->_term?(sp)->_term:_nc_prescreen._cur_term): _nc_prescreen._cur_term)
288 #define TerminalOf(sp) ((sp)?((sp)->_term?(sp)->_term:cur_term):cur_term)
292 #include <term_entry.h>
293 #include <nc_tparm.h>
295 #if NCURSES_EXT_COLORS && USE_WIDEC_SUPPORT
296 #define if_EXT_COLORS(stmt) stmt
297 #define NetPair(value,p) (value).ext_color = (p), \
298 AttrOf(value) &= ALL_BUT_COLOR, \
299 AttrOf(value) |= (A_COLOR & COLOR_PAIR((p > 255) ? 255 : p))
300 #define SetPair(value,p) (value).ext_color = (p)
301 #define GetPair(value) (value).ext_color
302 #define unColor(n) (AttrOf(n) & ALL_BUT_COLOR)
303 #define GET_WINDOW_PAIR(w) (w)->_color
304 #define SET_WINDOW_PAIR(w,p) (w)->_color = (p)
305 #define SameAttrOf(a,b) (AttrOf(a) == AttrOf(b) && GetPair(a) == GetPair(b))
306 #define VIDATTR(attr, pair) vid_attr(attr, pair, 0)
308 #define if_EXT_COLORS(stmt) /* nothing */
309 #define SetPair(value,p) RemAttr(value, A_COLOR), \
310 SetAttr(value, AttrOf(value) | (A_COLOR & COLOR_PAIR(p)))
311 #define GetPair(value) PAIR_NUMBER(AttrOf(value))
312 #define unColor(n) (AttrOf(n) & ALL_BUT_COLOR)
313 #define GET_WINDOW_PAIR(w) PAIR_NUMBER(WINDOW_ATTRS(w))
314 #define SET_WINDOW_PAIR(w,p) WINDOW_ATTRS(w) &= ALL_BUT_COLOR, \
315 WINDOW_ATTRS(w) |= (A_COLOR & COLOR_PAIR(p))
316 #define SameAttrOf(a,b) (AttrOf(a) == AttrOf(b))
317 #define VIDATTR(attr, pair) vidattr(attr)
320 #if NCURSES_NO_PADDING
321 #define GetNoPadding(sp) ((sp) ? (sp)->_no_padding : _nc_prescreen._no_padding)
322 #define SetNoPadding(sp) _nc_set_no_padding(sp)
323 extern NCURSES_EXPORT(void) _nc_set_no_padding(SCREEN *);
325 #define GetNoPadding(sp) FALSE
326 #define SetNoPadding(sp) /*nothing*/
329 #define WINDOW_ATTRS(w) ((w)->_attrs)
331 #define SCREEN_ATTRS(s) (*((s)->_current_attr))
332 #define GET_SCREEN_PAIR(s) GetPair(SCREEN_ATTRS(s))
333 #define SET_SCREEN_PAIR(s,p) SetPair(SCREEN_ATTRS(s), p)
336 NCURSES_EXPORT(int *) _nc_ptr_Lines (void);
337 NCURSES_EXPORT(int *) _nc_ptr_Cols (void);
338 #define ptrLines(sp) (sp ? &(sp->_LINES) : &(_nc_prescreen._LINES))
339 #define ptrCols(sp) (sp ? &(sp->_COLS) : &(_nc_prescreen._COLS))
340 #define SET_LINES(value) *_nc_ptr_Lines() = value
341 #define SET_COLS(value) *_nc_ptr_Cols() = value
343 #define ptrLines(sp) &LINES
344 #define ptrCols(sp) &COLS
345 #define SET_LINES(value) LINES = value
346 #define SET_COLS(value) COLS = value
349 #define TR_MUTEX(data) _tracef("%s@%d: me:%08lX COUNT:%2u/%2d/%6d/%2d/%s%9u: " #data, \
350 __FILE__, __LINE__, \
351 (unsigned long) (pthread_self()), \
352 data.__data.__lock, \
353 data.__data.__count, \
354 data.__data.__owner, \
355 data.__data.__kind, \
356 (data.__data.__nusers > 5) ? " OOPS " : "", \
357 data.__data.__nusers)
358 #define TR_GLOBAL_MUTEX(name) TR_MUTEX(_nc_globals.mutex_##name)
364 extern NCURSES_EXPORT(void) _nc_init_pthreads(void);
365 extern NCURSES_EXPORT(void) _nc_mutex_init(pthread_mutex_t *);
366 extern NCURSES_EXPORT(int) _nc_mutex_lock(pthread_mutex_t *);
367 extern NCURSES_EXPORT(int) _nc_mutex_trylock(pthread_mutex_t *);
368 extern NCURSES_EXPORT(int) _nc_mutex_unlock(pthread_mutex_t *);
369 #define _nc_lock_global(name) _nc_mutex_lock(&_nc_globals.mutex_##name)
370 #define _nc_try_global(name) _nc_mutex_trylock(&_nc_globals.mutex_##name)
371 #define _nc_unlock_global(name) _nc_mutex_unlock(&_nc_globals.mutex_##name)
374 #error POSIX threads requires --enable-reentrant option
378 #if defined(__GNUC__)
379 # if defined __USE_ISOC99
380 # define _cat_pragma(exp) _Pragma(#exp)
381 # define _weak_pragma(exp) _cat_pragma(weak name)
383 # define _weak_pragma(exp)
385 # define _declare(name) __extension__ extern __typeof__(name) name
386 # define weak_symbol(name) _weak_pragma(name) _declare(name) __attribute__((weak))
391 # if USE_WEAK_SYMBOLS
392 weak_symbol(pthread_sigmask);
393 weak_symbol(pthread_self);
394 weak_symbol(pthread_equal);
395 weak_symbol(pthread_mutex_init);
396 weak_symbol(pthread_mutex_lock);
397 weak_symbol(pthread_mutex_unlock);
398 weak_symbol(pthread_mutex_trylock);
399 weak_symbol(pthread_mutexattr_settype);
400 weak_symbol(pthread_mutexattr_init);
401 extern NCURSES_EXPORT(int) _nc_sigprocmask(int, const sigset_t *, sigset_t *);
403 # define sigprocmask _nc_sigprocmask
408 #undef HAVE_NANOSLEEP
409 #define HAVE_NANOSLEEP 0 /* nanosleep suspends all threads */
412 #else /* !USE_PTHREADS */
414 #define _nc_init_pthreads() /* nothing */
415 #define _nc_mutex_init(obj) /* nothing */
417 #define _nc_lock_global(name) /* nothing */
418 #define _nc_try_global(name) 0
419 #define _nc_unlock_global(name) /* nothing */
421 #endif /* USE_PTHREADS */
423 #if HAVE_GETTIMEOFDAY
424 # define PRECISE_GETTIME 1
425 # define TimeType struct timeval
427 # define PRECISE_GETTIME 0
428 # define TimeType time_t
432 * Definitions for color pairs
434 typedef unsigned colorpair_t; /* type big enough to store PAIR_OF() */
435 #define C_SHIFT 9 /* we need more bits than there are colors */
436 #define C_MASK ((1 << C_SHIFT) - 1)
437 #define PAIR_OF(fg, bg) ((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK))
438 #define FORE_OF(c) (((c) >> C_SHIFT) & C_MASK)
439 #define BACK_OF(c) ((c) & C_MASK)
440 #define isDefaultColor(c) ((c) >= COLOR_DEFAULT || (c) < 0)
442 #define COLOR_DEFAULT C_MASK
444 #if defined(USE_TERMLIB) && !defined(NEED_NCURSES_CH_T)
446 #undef NCURSES_CH_T /* this is not a termlib feature */
447 #define NCURSES_CH_T void /* ...but we need a pointer in SCREEN */
449 #endif /* USE_TERMLIB */
454 NCURSES_CH_T *text; /* text of the line */
455 NCURSES_SIZE_T firstchar; /* first changed character in the line */
456 NCURSES_SIZE_T lastchar; /* last changed character in the line */
457 NCURSES_SIZE_T oldindex; /* index of the line at last update */
459 #endif /* USE_TERMLIB */
462 M_XTERM = -1 /* use xterm's mouse tracking? */
463 ,M_NONE = 0 /* no mouse device */
468 ,M_SYSMOUSE /* FreeBSD sysmouse on console */
473 * Structures for scrolling.
477 unsigned long hashval;
478 int oldcount, newcount;
479 int oldindex, newindex;
483 * Structures for soft labels.
492 char *ent_text; /* text for the label */
493 char *form_text; /* formatted text (left/center/...) */
494 int ent_x; /* x coordinate of this field */
495 char dirty; /* this label has changed */
496 char visible; /* field is visible */
499 typedef struct _SLK {
500 bool dirty; /* all labels have changed */
501 bool hidden; /* soft labels are hidden */
504 short maxlab; /* number of available labels */
505 short labcnt; /* number of allocated labels */
506 short maxlen; /* length of labels */
507 NCURSES_CH_T attr; /* soft label attribute */
510 #endif /* USE_TERMLIB */
513 WINDOW *win; /* the window used in the hook */
514 int line; /* lines to take, < 0 => from bottom*/
515 int (*hook)(WINDOW *, int); /* callback for user */
519 #undef buttons /* term.h defines this, and gpm uses it! */
523 /* link dynamically to GPM */
524 typedef int *TYPE_gpm_fd;
525 typedef int (*TYPE_Gpm_Open) (Gpm_Connect *, int);
526 typedef int (*TYPE_Gpm_Close) (void);
527 typedef int (*TYPE_Gpm_GetEvent) (Gpm_Event *);
529 #define my_gpm_fd SP_PARM->_mouse_gpm_fd
530 #define my_Gpm_Open SP_PARM->_mouse_Gpm_Open
531 #define my_Gpm_Close SP_PARM->_mouse_Gpm_Close
532 #define my_Gpm_GetEvent SP_PARM->_mouse_Gpm_GetEvent
534 /* link statically to GPM */
535 #define my_gpm_fd &gpm_fd
536 #define my_Gpm_Open Gpm_Open
537 #define my_Gpm_Close Gpm_Close
538 #define my_Gpm_GetEvent Gpm_GetEvent
539 #endif /* HAVE_LIBDL */
540 #endif /* USE_GPM_SUPPORT */
545 char *fix_sgr0; /* this holds the filtered sgr0 string */
546 char *last_bufp; /* help with fix_sgr0 leak */
550 #define TGETENT_MAX 4
571 const char *tparam_base;
573 STACK_FRAME stack[STACKSIZE];
583 int dynamic_var[NUM_VARS];
584 int static_vars[NUM_VARS];
593 * The filesystem database normally uses a single-letter for the lower level
594 * of directories. Use a hexadecimal code for filesystems which do not
595 * preserve mixed-case names.
597 #if MIXEDCASE_FILENAMES
598 #define LEAF_FMT "%c"
600 #define LEAF_FMT "%02x"
604 * TRACEMSE_FMT is no longer than 80 columns, there are 5 numbers that
605 * could at most have 10 digits, and the mask contains no more than 32 bits
606 * with each bit representing less than 15 characters. Usually the whole
607 * string is less than 80 columns, but this buffer size is an absolute
610 #define TRACEMSE_MAX (80 + (5 * 10) + (32 * 15))
611 #define TRACEMSE_FMT "id %2d at (%2d, %2d, %2d) state %4lx = {" /* } */
614 * Global data which is not specific to a screen.
617 SIG_ATOMIC_T have_sigwinch;
618 SIG_ATOMIC_T cleanup_nested;
623 const char *comp_sourcename;
626 bool have_tic_directory;
627 bool keep_tic_directory;
628 const char *tic_directory;
634 char **keyname_table;
639 size_t safeprint_used;
641 TGETENT_CACHE tgetent_cache[TGETENT_MAX];
643 long tgetent_sequence;
645 WINDOWLIST *_nc_windowlist;
646 #define _nc_windows _nc_globals._nc_windowlist
648 #if USE_HOME_TERMINFO
652 #if !USE_SAFE_SPRINTF
659 char trace_fname[PATH_MAX];
664 size_t tracearg_used;
666 TRACEBUF *tracebuf_ptr;
667 size_t tracebuf_used;
669 char tracechr_buf[40];
672 size_t tracedmp_used;
674 unsigned char *tracetry_buf;
675 size_t tracetry_used;
677 char traceatr_color_buf[2][80];
678 int traceatr_color_sel;
679 int traceatr_color_last;
684 pthread_mutex_t mutex_curses;
685 pthread_mutex_t mutex_tst_tracef;
686 pthread_mutex_t mutex_tracef;
689 #define _nc_use_pthreads _nc_globals.use_pthreads
693 extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals;
698 * Global data which can be swept up into a SCREEN when one is created.
699 * It may be modified before the next SCREEN is created.
704 attr_t previous_attr;
705 ripoff_t rippedoff[N_RIPS];
707 TPARM_STATE tparm_state;
708 TTY *saved_tty; /* savetty/resetty information */
709 #if NCURSES_NO_PADDING
710 bool _no_padding; /* flag to set if padding disabled */
712 #if BROKEN_LINKER || USE_REENTRANT
713 chtype *real_acs_map;
719 const char *_tputs_trace;
724 #define ripoff_sp _nc_prescreen.rsp
725 #define ripoff_stack _nc_prescreen.rippedoff
727 extern NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen;
730 * The SCREEN structure.
734 int _ifd; /* input file ptr for screen */
735 FILE *_ofp; /* output file ptr for screen */
736 char *_setbuf; /* buffered I/O for output */
737 bool _filtered; /* filter() was called */
738 bool _buffered; /* setvbuf uses _setbuf data */
739 bool _prescreen; /* is in prescreen phase */
740 bool _use_env; /* LINES & COLS from environment? */
741 int _checkfd; /* filedesc for typeahead check */
742 TERMINAL *_term; /* terminal type information */
743 TTY _saved_tty; /* savetty/resetty information */
744 NCURSES_SIZE_T _lines; /* screen lines */
745 NCURSES_SIZE_T _columns; /* screen columns */
747 NCURSES_SIZE_T _lines_avail; /* lines available for stdscr */
748 NCURSES_SIZE_T _topstolen; /* lines stolen from top */
750 WINDOW *_curscr; /* current screen */
751 WINDOW *_newscr; /* virtual screen to be updated to */
752 WINDOW *_stdscr; /* screen's full-window context */
754 TRIES *_keytry; /* "Try" for use with keypad mode */
755 TRIES *_key_ok; /* Disabled keys via keyok(,FALSE) */
756 bool _tried; /* keypad mode was initialized */
757 bool _keypad_on; /* keypad mode is currently on */
759 bool _called_wgetch; /* check for recursion in wgetch() */
760 int _fifo[FIFO_SIZE]; /* input push-back buffer */
761 short _fifohead, /* head of fifo queue */
762 _fifotail, /* tail of fifo queue */
763 _fifopeek, /* where to peek for next char */
764 _fifohold; /* set if breakout marked */
766 int _endwin; /* are we out of window mode? */
767 NCURSES_CH_T *_current_attr; /* holds current attributes set */
768 int _coloron; /* is color enabled? */
769 int _color_defs; /* are colors modified */
770 int _cursor; /* visibility of the cursor */
771 int _cursrow; /* physical cursor row */
772 int _curscol; /* physical cursor column */
773 bool _notty; /* true if we cannot switch non-tty */
774 int _nl; /* True if NL -> CR/NL is on */
775 int _raw; /* True if in raw mode */
776 int _cbreak; /* 1 if in cbreak mode */
777 /* > 1 if in halfdelay mode */
778 int _echo; /* True if echo on */
779 int _use_meta; /* use the meta key? */
780 struct _SLK *_slk; /* ptr to soft key struct / NULL */
781 int slk_format; /* selected format for this screen */
782 /* cursor movement costs; units are 10ths of milliseconds */
783 #if NCURSES_NO_PADDING
784 bool _no_padding; /* flag to set if padding disabled */
786 int _char_padding; /* cost of character put */
787 int _cr_cost; /* cost of (carriage_return) */
788 int _cup_cost; /* cost of (cursor_address) */
789 int _home_cost; /* cost of (cursor_home) */
790 int _ll_cost; /* cost of (cursor_to_ll) */
792 int _ht_cost; /* cost of (tab) */
793 int _cbt_cost; /* cost of (backtab) */
794 #endif /* USE_HARD_TABS */
795 int _cub1_cost; /* cost of (cursor_left) */
796 int _cuf1_cost; /* cost of (cursor_right) */
797 int _cud1_cost; /* cost of (cursor_down) */
798 int _cuu1_cost; /* cost of (cursor_up) */
799 int _cub_cost; /* cost of (parm_cursor_left) */
800 int _cuf_cost; /* cost of (parm_cursor_right) */
801 int _cud_cost; /* cost of (parm_cursor_down) */
802 int _cuu_cost; /* cost of (parm_cursor_up) */
803 int _hpa_cost; /* cost of (column_address) */
804 int _vpa_cost; /* cost of (row_address) */
805 /* used in tty_update.c, must be chars */
806 int _ed_cost; /* cost of (clr_eos) */
807 int _el_cost; /* cost of (clr_eol) */
808 int _el1_cost; /* cost of (clr_bol) */
809 int _dch1_cost; /* cost of (delete_character) */
810 int _ich1_cost; /* cost of (insert_character) */
811 int _dch_cost; /* cost of (parm_dch) */
812 int _ich_cost; /* cost of (parm_ich) */
813 int _ech_cost; /* cost of (erase_chars) */
814 int _rep_cost; /* cost of (repeat_char) */
815 int _hpa_ch_cost; /* cost of (column_address) */
816 int _cup_ch_cost; /* cost of (cursor_address) */
817 int _cuf_ch_cost; /* cost of (parm_cursor_right) */
818 int _inline_cost; /* cost of inline-move */
819 int _smir_cost; /* cost of (enter_insert_mode) */
820 int _rmir_cost; /* cost of (exit_insert_mode) */
821 int _ip_cost; /* cost of (insert_padding) */
822 /* used in lib_mvcur.c */
823 char * _address_cursor;
824 /* used in tty_update.c */
825 int _scrolling; /* 1 if terminal's smart enough to */
827 /* used in lib_color.c */
828 color_t *_color_table; /* screen's color palette */
829 int _color_count; /* count of colors in palette */
830 colorpair_t *_color_pairs; /* screen's color pair list */
831 int _pair_count; /* count of color pairs */
832 int _pair_limit; /* actual limit of color-pairs */
833 #if NCURSES_EXT_FUNCS
834 bool _default_color; /* use default colors */
835 bool _has_sgr_39_49; /* has ECMA default color support */
836 int _default_fg; /* assumed default foreground */
837 int _default_bg; /* assumed default background */
838 int _default_pairs; /* count pairs using default color */
840 chtype _ok_attributes; /* valid attributes for terminal */
841 chtype _xmc_suppress; /* attributes to suppress if xmc */
842 chtype _xmc_triggers; /* attributes to process if xmc */
843 chtype * _acs_map; /* the real alternate-charset map */
844 bool * _screen_acs_map;
847 /* used in lib_vidattr.c */
848 bool _use_rmso; /* true if we may use 'rmso' */
849 bool _use_rmul; /* true if we may use 'rmul' */
852 * These data correspond to the state of the idcok() and idlok()
853 * functions. A caveat is in order here: the XSI and SVr4
854 * documentation specify that these functions apply to the window which
855 * is given as an argument. However, ncurses implements this logic
856 * only for the newscr/curscr update process, _not_ per-window.
860 #define _nc_idlok SP->_nc_sp_idlok
861 #define _nc_idcok SP->_nc_sp_idcok
864 * These are the data that support the mouse interface.
866 bool _mouse_initialized;
867 MouseType _mouse_type;
869 bool (*_mouse_event) (SCREEN *);
870 bool (*_mouse_inline)(SCREEN *);
871 bool (*_mouse_parse) (SCREEN *, int);
872 void (*_mouse_resume)(SCREEN *);
873 void (*_mouse_wrap) (SCREEN *);
874 int _mouse_fd; /* file-descriptor, if any */
875 bool _mouse_active; /* true if initialized */
877 NCURSES_CONST char *_mouse_xtermcap; /* string to enable/disable mouse */
878 MEVENT _mouse_events[EV_MAX]; /* hold the last mouse event seen */
879 MEVENT *_mouse_eventp; /* next free slot in event queue */
882 bool _mouse_gpm_loaded;
883 bool _mouse_gpm_found;
886 TYPE_gpm_fd _mouse_gpm_fd;
887 TYPE_Gpm_Open _mouse_Gpm_Open;
888 TYPE_Gpm_Close _mouse_Gpm_Close;
889 TYPE_Gpm_GetEvent _mouse_Gpm_GetEvent;
891 Gpm_Connect _mouse_gpm_connect;
892 #endif /* USE_GPM_SUPPORT */
896 int _emxmouse_thread;
897 int _emxmouse_activated;
898 char _emxmouse_buttons[4];
902 MEVENT _sysmouse_fifo[FIFO_SIZE];
905 int _sysmouse_char_width; /* character width */
906 int _sysmouse_char_height; /* character height */
907 int _sysmouse_old_buttons;
908 int _sysmouse_new_buttons;
912 * This supports automatic resizing
915 int (*_resize)(int,int);
919 * These are data that support the proper handling of the panel stack on an
922 struct panelhook _panelHook;
925 SCREEN *_next_screen;
927 /* hashes for old and new lines */
928 unsigned long *oldhash, *newhash;
934 bool _cleanup; /* cleanup after int/quit signal */
935 int (*_outch)(int); /* output handler if not putc */
937 int _legacy_coding; /* see use_legacy_coding() */
940 char _ttytype[NAMESIZE];
947 const char *_tputs_trace;
952 char tracechr_buf[40];
953 char tracemse_buf[TRACEMSE_MAX];
956 * ncurses/ncursesw are the same up to this point.
958 #if USE_WIDEC_SUPPORT
959 /* recent versions of 'screen' have partially-working support for
960 * UTF-8, but do not permit ACS at the same time (see tty_update.c).
962 bool _screen_acs_fix;
966 extern NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain;
967 extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
970 WINDOW win; /* first, so WINDOW_EXT() works */
972 SCREEN *screen; /* screen containing the window */
973 #ifdef _XOPEN_SOURCE_EXTENDED
974 char addch_work[(MB_LEN_MAX * 9) + 1];
975 unsigned addch_used; /* number of bytes in addch_work[] */
976 int addch_x; /* x-position for addch_work[] */
977 int addch_y; /* y-position for addch_work[] */
981 #define WINDOW_EXT(win,field) (((WINDOWLIST *)(win))->field)
983 #define SP_PRE_INIT(sp) \
990 sp->_fifohead = -1; \
991 sp->_endwin = TRUE; \
993 sp->_windowlist = 0; \
994 sp->_outch = NCURSES_SP_NAME(_nc_outch); \
997 /* usually in <limits.h> */
999 #define UCHAR_MAX 255
1002 /* The terminfo source is assumed to be 7-bit ASCII */
1003 #define is7bits(c) ((unsigned)(c) < 128)
1005 /* Checks for isprint() should be done on 8-bit characters (non-wide) */
1006 #define is8bits(c) ((unsigned)(c) <= UCHAR_MAX)
1009 #define min(a,b) ((a) > (b) ? (b) : (a))
1013 #define max(a,b) ((a) < (b) ? (b) : (a))
1016 /* usually in <unistd.h> */
1017 #ifndef STDIN_FILENO
1018 #define STDIN_FILENO 0
1021 #ifndef STDOUT_FILENO
1022 #define STDOUT_FILENO 1
1025 #ifndef STDERR_FILENO
1026 #define STDERR_FILENO 2
1029 #ifndef EXIT_SUCCESS
1030 #define EXIT_SUCCESS 0
1033 #ifndef EXIT_FAILURE
1034 #define EXIT_FAILURE 1
1038 #define R_OK 4 /* Test for read permission. */
1041 #define W_OK 2 /* Test for write permission. */
1044 #define X_OK 1 /* Test for execute permission. */
1047 #define F_OK 0 /* Test for existence. */
1051 #include <fcntl.h> /* may define O_BINARY */
1060 #define COUNT_OUTCHARS(n) _nc_count_outchars(n);
1062 #define COUNT_OUTCHARS(n) _nc_outchars += (n);
1065 #define COUNT_OUTCHARS(n) /* nothing */
1068 #define RESET_OUTCHARS() COUNT_OUTCHARS(-_nc_outchars)
1070 #define UChar(c) ((unsigned char)(c))
1071 #define ChCharOf(c) ((c) & (chtype)A_CHARTEXT)
1072 #define ChAttrOf(c) ((c) & (chtype)A_ATTRIBUTES)
1075 #define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */
1078 #if USE_WIDEC_SUPPORT /* { */
1079 #define isEILSEQ(status) (((size_t)status == (size_t)-1) && (errno == EILSEQ))
1081 #define init_mb(state) memset(&state, 0, sizeof(state))
1083 #if NCURSES_EXT_COLORS
1084 #define NulColor , 0
1086 #define NulColor /* nothing */
1089 #define NulChar 0,0,0,0 /* FIXME: see CCHARW_MAX */
1090 #define CharOf(c) ((c).chars[0])
1091 #define AttrOf(c) ((c).attr)
1093 #define AddAttr(c,a) AttrOf(c) |= ((a) & A_ATTRIBUTES)
1094 #define RemAttr(c,a) AttrOf(c) &= ~((a) & A_ATTRIBUTES)
1095 #define SetAttr(c,a) AttrOf(c) = ((a) & A_ATTRIBUTES) | WidecExt(c)
1097 #define NewChar2(c,a) { a, { c, NulChar } NulColor }
1098 #define NewChar(ch) NewChar2(ChCharOf(ch), ChAttrOf(ch))
1101 #define CharEq(a,b) (((a).attr == (b).attr) \
1102 && (a).chars[0] == (b).chars[0] \
1103 && (a).chars[1] == (b).chars[1] \
1104 && (a).chars[2] == (b).chars[2] \
1105 && (a).chars[3] == (b).chars[3] \
1106 && (a).chars[4] == (b).chars[4] \
1107 if_EXT_COLORS(&& (a).ext_color == (b).ext_color))
1109 #define CharEq(a,b) (!memcmp(&(a), &(b), sizeof(a)))
1112 #define SetChar(ch,c,a) do { \
1113 NCURSES_CH_T *_cp = &ch; \
1114 memset(_cp, 0, sizeof(ch)); \
1115 _cp->chars[0] = (c); \
1117 if_EXT_COLORS(SetPair(ch, PAIR_NUMBER(a))); \
1119 #define CHREF(wch) (&wch)
1120 #define CHDEREF(wch) (*wch)
1121 #define ARG_CH_T NCURSES_CH_T *
1122 #define CARG_CH_T const NCURSES_CH_T *
1123 #define PUTC_DATA char PUTC_buf[MB_LEN_MAX]; int PUTC_i, PUTC_n; \
1124 mbstate_t PUT_st; wchar_t PUTC_ch
1125 #define PUTC_INIT init_mb (PUT_st)
1126 #define PUTC(ch,b) do { if(!isWidecExt(ch)) { \
1127 if (Charable(ch)) { \
1128 fputc(CharOf(ch), b); \
1129 COUNT_OUTCHARS(1); \
1132 for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { \
1133 PUTC_ch = (ch).chars[PUTC_i]; \
1134 if (PUTC_ch == L'\0') \
1136 PUTC_n = wcrtomb(PUTC_buf, \
1137 (ch).chars[PUTC_i], &PUT_st); \
1138 if (PUTC_n <= 0) { \
1139 if (PUTC_ch && is8bits(PUTC_ch) && PUTC_i == 0) \
1143 fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b); \
1145 COUNT_OUTCHARS(PUTC_i); \
1148 #define BLANK NewChar2(' ', WA_NORMAL)
1149 #define ZEROS NewChar2('\0', WA_NORMAL)
1150 #define ISBLANK(ch) ((ch).chars[0] == L' ' && (ch).chars[1] == L'\0')
1153 * Wide characters cannot be represented in the A_CHARTEXT mask of
1154 * attr_t's but an application might have set a narrow character there.
1155 * But even in that case, it would only be a printable character, or
1156 * zero. Otherwise we can use those bits to tell if a cell is the
1157 * first or extension part of a wide character.
1159 #define WidecExt(ch) (AttrOf(ch) & A_CHARTEXT)
1160 #define isWidecBase(ch) (WidecExt(ch) == 1)
1161 #define isWidecExt(ch) (WidecExt(ch) > 1 && WidecExt(ch) < 32)
1162 #define SetWidecExt(dst, ext) AttrOf(dst) &= ~A_CHARTEXT, \
1163 AttrOf(dst) |= (ext + 1)
1165 #define if_WIDEC(code) code
1166 #define Charable(ch) ((SP != 0 && SP->_legacy_coding) \
1167 || (AttrOf(ch) & A_ALTCHARSET) \
1168 || (!isWidecExt(ch) && \
1169 (ch).chars[1] == L'\0' && \
1170 _nc_is_charable(CharOf(ch))))
1172 #define L(ch) L ## ch
1174 #define CharOf(c) ChCharOf(c)
1175 #define AttrOf(c) ChAttrOf(c)
1176 #define AddAttr(c,a) c |= (a)
1177 #define RemAttr(c,a) c &= ~((a) & A_ATTRIBUTES)
1178 #define SetAttr(c,a) c = ((c) & ~A_ATTRIBUTES) | (a)
1179 #define NewChar(ch) (ch)
1180 #define NewChar2(c,a) ((c) | (a))
1181 #define CharEq(a,b) ((a) == (b))
1182 #define SetChar(ch,c,a) ch = (c) | (a)
1183 #define CHREF(wch) wch
1184 #define CHDEREF(wch) wch
1185 #define ARG_CH_T NCURSES_CH_T
1186 #define CARG_CH_T NCURSES_CH_T
1187 #define PUTC_DATA int data = 0
1188 #define PUTC(ch,b) do { data = CharOf(ch); putc(data,b); } while (0)
1190 #define BLANK (' '|A_NORMAL)
1191 #define ZEROS ('\0'|A_NORMAL)
1192 #define ISBLANK(ch) (CharOf(ch) == ' ')
1194 #define isWidecExt(ch) (0)
1195 #define if_WIDEC(code) /* nothing */
1200 #define AttrOfD(ch) AttrOf(CHDEREF(ch))
1201 #define CharOfD(ch) CharOf(CHDEREF(ch))
1202 #define SetChar2(wch,ch) SetChar(wch,ChCharOf(ch),ChAttrOf(ch))
1204 #define BLANK_ATTR A_NORMAL
1205 #define BLANK_TEXT L(' ')
1209 #define LEGALYX(w, y, x) \
1211 ((x) >= 0 && (x) <= (w)->_maxx && \
1212 (y) >= 0 && (y) <= (w)->_maxy))
1214 #define CHANGED_CELL(line,col) \
1215 if (line->firstchar == _NOCHANGE) \
1216 line->firstchar = line->lastchar = col; \
1217 else if ((col) < line->firstchar) \
1218 line->firstchar = col; \
1219 else if ((col) > line->lastchar) \
1220 line->lastchar = col
1222 #define CHANGED_RANGE(line,start,end) \
1223 if (line->firstchar == _NOCHANGE \
1224 || line->firstchar > (start)) \
1225 line->firstchar = start; \
1226 if (line->lastchar == _NOCHANGE \
1227 || line->lastchar < (end)) \
1228 line->lastchar = end
1230 #define CHANGED_TO_EOL(line,start,end) \
1231 if (line->firstchar == _NOCHANGE \
1232 || line->firstchar > (start)) \
1233 line->firstchar = start; \
1234 line->lastchar = end
1236 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
1238 #define FreeIfNeeded(p) if ((p) != 0) free(p)
1240 /* FreeAndNull() is not a comma-separated expression because some compilers
1241 * do not accept a mixture of void with values.
1243 #define FreeAndNull(p) free(p); p = 0
1245 #include <nc_alloc.h>
1248 * TTY bit definition for converting tabs to spaces.
1251 # define OFLAGS_TABS TAB3 /* POSIX specifies TAB3 */
1254 # define OFLAGS_TABS XTABS /* XTABS is usually the "same" */
1257 # define OFLAGS_TABS OXTABS /* the traditional BSD equivalent */
1259 # define OFLAGS_TABS 0
1265 * Standardize/simplify common loops
1267 #define each_screen(p) p = _nc_screen_chain; p != 0; p = (p)->_next_screen
1268 #define each_window(p) p = _nc_windows; p != 0; p = (p)->next
1269 #define each_ripoff(p) p = ripoff_stack; (p - ripoff_stack) < N_RIPS; ++p
1272 * Prefixes for call/return points of library function traces. We use these to
1273 * instrument the public functions so that the traces can be easily transformed
1274 * into regression scripts.
1276 #define T_CALLED(fmt) "called {" fmt
1277 #define T_CREATE(fmt) "create :" fmt
1278 #define T_RETURN(fmt) "return }" fmt
1283 #define TPUTS_TRACE(s) _nc_set_tputs_trace(s);
1285 #define TPUTS_TRACE(s) _nc_tputs_trace = s;
1288 #define START_TRACE() \
1289 if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
1290 int t = _nc_getenv_num("NCURSES_TRACE"); \
1292 trace((unsigned) t); \
1296 * Many of the _tracef() calls use static buffers; lock the trace state before
1297 * trying to fill them.
1300 #define USE_TRACEF(mask) _nc_use_tracef(mask)
1301 extern NCURSES_EXPORT(int) _nc_use_tracef (unsigned);
1302 extern NCURSES_EXPORT(void) _nc_locked_tracef (const char *, ...) GCC_PRINTFLIKE(1,2);
1304 #define USE_TRACEF(mask) (_nc_tracing & (mask))
1305 #define _nc_locked_tracef _tracef
1308 #define TR(n, a) if (USE_TRACEF(n)) _nc_locked_tracef a
1309 #define T(a) TR(TRACE_CALLS, a)
1310 #define TRACE_RETURN(value,type) return _nc_retrace_##type(value)
1312 #define returnAttr(code) TRACE_RETURN(code,attr_t)
1313 #define returnBits(code) TRACE_RETURN(code,unsigned)
1314 #define returnBool(code) TRACE_RETURN(code,bool)
1315 #define returnCPtr(code) TRACE_RETURN(code,cptr)
1316 #define returnCVoidPtr(code) TRACE_RETURN(code,cvoid_ptr)
1317 #define returnChtype(code) TRACE_RETURN(code,chtype)
1318 #define returnCode(code) TRACE_RETURN(code,int)
1319 #define returnPtr(code) TRACE_RETURN(code,ptr)
1320 #define returnSP(code) TRACE_RETURN(code,sp)
1321 #define returnVoid T((T_RETURN(""))); return
1322 #define returnVoidPtr(code) TRACE_RETURN(code,void_ptr)
1323 #define returnWin(code) TRACE_RETURN(code,win)
1325 extern NCURSES_EXPORT(NCURSES_BOOL) _nc_retrace_bool (NCURSES_BOOL);
1326 extern NCURSES_EXPORT(NCURSES_CONST void *) _nc_retrace_cvoid_ptr (NCURSES_CONST void *);
1327 extern NCURSES_EXPORT(SCREEN *) _nc_retrace_sp (SCREEN *);
1328 extern NCURSES_EXPORT(WINDOW *) _nc_retrace_win (WINDOW *);
1329 extern NCURSES_EXPORT(attr_t) _nc_retrace_attr_t (attr_t);
1330 extern NCURSES_EXPORT(char *) _nc_retrace_ptr (char *);
1331 extern NCURSES_EXPORT(char *) _nc_trace_ttymode(TTY *tty);
1332 extern NCURSES_EXPORT(char *) _nc_varargs (const char *, va_list);
1333 extern NCURSES_EXPORT(chtype) _nc_retrace_chtype (chtype);
1334 extern NCURSES_EXPORT(const char *) _nc_altcharset_name(attr_t, chtype);
1335 extern NCURSES_EXPORT(const char *) _nc_retrace_cptr (const char *);
1336 extern NCURSES_EXPORT(int) _nc_retrace_int (int);
1337 extern NCURSES_EXPORT(unsigned) _nc_retrace_unsigned (unsigned);
1338 extern NCURSES_EXPORT(void *) _nc_retrace_void_ptr (void *);
1339 extern NCURSES_EXPORT(void) _nc_fifo_dump (SCREEN *);
1342 NCURSES_WRAPPED_VAR(long, _nc_outchars);
1343 NCURSES_WRAPPED_VAR(const char *, _nc_tputs_trace);
1344 #define _nc_outchars NCURSES_PUBLIC_VAR(_nc_outchars())
1345 #define _nc_tputs_trace NCURSES_PUBLIC_VAR(_nc_tputs_trace())
1346 extern NCURSES_EXPORT(void) _nc_set_tputs_trace (const char *);
1347 extern NCURSES_EXPORT(void) _nc_count_outchars (long);
1349 extern NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace;
1350 extern NCURSES_EXPORT_VAR(long) _nc_outchars;
1353 extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing;
1355 #if USE_WIDEC_SUPPORT
1356 extern NCURSES_EXPORT(const char *) _nc_viswbuf2 (int, const wchar_t *);
1357 extern NCURSES_EXPORT(const char *) _nc_viswbufn (const wchar_t *, int);
1360 extern NCURSES_EXPORT(const char *) _nc_viscbuf2 (int, const NCURSES_CH_T *, int);
1361 extern NCURSES_EXPORT(const char *) _nc_viscbuf (const NCURSES_CH_T *, int);
1365 #define START_TRACE() /* nothing */
1369 #define TPUTS_TRACE(s)
1371 #define returnAttr(code) return code
1372 #define returnBits(code) return code
1373 #define returnBool(code) return code
1374 #define returnCPtr(code) return code
1375 #define returnCVoidPtr(code) return code
1376 #define returnChtype(code) return code
1377 #define returnCode(code) return code
1378 #define returnPtr(code) return code
1379 #define returnSP(code) return code
1380 #define returnVoid return
1381 #define returnVoidPtr(code) return code
1382 #define returnWin(code) return code
1384 #endif /* TRACE/!TRACE */
1387 * Return-codes for tgetent() and friends.
1389 #define TGETENT_YES 1 /* entry is found */
1390 #define TGETENT_NO 0 /* entry is not found */
1391 #define TGETENT_ERR -1 /* an error occurred */
1393 extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *);
1394 extern NCURSES_EXPORT(const char *) _nc_visbufn (const char *, int);
1396 #define EMPTY_MODULE(name) \
1397 extern NCURSES_EXPORT(void) name (void); \
1398 NCURSES_EXPORT(void) name (void) { }
1400 #define ALL_BUT_COLOR ((chtype)~(A_COLOR))
1401 #define NONBLANK_ATTR (A_NORMAL|A_BOLD|A_DIM|A_BLINK)
1402 #define XMC_CHANGES(c) ((c) & SP->_xmc_suppress)
1404 #define toggle_attr_on(S,at) {\
1405 if (PAIR_NUMBER(at) > 0) {\
1406 (S) = ((S) & ALL_BUT_COLOR) | (at);\
1410 TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
1413 #define toggle_attr_off(S,at) {\
1414 if (PAIR_NUMBER(at) > 0) {\
1415 (S) &= ~(at|A_COLOR);\
1419 TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
1421 #define DelCharCost(count) \
1424 : ((delete_character != 0) \
1425 ? (SP->_dch1_cost * count) \
1428 #define InsCharCost(count) \
1431 : ((enter_insert_mode && exit_insert_mode) \
1432 ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) \
1433 : ((insert_character != 0) \
1434 ? ((SP->_ich1_cost + SP->_ip_cost) * count) \
1438 #define UpdateAttrs(c) if (!SameAttrOf(SCREEN_ATTRS(SP), c)) { \
1439 attr_t chg = AttrOf(SCREEN_ATTRS(SP)); \
1440 VIDATTR(AttrOf(c), GetPair(c)); \
1441 if (magic_cookie_glitch > 0 \
1442 && XMC_CHANGES((chg ^ AttrOf(SCREEN_ATTRS(SP))))) { \
1443 T(("%s @%d before glitch %d,%d", \
1444 __FILE__, __LINE__, \
1447 _nc_do_xmc_glitch(chg); \
1451 #define UpdateAttrs(c) if (!SameAttrOf(SCREEN_ATTRS(SP), c)) \
1452 VIDATTR(AttrOf(c), GetPair(c));
1456 * Macros to make additional parameter to implement wgetch_events()
1458 #ifdef NCURSES_WGETCH_EVENTS
1459 #define EVENTLIST_0th(param) param
1460 #define EVENTLIST_1st(param) param
1461 #define EVENTLIST_2nd(param) , param
1463 #define EVENTLIST_0th(param) void
1464 #define EVENTLIST_1st(param) /* nothing */
1465 #define EVENTLIST_2nd(param) /* nothing */
1468 #if NCURSES_EXPANDED && NCURSES_EXT_FUNCS
1470 #undef toggle_attr_on
1471 #define toggle_attr_on(S,at) _nc_toggle_attr_on(&(S), at)
1472 extern NCURSES_EXPORT(void) _nc_toggle_attr_on (attr_t *, attr_t);
1474 #undef toggle_attr_off
1475 #define toggle_attr_off(S,at) _nc_toggle_attr_off(&(S), at)
1476 extern NCURSES_EXPORT(void) _nc_toggle_attr_off (attr_t *, attr_t);
1479 #define DelCharCost(count) _nc_DelCharCost(count)
1480 extern NCURSES_EXPORT(int) _nc_DelCharCost (int);
1483 #define InsCharCost(count) _nc_InsCharCost(count)
1484 extern NCURSES_EXPORT(int) _nc_InsCharCost (int);
1487 #define UpdateAttrs(c) _nc_UpdateAttrs(c)
1488 extern NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T);
1492 extern NCURSES_EXPORT(void) _nc_expanded (void);
1496 #if !NCURSES_EXT_FUNCS
1497 #define set_escdelay(value) ESCDELAY = value
1501 #define getcwd(buf,len) getwd(buf)
1505 #if USE_WIDEC_SUPPORT
1506 extern NCURSES_EXPORT(bool) _nc_is_charable(wchar_t);
1507 extern NCURSES_EXPORT(int) _nc_to_char(wint_t);
1508 extern NCURSES_EXPORT(wint_t) _nc_to_widechar(int);
1513 short nte_name; /* offset of name to hash on */
1514 int nte_type; /* BOOLEAN, NUMBER or STRING */
1515 short nte_index; /* index of associated variable in its array */
1516 short nte_link; /* index in table of next hash, or -1 */
1528 extern NCURSES_EXPORT(void) _nc_do_xmc_glitch (attr_t);
1532 #if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
1533 extern NCURSES_EXPORT(void) _nc_linedump (void);
1537 extern NCURSES_EXPORT(void) _nc_init_acs (void); /* corresponds to traditional 'init_acs()' */
1538 extern NCURSES_EXPORT(int) _nc_msec_cost (const char *const, int); /* used by 'tack' program */
1541 #if USE_WIDEC_SUPPORT
1542 NCURSES_EXPORT(int) _nc_build_wch(WINDOW *win, ARG_CH_T ch);
1546 #if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
1547 extern NCURSES_EXPORT(int) _nc_wchstrlen(const cchar_t *);
1551 extern NCURSES_EXPORT(bool) _nc_reset_colors(void);
1554 extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, unsigned long *, int EVENTLIST_2nd(_nc_eventlist *));
1557 extern NCURSES_EXPORT(int) _nc_insert_ch(WINDOW *, chtype);
1560 #define INFINITY 1000000 /* cost: too high to use */
1562 extern NCURSES_EXPORT(void) _nc_mvcur_init (void);
1563 extern NCURSES_EXPORT(void) _nc_mvcur_resume (void);
1564 extern NCURSES_EXPORT(void) _nc_mvcur_wrap (void);
1566 extern NCURSES_EXPORT(int) _nc_scrolln (int, int, int, int);
1568 extern NCURSES_EXPORT(void) _nc_screen_init (void);
1569 extern NCURSES_EXPORT(void) _nc_screen_resume (void);
1570 extern NCURSES_EXPORT(void) _nc_screen_wrap (void);
1573 extern NCURSES_EXPORT(bool) _nc_has_mouse (SCREEN *);
1576 #define INFINITY 1000000 /* cost: too high to use */
1577 #define BAUDBYTE 9 /* 9 = 7 bits + 1 parity + 1 stop */
1580 extern NCURSES_EXPORT(char *) _nc_get_locale(void);
1581 extern NCURSES_EXPORT(int) _nc_unicode_locale(void);
1582 extern NCURSES_EXPORT(int) _nc_locale_breaks_acs(TERMINAL *);
1583 extern NCURSES_EXPORT(int) _nc_setupterm(NCURSES_CONST char *, int, int *, bool);
1584 extern NCURSES_EXPORT(void) _nc_get_screensize(SCREEN *, int *, int *);
1588 extern NCURSES_EXPORT(int) _nc_handle_sigwinch(SCREEN *);
1590 #define _nc_handle_sigwinch(a) /* nothing */
1594 #if USE_WIDEC_SUPPORT
1595 extern NCURSES_EXPORT(void) _nc_init_wacs(void);
1599 char *s_head; /* beginning of the string (may be null) */
1600 char *s_tail; /* end of the string (may be null) */
1601 size_t s_size; /* current remaining size available */
1602 size_t s_init; /* total size available */
1606 extern NCURSES_EXPORT(string_desc *) _nc_str_init (string_desc *, char *, size_t);
1607 extern NCURSES_EXPORT(string_desc *) _nc_str_null (string_desc *, size_t);
1608 extern NCURSES_EXPORT(string_desc *) _nc_str_copy (string_desc *, string_desc *);
1609 extern NCURSES_EXPORT(bool) _nc_safe_strcat (string_desc *, const char *);
1610 extern NCURSES_EXPORT(bool) _nc_safe_strcpy (string_desc *, const char *);
1613 #define strstr _nc_strstr
1614 extern NCURSES_EXPORT(char *) _nc_strstr (const char *, const char *);
1617 /* safe_sprintf.c */
1618 extern NCURSES_EXPORT(char *) _nc_printf_string (const char *, va_list);
1621 extern NCURSES_EXPORT(int) _nc_add_to_try (TRIES **, const char *, unsigned);
1622 extern NCURSES_EXPORT(char *) _nc_expand_try (TRIES *, unsigned, int *, size_t);
1623 extern NCURSES_EXPORT(int) _nc_remove_key (TRIES **, unsigned);
1624 extern NCURSES_EXPORT(int) _nc_remove_string (TRIES **, const char *);
1627 extern NCURSES_EXPORT(ENTRY *) _nc_delink_entry (ENTRY *, TERMTYPE *);
1628 extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_keyname (SCREEN *, int);
1629 extern NCURSES_EXPORT(SCREEN *) _nc_screen_of (WINDOW *);
1630 extern NCURSES_EXPORT(WINDOW *) _nc_makenew (int, int, int, int, int);
1631 extern NCURSES_EXPORT(char *) _nc_trace_buf (int, size_t);
1632 extern NCURSES_EXPORT(char *) _nc_trace_bufcat (int, const char *);
1633 extern NCURSES_EXPORT(char *) _nc_tracechar (SCREEN *, int);
1634 extern NCURSES_EXPORT(char *) _nc_tracemouse (SCREEN *, MEVENT const *);
1635 extern NCURSES_EXPORT(int) _nc_access (const char *, int);
1636 extern NCURSES_EXPORT(int) _nc_baudrate (int);
1637 extern NCURSES_EXPORT(int) _nc_freewin (WINDOW *);
1638 extern NCURSES_EXPORT(int) _nc_getenv_num (const char *);
1639 extern NCURSES_EXPORT(int) _nc_keypad (SCREEN *, bool);
1640 extern NCURSES_EXPORT(int) _nc_ospeed (int);
1641 extern NCURSES_EXPORT(int) _nc_outch (int);
1642 extern NCURSES_EXPORT(int) _nc_putp(const char *, const char *);
1643 extern NCURSES_EXPORT(int) _nc_putp_flush(const char *, const char *);
1644 extern NCURSES_EXPORT(int) _nc_read_termcap_entry (const char *const, TERMTYPE *const);
1645 extern NCURSES_EXPORT(int) _nc_setupscreen (int, int, FILE *, bool, int);
1646 extern NCURSES_EXPORT(int) _nc_timed_wait (SCREEN *, int, int, int * EVENTLIST_2nd(_nc_eventlist *));
1647 extern NCURSES_EXPORT(void) _nc_do_color (short, short, bool, int (*)(int));
1648 extern NCURSES_EXPORT(void) _nc_flush (void);
1649 extern NCURSES_EXPORT(void) _nc_free_and_exit (int);
1650 extern NCURSES_EXPORT(void) _nc_free_entry (ENTRY *, TERMTYPE *);
1651 extern NCURSES_EXPORT(void) _nc_freeall (void);
1652 extern NCURSES_EXPORT(void) _nc_hash_map (void);
1653 extern NCURSES_EXPORT(void) _nc_init_keytry (SCREEN *);
1654 extern NCURSES_EXPORT(void) _nc_keep_tic_dir (const char *);
1655 extern NCURSES_EXPORT(void) _nc_make_oldhash (int i);
1656 extern NCURSES_EXPORT(void) _nc_scroll_oldhash (int n, int top, int bot);
1657 extern NCURSES_EXPORT(void) _nc_scroll_optimize (void);
1658 extern NCURSES_EXPORT(void) _nc_set_buffer (FILE *, bool);
1659 extern NCURSES_EXPORT(void) _nc_signal_handler (bool);
1660 extern NCURSES_EXPORT(void) _nc_synchook (WINDOW *);
1661 extern NCURSES_EXPORT(void) _nc_trace_tries (TRIES *);
1664 extern NCURSES_EXPORT(void) _nc_alloc_entry_leaks(void);
1665 extern NCURSES_EXPORT(void) _nc_captoinfo_leaks(void);
1666 extern NCURSES_EXPORT(void) _nc_codes_leaks(void);
1667 extern NCURSES_EXPORT(void) _nc_comp_captab_leaks(void);
1668 extern NCURSES_EXPORT(void) _nc_comp_scan_leaks(void);
1669 extern NCURSES_EXPORT(void) _nc_keyname_leaks(void);
1670 extern NCURSES_EXPORT(void) _nc_names_leaks(void);
1671 extern NCURSES_EXPORT(void) _nc_tgetent_leaks(void);
1675 extern NCURSES_EXPORT(NCURSES_CH_T) _nc_render (WINDOW *, NCURSES_CH_T);
1676 extern NCURSES_EXPORT(int) _nc_waddch_nosync (WINDOW *, const NCURSES_CH_T);
1677 extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, NCURSES_SIZE_T const, NCURSES_SIZE_T const, NCURSES_CH_T);
1680 #if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
1681 extern NCURSES_EXPORT(size_t) _nc_wcrtomb (char *, wchar_t, mbstate_t *);
1685 extern NCURSES_EXPORT(void) _nc_update_screensize (SCREEN *);
1689 extern NCURSES_EXPORT(void) _nc_resize_margins (WINDOW *);
1691 #define _nc_resize_margins(wp) /* nothing */
1694 #ifdef NCURSES_WGETCH_EVENTS
1695 extern NCURSES_EXPORT(int) _nc_eventlist_timeout(_nc_eventlist *);
1697 #define wgetch_events(win, evl) wgetch(win)
1698 #define wgetnstr_events(win, str, maxlen, evl) wgetnstr(win, str, maxlen)
1702 * Not everyone has vsscanf(), but we'd like to use it for scanw().
1705 extern int vsscanf(const char *str, const char *format, va_list __arg);
1708 /* scroll indices */
1709 extern NCURSES_EXPORT_VAR(int *) _nc_oldnums;
1711 #define USE_SETBUF_0 0
1713 #define NC_BUFFERED(flag) _nc_set_buffer(SP->_ofp, flag)
1715 #define NC_OUTPUT ((SP_PARM != 0) ? SP_PARM->_ofp : stdout)
1718 * On systems with a broken linker, define 'SP' as a function to force the
1719 * linker to pull in the data-only module with 'SP'.
1722 #define SP _nc_screen()
1723 extern NCURSES_EXPORT(SCREEN *) _nc_screen (void);
1724 extern NCURSES_EXPORT(int) _nc_alloc_screen (void);
1725 extern NCURSES_EXPORT(void) _nc_set_screen (SCREEN *);
1727 /* current screen is private data; avoid possible linking conflicts too */
1728 extern NCURSES_EXPORT_VAR(SCREEN *) SP;
1729 #define _nc_alloc_screen() ((SP = typeCalloc(SCREEN, 1)) != 0)
1730 #define _nc_set_screen(sp) SP = sp
1733 #define CURRENT_SCREEN SP
1735 #define CURRENT_SCREEN_PRE (IsPreScreen(CURRENT_SCREEN) ? CURRENT_SCREEN : new_prescr())
1738 * We don't want to use the lines or columns capabilities internally, because
1739 * if the application is running multiple screens under X, it's quite possible
1740 * they could all have type xterm but have different sizes! So...
1742 #define screen_lines(sp) (sp)->_lines
1743 #define screen_columns(sp) (sp)->_columns
1745 extern NCURSES_EXPORT(int) _nc_slk_initialize (WINDOW *, int);
1748 * Some constants related to SLK's
1750 #define MAX_SKEY_OLD 8 /* count of soft keys */
1751 #define MAX_SKEY_LEN_OLD 8 /* max length of soft key text */
1752 #define MAX_SKEY_PC 12 /* This is what most PC's have */
1753 #define MAX_SKEY_LEN_PC 5
1755 /* Macro to check whether or not we use a standard format */
1756 #define SLK_STDFMT(fmt) (fmt < 3)
1757 /* Macro to determine height of label window */
1758 #define SLK_LINES(fmt) (SLK_STDFMT(fmt) ? 1 : ((fmt) - 2))
1760 #define MAX_SKEY(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_OLD : MAX_SKEY_PC)
1761 #define MAX_SKEY_LEN(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_LEN_OLD : MAX_SKEY_LEN_PC)
1763 extern NCURSES_EXPORT(int) _nc_ripoffline (int line, int (*init)(WINDOW *,int));
1766 * Common error messages
1768 #define MSG_NO_MEMORY "Out of memory"
1769 #define MSG_NO_INPUTS "Premature EOF"
1771 /* timed_wait flag definitions */
1775 #define TW_ANY (TW_INPUT | TW_MOUSE)
1778 #define IsTermInfo(sp) TRUE
1779 #define HasTInfoTerminal(sp) ((0!=TerminalOf(sp)) && IsTermInfo(sp))
1780 #define IsValidTIScreen(sp) (HasTInfoTerminal(sp))
1783 * Exported entrypoints beyond the published API
1785 #if NCURSES_SP_FUNCS
1786 extern NCURSES_EXPORT(WINDOW *) _nc_curscr_of(SCREEN*);
1787 extern NCURSES_EXPORT(WINDOW *) _nc_newscr_of(SCREEN*);
1788 extern NCURSES_EXPORT(WINDOW *) _nc_stdscr_of(SCREEN*);
1789 extern NCURSES_EXPORT(int) _nc_outc_wrapper(SCREEN*,int);
1791 extern NCURSES_EXPORT(TERMINAL*) NCURSES_SP_NAME(_nc_set_curterm)(SCREEN*,TERMINAL*);
1793 #if NCURSES_EXT_FUNCS
1794 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_set_tabsize)(SCREEN*, int);
1797 extern NCURSES_EXPORT(chtype) NCURSES_SP_NAME(_nc_acs_char)(SCREEN*,int);
1800 * We put the safe versions of various calls here as they are not published
1801 * part of the API up to now
1803 extern NCURSES_EXPORT(SCREEN*) _nc_SP(void);
1805 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_vidputs)(SCREEN*,chtype,int(*) (SCREEN*, int));
1806 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_vidattr)(SCREEN *, chtype);
1808 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_scr_restore)(SCREEN*, const char*);
1809 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_scr_init)(SCREEN*,const char*);
1811 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_restartterm)(SCREEN*,NCURSES_CONST char*,int,int*);
1812 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_ripoffline)(SCREEN*, int, int (*)(WINDOW *,int));
1813 extern NCURSES_EXPORT(bool) NCURSES_SP_NAME(_nc_is_term_resized)(SCREEN*,int,int);
1814 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_resize_term)(SCREEN*,int,int);
1815 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_resizeterm)(SCREEN*,int,int);
1817 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_outch)(SCREEN*, int);
1818 extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_flush)(SCREEN*);
1819 extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_freeall)(SCREEN*);
1820 extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_free_and_exit)(SCREEN*, int);
1821 extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_hash_map)(SCREEN*);
1822 extern NCURSES_EXPORT(WINDOW *) NCURSES_SP_NAME(_nc_makenew) (SCREEN*, int, int, int, int, int);
1823 extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_make_oldhash)(SCREEN*, int i);
1824 extern NCURSES_EXPORT(char *) NCURSES_SP_NAME(_nc_printf_string)(SCREEN*, const char *, va_list);
1825 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_putp)(SCREEN*, const char *, const char *);
1826 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_putp_flush)(SCREEN*, const char *, const char *);
1827 extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_set_buffer)(SCREEN*, FILE *, bool);
1828 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_tgetent)(SCREEN*,char*,const char *);
1829 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_tputs)(SCREEN*,const char*,int,int(*)(SCREEN*, int));
1830 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_savetty)(SCREEN*);
1831 extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_screen_wrap)(SCREEN*);
1832 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_resetty)(SCREEN*);
1833 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_scrolln)(SCREEN*, int, int, int, int);
1834 extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_scroll_oldhash)(SCREEN*, int n, int top, int bot);
1835 extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_scroll_optimize)(SCREEN*);
1837 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_mcprint)(SCREEN*,char*, int);
1838 extern NCURSES_EXPORT(char *) NCURSES_SP_NAME(_nc_tgetstr)(SCREEN*,NCURSES_CONST char*,char**);
1839 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_tgetflag)(SCREEN*,NCURSES_CONST char*);
1840 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_tgetnum)(SCREEN*,NCURSES_CONST char*);
1841 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_tigetflag)(SCREEN*,NCURSES_CONST char*);
1842 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_tigetnum)(SCREEN*,NCURSES_CONST char*);
1843 extern NCURSES_EXPORT(char *) NCURSES_SP_NAME(_nc_tigetstr)(SCREEN*, NCURSES_CONST char*);
1844 extern NCURSES_EXPORT(void) _nc_cookie_init(SCREEN *sp);
1845 extern NCURSES_EXPORT(int) _nc_tinfo_doupdate(SCREEN *sp);
1846 extern NCURSES_EXPORT(int) _nc_tinfo_mcprint(SCREEN*,char*,int);
1848 #if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
1849 extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_linedump)(SCREEN*);
1852 #if USE_WIDEC_SUPPORT
1853 extern NCURSES_EXPORT(wchar_t *) NCURSES_SP_NAME(_nc_wunctrl)(SCREEN*, cchar_t *);
1856 /* FIXME - move these to curses.h.in */
1857 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(getmouse) (SCREEN*, MEVENT *);
1858 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(ungetmouse) (SCREEN*, MEVENT *);
1859 extern NCURSES_EXPORT(mmask_t) NCURSES_SP_NAME(mousemask) (SCREEN*, mmask_t, mmask_t *);
1860 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(mouseinterval) (SCREEN*, int);
1861 extern NCURSES_EXPORT(bool) NCURSES_SP_NAME(has_mouse) (SCREEN*);
1862 #endif /* NCURSES_SP_FUNCS */
1864 #if NCURSES_SP_FUNCS
1866 #define safe_keyname NCURSES_SP_NAME(keyname)
1867 #define safe_unctrl NCURSES_SP_NAME(unctrl)
1868 #define safe_ungetch NCURSES_SP_NAME(ungetch)
1872 #define safe_keyname _nc_keyname
1873 #define safe_unctrl _nc_unctrl
1874 #define safe_ungetch _nc_ungetch
1876 extern NCURSES_EXPORT(int) _nc_ungetch (SCREEN *, int);
1877 extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_unctrl (SCREEN *, chtype);
1885 #endif /* CURSES_PRIV_H */