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.403 2009/02/28 20:55:48 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->_LINES) : &(_nc_prescreen._LINES))
339 #define ptrCols() (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() &LINES
344 #define ptrCols() &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->_mouse_gpm_fd
530 #define my_Gpm_Open SP->_mouse_Gpm_Open
531 #define my_Gpm_Close SP->_mouse_Gpm_Close
532 #define my_Gpm_GetEvent SP->_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 /* usually in <limits.h> */
985 #define UCHAR_MAX 255
988 /* The terminfo source is assumed to be 7-bit ASCII */
989 #define is7bits(c) ((unsigned)(c) < 128)
991 /* Checks for isprint() should be done on 8-bit characters (non-wide) */
992 #define is8bits(c) ((unsigned)(c) <= UCHAR_MAX)
995 #define min(a,b) ((a) > (b) ? (b) : (a))
999 #define max(a,b) ((a) < (b) ? (b) : (a))
1002 /* usually in <unistd.h> */
1003 #ifndef STDIN_FILENO
1004 #define STDIN_FILENO 0
1007 #ifndef STDOUT_FILENO
1008 #define STDOUT_FILENO 1
1011 #ifndef STDERR_FILENO
1012 #define STDERR_FILENO 2
1015 #ifndef EXIT_SUCCESS
1016 #define EXIT_SUCCESS 0
1019 #ifndef EXIT_FAILURE
1020 #define EXIT_FAILURE 1
1024 #define R_OK 4 /* Test for read permission. */
1027 #define W_OK 2 /* Test for write permission. */
1030 #define X_OK 1 /* Test for execute permission. */
1033 #define F_OK 0 /* Test for existence. */
1037 #include <fcntl.h> /* may define O_BINARY */
1046 #define COUNT_OUTCHARS(n) _nc_count_outchars(n);
1048 #define COUNT_OUTCHARS(n) _nc_outchars += (n);
1051 #define COUNT_OUTCHARS(n) /* nothing */
1054 #define RESET_OUTCHARS() COUNT_OUTCHARS(-_nc_outchars)
1056 #define UChar(c) ((unsigned char)(c))
1057 #define ChCharOf(c) ((c) & (chtype)A_CHARTEXT)
1058 #define ChAttrOf(c) ((c) & (chtype)A_ATTRIBUTES)
1061 #define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */
1064 #if USE_WIDEC_SUPPORT /* { */
1065 #define isEILSEQ(status) (((size_t)status == (size_t)-1) && (errno == EILSEQ))
1067 #define init_mb(state) memset(&state, 0, sizeof(state))
1069 #if NCURSES_EXT_COLORS
1070 #define NulColor , 0
1072 #define NulColor /* nothing */
1075 #define NulChar 0,0,0,0 /* FIXME: see CCHARW_MAX */
1076 #define CharOf(c) ((c).chars[0])
1077 #define AttrOf(c) ((c).attr)
1079 #define AddAttr(c,a) AttrOf(c) |= ((a) & A_ATTRIBUTES)
1080 #define RemAttr(c,a) AttrOf(c) &= ~((a) & A_ATTRIBUTES)
1081 #define SetAttr(c,a) AttrOf(c) = ((a) & A_ATTRIBUTES) | WidecExt(c)
1083 #define NewChar2(c,a) { a, { c, NulChar } NulColor }
1084 #define NewChar(ch) NewChar2(ChCharOf(ch), ChAttrOf(ch))
1087 #define CharEq(a,b) (((a).attr == (b).attr) \
1088 && (a).chars[0] == (b).chars[0] \
1089 && (a).chars[1] == (b).chars[1] \
1090 && (a).chars[2] == (b).chars[2] \
1091 && (a).chars[3] == (b).chars[3] \
1092 && (a).chars[4] == (b).chars[4] \
1093 if_EXT_COLORS(&& (a).ext_color == (b).ext_color))
1095 #define CharEq(a,b) (!memcmp(&(a), &(b), sizeof(a)))
1098 #define SetChar(ch,c,a) do { \
1099 NCURSES_CH_T *_cp = &ch; \
1100 memset(_cp, 0, sizeof(ch)); \
1101 _cp->chars[0] = (c); \
1103 if_EXT_COLORS(SetPair(ch, PAIR_NUMBER(a))); \
1105 #define CHREF(wch) (&wch)
1106 #define CHDEREF(wch) (*wch)
1107 #define ARG_CH_T NCURSES_CH_T *
1108 #define CARG_CH_T const NCURSES_CH_T *
1109 #define PUTC_DATA char PUTC_buf[MB_LEN_MAX]; int PUTC_i, PUTC_n; \
1110 mbstate_t PUT_st; wchar_t PUTC_ch
1111 #define PUTC_INIT init_mb (PUT_st)
1112 #define PUTC(ch,b) do { if(!isWidecExt(ch)) { \
1113 if (Charable(ch)) { \
1114 fputc(CharOf(ch), b); \
1115 COUNT_OUTCHARS(1); \
1118 for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { \
1119 PUTC_ch = (ch).chars[PUTC_i]; \
1120 if (PUTC_ch == L'\0') \
1122 PUTC_n = wcrtomb(PUTC_buf, \
1123 (ch).chars[PUTC_i], &PUT_st); \
1124 if (PUTC_n <= 0) { \
1125 if (PUTC_ch && is8bits(PUTC_ch) && PUTC_i == 0) \
1129 fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b); \
1131 COUNT_OUTCHARS(PUTC_i); \
1134 #define BLANK NewChar2(' ', WA_NORMAL)
1135 #define ZEROS NewChar2('\0', WA_NORMAL)
1136 #define ISBLANK(ch) ((ch).chars[0] == L' ' && (ch).chars[1] == L'\0')
1139 * Wide characters cannot be represented in the A_CHARTEXT mask of
1140 * attr_t's but an application might have set a narrow character there.
1141 * But even in that case, it would only be a printable character, or
1142 * zero. Otherwise we can use those bits to tell if a cell is the
1143 * first or extension part of a wide character.
1145 #define WidecExt(ch) (AttrOf(ch) & A_CHARTEXT)
1146 #define isWidecBase(ch) (WidecExt(ch) == 1)
1147 #define isWidecExt(ch) (WidecExt(ch) > 1 && WidecExt(ch) < 32)
1148 #define SetWidecExt(dst, ext) AttrOf(dst) &= ~A_CHARTEXT, \
1149 AttrOf(dst) |= (ext + 1)
1151 #define if_WIDEC(code) code
1152 #define Charable(ch) ((SP != 0 && SP->_legacy_coding) \
1153 || (AttrOf(ch) & A_ALTCHARSET) \
1154 || (!isWidecExt(ch) && \
1155 (ch).chars[1] == L'\0' && \
1156 _nc_is_charable(CharOf(ch))))
1158 #define L(ch) L ## ch
1160 #define CharOf(c) ChCharOf(c)
1161 #define AttrOf(c) ChAttrOf(c)
1162 #define AddAttr(c,a) c |= (a)
1163 #define RemAttr(c,a) c &= ~((a) & A_ATTRIBUTES)
1164 #define SetAttr(c,a) c = ((c) & ~A_ATTRIBUTES) | (a)
1165 #define NewChar(ch) (ch)
1166 #define NewChar2(c,a) ((c) | (a))
1167 #define CharEq(a,b) ((a) == (b))
1168 #define SetChar(ch,c,a) ch = (c) | (a)
1169 #define CHREF(wch) wch
1170 #define CHDEREF(wch) wch
1171 #define ARG_CH_T NCURSES_CH_T
1172 #define CARG_CH_T NCURSES_CH_T
1173 #define PUTC_DATA int data = 0
1174 #define PUTC(ch,b) do { data = CharOf(ch); putc(data,b); } while (0)
1176 #define BLANK (' '|A_NORMAL)
1177 #define ZEROS ('\0'|A_NORMAL)
1178 #define ISBLANK(ch) (CharOf(ch) == ' ')
1180 #define isWidecExt(ch) (0)
1181 #define if_WIDEC(code) /* nothing */
1186 #define AttrOfD(ch) AttrOf(CHDEREF(ch))
1187 #define CharOfD(ch) CharOf(CHDEREF(ch))
1188 #define SetChar2(wch,ch) SetChar(wch,ChCharOf(ch),ChAttrOf(ch))
1190 #define BLANK_ATTR A_NORMAL
1191 #define BLANK_TEXT L(' ')
1195 #define LEGALYX(w, y, x) \
1197 ((x) >= 0 && (x) <= (w)->_maxx && \
1198 (y) >= 0 && (y) <= (w)->_maxy))
1200 #define CHANGED_CELL(line,col) \
1201 if (line->firstchar == _NOCHANGE) \
1202 line->firstchar = line->lastchar = col; \
1203 else if ((col) < line->firstchar) \
1204 line->firstchar = col; \
1205 else if ((col) > line->lastchar) \
1206 line->lastchar = col
1208 #define CHANGED_RANGE(line,start,end) \
1209 if (line->firstchar == _NOCHANGE \
1210 || line->firstchar > (start)) \
1211 line->firstchar = start; \
1212 if (line->lastchar == _NOCHANGE \
1213 || line->lastchar < (end)) \
1214 line->lastchar = end
1216 #define CHANGED_TO_EOL(line,start,end) \
1217 if (line->firstchar == _NOCHANGE \
1218 || line->firstchar > (start)) \
1219 line->firstchar = start; \
1220 line->lastchar = end
1222 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
1224 #define FreeIfNeeded(p) if ((p) != 0) free(p)
1226 /* FreeAndNull() is not a comma-separated expression because some compilers
1227 * do not accept a mixture of void with values.
1229 #define FreeAndNull(p) free(p); p = 0
1231 #include <nc_alloc.h>
1234 * TTY bit definition for converting tabs to spaces.
1237 # define OFLAGS_TABS TAB3 /* POSIX specifies TAB3 */
1240 # define OFLAGS_TABS XTABS /* XTABS is usually the "same" */
1243 # define OFLAGS_TABS OXTABS /* the traditional BSD equivalent */
1245 # define OFLAGS_TABS 0
1251 * Standardize/simplify common loops
1253 #define each_screen(p) p = _nc_screen_chain; p != 0; p = (p)->_next_screen
1254 #define each_window(p) p = _nc_windows; p != 0; p = (p)->next
1255 #define each_ripoff(p) p = ripoff_stack; (p - ripoff_stack) < N_RIPS; ++p
1258 * Prefixes for call/return points of library function traces. We use these to
1259 * instrument the public functions so that the traces can be easily transformed
1260 * into regression scripts.
1262 #define T_CALLED(fmt) "called {" fmt
1263 #define T_CREATE(fmt) "create :" fmt
1264 #define T_RETURN(fmt) "return }" fmt
1269 #define TPUTS_TRACE(s) _nc_set_tputs_trace(s);
1271 #define TPUTS_TRACE(s) _nc_tputs_trace = s;
1274 #define START_TRACE() \
1275 if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
1276 int t = _nc_getenv_num("NCURSES_TRACE"); \
1278 trace((unsigned) t); \
1282 * Many of the _tracef() calls use static buffers; lock the trace state before
1283 * trying to fill them.
1286 #define USE_TRACEF(mask) _nc_use_tracef(mask)
1287 extern NCURSES_EXPORT(int) _nc_use_tracef (unsigned);
1288 extern NCURSES_EXPORT(void) _nc_locked_tracef (const char *, ...) GCC_PRINTFLIKE(1,2);
1290 #define USE_TRACEF(mask) (_nc_tracing & (mask))
1291 #define _nc_locked_tracef _tracef
1294 #define TR(n, a) if (USE_TRACEF(n)) _nc_locked_tracef a
1295 #define T(a) TR(TRACE_CALLS, a)
1296 #define TRACE_RETURN(value,type) return _nc_retrace_##type(value)
1298 #define returnAttr(code) TRACE_RETURN(code,attr_t)
1299 #define returnBits(code) TRACE_RETURN(code,unsigned)
1300 #define returnBool(code) TRACE_RETURN(code,bool)
1301 #define returnCPtr(code) TRACE_RETURN(code,cptr)
1302 #define returnCVoidPtr(code) TRACE_RETURN(code,cvoid_ptr)
1303 #define returnChtype(code) TRACE_RETURN(code,chtype)
1304 #define returnCode(code) TRACE_RETURN(code,int)
1305 #define returnPtr(code) TRACE_RETURN(code,ptr)
1306 #define returnSP(code) TRACE_RETURN(code,sp)
1307 #define returnVoid T((T_RETURN(""))); return
1308 #define returnVoidPtr(code) TRACE_RETURN(code,void_ptr)
1309 #define returnWin(code) TRACE_RETURN(code,win)
1311 extern NCURSES_EXPORT(NCURSES_BOOL) _nc_retrace_bool (NCURSES_BOOL);
1312 extern NCURSES_EXPORT(NCURSES_CONST void *) _nc_retrace_cvoid_ptr (NCURSES_CONST void *);
1313 extern NCURSES_EXPORT(SCREEN *) _nc_retrace_sp (SCREEN *);
1314 extern NCURSES_EXPORT(WINDOW *) _nc_retrace_win (WINDOW *);
1315 extern NCURSES_EXPORT(attr_t) _nc_retrace_attr_t (attr_t);
1316 extern NCURSES_EXPORT(char *) _nc_retrace_ptr (char *);
1317 extern NCURSES_EXPORT(char *) _nc_trace_ttymode(TTY *tty);
1318 extern NCURSES_EXPORT(char *) _nc_varargs (const char *, va_list);
1319 extern NCURSES_EXPORT(chtype) _nc_retrace_chtype (chtype);
1320 extern NCURSES_EXPORT(const char *) _nc_altcharset_name(attr_t, chtype);
1321 extern NCURSES_EXPORT(const char *) _nc_retrace_cptr (const char *);
1322 extern NCURSES_EXPORT(int) _nc_retrace_int (int);
1323 extern NCURSES_EXPORT(unsigned) _nc_retrace_unsigned (unsigned);
1324 extern NCURSES_EXPORT(void *) _nc_retrace_void_ptr (void *);
1325 extern NCURSES_EXPORT(void) _nc_fifo_dump (SCREEN *);
1328 NCURSES_WRAPPED_VAR(long, _nc_outchars);
1329 NCURSES_WRAPPED_VAR(const char *, _nc_tputs_trace);
1330 #define _nc_outchars NCURSES_PUBLIC_VAR(_nc_outchars())
1331 #define _nc_tputs_trace NCURSES_PUBLIC_VAR(_nc_tputs_trace())
1332 extern NCURSES_EXPORT(void) _nc_set_tputs_trace (const char *);
1333 extern NCURSES_EXPORT(void) _nc_count_outchars (long);
1335 extern NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace;
1336 extern NCURSES_EXPORT_VAR(long) _nc_outchars;
1339 extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing;
1341 #if USE_WIDEC_SUPPORT
1342 extern NCURSES_EXPORT(const char *) _nc_viswbuf2 (int, const wchar_t *);
1343 extern NCURSES_EXPORT(const char *) _nc_viswbufn (const wchar_t *, int);
1346 extern NCURSES_EXPORT(const char *) _nc_viscbuf2 (int, const NCURSES_CH_T *, int);
1347 extern NCURSES_EXPORT(const char *) _nc_viscbuf (const NCURSES_CH_T *, int);
1351 #define START_TRACE() /* nothing */
1355 #define TPUTS_TRACE(s)
1357 #define returnAttr(code) return code
1358 #define returnBits(code) return code
1359 #define returnBool(code) return code
1360 #define returnCPtr(code) return code
1361 #define returnCVoidPtr(code) return code
1362 #define returnChtype(code) return code
1363 #define returnCode(code) return code
1364 #define returnPtr(code) return code
1365 #define returnSP(code) return code
1366 #define returnVoid return
1367 #define returnVoidPtr(code) return code
1368 #define returnWin(code) return code
1370 #endif /* TRACE/!TRACE */
1373 * Return-codes for tgetent() and friends.
1375 #define TGETENT_YES 1 /* entry is found */
1376 #define TGETENT_NO 0 /* entry is not found */
1377 #define TGETENT_ERR -1 /* an error occurred */
1379 extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *);
1380 extern NCURSES_EXPORT(const char *) _nc_visbufn (const char *, int);
1382 #define EMPTY_MODULE(name) \
1383 extern NCURSES_EXPORT(void) name (void); \
1384 NCURSES_EXPORT(void) name (void) { }
1386 #define ALL_BUT_COLOR ((chtype)~(A_COLOR))
1387 #define NONBLANK_ATTR (A_NORMAL|A_BOLD|A_DIM|A_BLINK)
1388 #define XMC_CHANGES(c) ((c) & SP->_xmc_suppress)
1390 #define toggle_attr_on(S,at) {\
1391 if (PAIR_NUMBER(at) > 0) {\
1392 (S) = ((S) & ALL_BUT_COLOR) | (at);\
1396 TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
1399 #define toggle_attr_off(S,at) {\
1400 if (PAIR_NUMBER(at) > 0) {\
1401 (S) &= ~(at|A_COLOR);\
1405 TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
1407 #define DelCharCost(count) \
1410 : ((delete_character != 0) \
1411 ? (SP->_dch1_cost * count) \
1414 #define InsCharCost(count) \
1417 : ((enter_insert_mode && exit_insert_mode) \
1418 ? SP->_smir_cost + SP->_rmir_cost + (SP->_ip_cost * count) \
1419 : ((insert_character != 0) \
1420 ? ((SP->_ich1_cost + SP->_ip_cost) * count) \
1424 #define UpdateAttrs(c) if (!SameAttrOf(SCREEN_ATTRS(SP), c)) { \
1425 attr_t chg = AttrOf(SCREEN_ATTRS(SP)); \
1426 VIDATTR(AttrOf(c), GetPair(c)); \
1427 if (magic_cookie_glitch > 0 \
1428 && XMC_CHANGES((chg ^ AttrOf(SCREEN_ATTRS(SP))))) { \
1429 T(("%s @%d before glitch %d,%d", \
1430 __FILE__, __LINE__, \
1433 _nc_do_xmc_glitch(chg); \
1437 #define UpdateAttrs(c) if (!SameAttrOf(SCREEN_ATTRS(SP), c)) \
1438 VIDATTR(AttrOf(c), GetPair(c));
1442 * Macros to make additional parameter to implement wgetch_events()
1444 #ifdef NCURSES_WGETCH_EVENTS
1445 #define EVENTLIST_0th(param) param
1446 #define EVENTLIST_1st(param) param
1447 #define EVENTLIST_2nd(param) , param
1449 #define EVENTLIST_0th(param) void
1450 #define EVENTLIST_1st(param) /* nothing */
1451 #define EVENTLIST_2nd(param) /* nothing */
1454 #if NCURSES_EXPANDED && NCURSES_EXT_FUNCS
1456 #undef toggle_attr_on
1457 #define toggle_attr_on(S,at) _nc_toggle_attr_on(&(S), at)
1458 extern NCURSES_EXPORT(void) _nc_toggle_attr_on (attr_t *, attr_t);
1460 #undef toggle_attr_off
1461 #define toggle_attr_off(S,at) _nc_toggle_attr_off(&(S), at)
1462 extern NCURSES_EXPORT(void) _nc_toggle_attr_off (attr_t *, attr_t);
1465 #define DelCharCost(count) _nc_DelCharCost(count)
1466 extern NCURSES_EXPORT(int) _nc_DelCharCost (int);
1469 #define InsCharCost(count) _nc_InsCharCost(count)
1470 extern NCURSES_EXPORT(int) _nc_InsCharCost (int);
1473 #define UpdateAttrs(c) _nc_UpdateAttrs(c)
1474 extern NCURSES_EXPORT(void) _nc_UpdateAttrs (NCURSES_CH_T);
1478 extern NCURSES_EXPORT(void) _nc_expanded (void);
1482 #if !NCURSES_EXT_FUNCS
1483 #define set_escdelay(value) ESCDELAY = value
1487 #define getcwd(buf,len) getwd(buf)
1491 #if USE_WIDEC_SUPPORT
1492 extern NCURSES_EXPORT(bool) _nc_is_charable(wchar_t);
1493 extern NCURSES_EXPORT(int) _nc_to_char(wint_t);
1494 extern NCURSES_EXPORT(wint_t) _nc_to_widechar(int);
1499 short nte_name; /* offset of name to hash on */
1500 int nte_type; /* BOOLEAN, NUMBER or STRING */
1501 short nte_index; /* index of associated variable in its array */
1502 short nte_link; /* index in table of next hash, or -1 */
1514 extern NCURSES_EXPORT(void) _nc_do_xmc_glitch (attr_t);
1518 #if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
1519 extern NCURSES_EXPORT(void) _nc_linedump (void);
1523 extern NCURSES_EXPORT(void) _nc_init_acs (void); /* corresponds to traditional 'init_acs()' */
1524 extern NCURSES_EXPORT(int) _nc_msec_cost (const char *const, int); /* used by 'tack' program */
1527 #if USE_WIDEC_SUPPORT
1528 NCURSES_EXPORT(int) _nc_build_wch(WINDOW *win, ARG_CH_T ch);
1532 #if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
1533 extern NCURSES_EXPORT(int) _nc_wchstrlen(const cchar_t *);
1537 extern NCURSES_EXPORT(bool) _nc_reset_colors(void);
1540 extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, unsigned long *, int EVENTLIST_2nd(_nc_eventlist *));
1543 extern NCURSES_EXPORT(int) _nc_insert_ch(WINDOW *, chtype);
1546 #define INFINITY 1000000 /* cost: too high to use */
1548 extern NCURSES_EXPORT(void) _nc_mvcur_init (void);
1549 extern NCURSES_EXPORT(void) _nc_mvcur_resume (void);
1550 extern NCURSES_EXPORT(void) _nc_mvcur_wrap (void);
1552 extern NCURSES_EXPORT(int) _nc_scrolln (int, int, int, int);
1554 extern NCURSES_EXPORT(void) _nc_screen_init (void);
1555 extern NCURSES_EXPORT(void) _nc_screen_resume (void);
1556 extern NCURSES_EXPORT(void) _nc_screen_wrap (void);
1559 extern NCURSES_EXPORT(bool) _nc_has_mouse (SCREEN *);
1562 #define INFINITY 1000000 /* cost: too high to use */
1563 #define BAUDBYTE 9 /* 9 = 7 bits + 1 parity + 1 stop */
1566 extern NCURSES_EXPORT(char *) _nc_get_locale(void);
1567 extern NCURSES_EXPORT(int) _nc_unicode_locale(void);
1568 extern NCURSES_EXPORT(int) _nc_locale_breaks_acs(TERMINAL *);
1569 extern NCURSES_EXPORT(int) _nc_setupterm(NCURSES_CONST char *, int, int *, bool);
1570 extern NCURSES_EXPORT(void) _nc_get_screensize(SCREEN *, int *, int *);
1574 extern NCURSES_EXPORT(int) _nc_handle_sigwinch(SCREEN *);
1576 #define _nc_handle_sigwinch(a) /* nothing */
1580 extern NCURSES_EXPORT(int) _nc_ungetch (SCREEN *, int);
1583 #if USE_WIDEC_SUPPORT
1584 extern NCURSES_EXPORT(void) _nc_init_wacs(void);
1588 char *s_head; /* beginning of the string (may be null) */
1589 char *s_tail; /* end of the string (may be null) */
1590 size_t s_size; /* current remaining size available */
1591 size_t s_init; /* total size available */
1595 extern NCURSES_EXPORT(string_desc *) _nc_str_init (string_desc *, char *, size_t);
1596 extern NCURSES_EXPORT(string_desc *) _nc_str_null (string_desc *, size_t);
1597 extern NCURSES_EXPORT(string_desc *) _nc_str_copy (string_desc *, string_desc *);
1598 extern NCURSES_EXPORT(bool) _nc_safe_strcat (string_desc *, const char *);
1599 extern NCURSES_EXPORT(bool) _nc_safe_strcpy (string_desc *, const char *);
1602 #define strstr _nc_strstr
1603 extern NCURSES_EXPORT(char *) _nc_strstr (const char *, const char *);
1606 /* safe_sprintf.c */
1607 extern NCURSES_EXPORT(char *) _nc_printf_string (const char *, va_list);
1610 extern NCURSES_EXPORT(int) _nc_add_to_try (TRIES **, const char *, unsigned);
1611 extern NCURSES_EXPORT(char *) _nc_expand_try (TRIES *, unsigned, int *, size_t);
1612 extern NCURSES_EXPORT(int) _nc_remove_key (TRIES **, unsigned);
1613 extern NCURSES_EXPORT(int) _nc_remove_string (TRIES **, const char *);
1616 extern NCURSES_EXPORT(ENTRY *) _nc_delink_entry (ENTRY *, TERMTYPE *);
1617 extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_keyname (SCREEN *, int);
1618 extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_unctrl (SCREEN *, chtype);
1619 extern NCURSES_EXPORT(SCREEN *) _nc_screen_of (WINDOW *);
1620 extern NCURSES_EXPORT(WINDOW *) _nc_makenew (int, int, int, int, int);
1621 extern NCURSES_EXPORT(char *) _nc_trace_buf (int, size_t);
1622 extern NCURSES_EXPORT(char *) _nc_trace_bufcat (int, const char *);
1623 extern NCURSES_EXPORT(char *) _nc_tracechar (SCREEN *, int);
1624 extern NCURSES_EXPORT(char *) _nc_tracemouse (SCREEN *, MEVENT const *);
1625 extern NCURSES_EXPORT(int) _nc_access (const char *, int);
1626 extern NCURSES_EXPORT(int) _nc_baudrate (int);
1627 extern NCURSES_EXPORT(int) _nc_freewin (WINDOW *);
1628 extern NCURSES_EXPORT(int) _nc_getenv_num (const char *);
1629 extern NCURSES_EXPORT(int) _nc_keypad (SCREEN *, bool);
1630 extern NCURSES_EXPORT(int) _nc_ospeed (int);
1631 extern NCURSES_EXPORT(int) _nc_outch (int);
1632 extern NCURSES_EXPORT(int) _nc_putp(const char *, const char *);
1633 extern NCURSES_EXPORT(int) _nc_putp_flush(const char *, const char *);
1634 extern NCURSES_EXPORT(int) _nc_read_termcap_entry (const char *const, TERMTYPE *const);
1635 extern NCURSES_EXPORT(int) _nc_setupscreen (int, int, FILE *, bool, int);
1636 extern NCURSES_EXPORT(int) _nc_timed_wait (SCREEN *, int, int, int * EVENTLIST_2nd(_nc_eventlist *));
1637 extern NCURSES_EXPORT(void) _nc_do_color (short, short, bool, int (*)(int));
1638 extern NCURSES_EXPORT(void) _nc_flush (void);
1639 extern NCURSES_EXPORT(void) _nc_free_and_exit (int);
1640 extern NCURSES_EXPORT(void) _nc_free_entry (ENTRY *, TERMTYPE *);
1641 extern NCURSES_EXPORT(void) _nc_freeall (void);
1642 extern NCURSES_EXPORT(void) _nc_hash_map (void);
1643 extern NCURSES_EXPORT(void) _nc_init_keytry (SCREEN *);
1644 extern NCURSES_EXPORT(void) _nc_keep_tic_dir (const char *);
1645 extern NCURSES_EXPORT(void) _nc_make_oldhash (int i);
1646 extern NCURSES_EXPORT(void) _nc_scroll_oldhash (int n, int top, int bot);
1647 extern NCURSES_EXPORT(void) _nc_scroll_optimize (void);
1648 extern NCURSES_EXPORT(void) _nc_set_buffer (FILE *, bool);
1649 extern NCURSES_EXPORT(void) _nc_signal_handler (bool);
1650 extern NCURSES_EXPORT(void) _nc_synchook (WINDOW *);
1651 extern NCURSES_EXPORT(void) _nc_trace_tries (TRIES *);
1654 extern NCURSES_EXPORT(void) _nc_alloc_entry_leaks(void);
1655 extern NCURSES_EXPORT(void) _nc_captoinfo_leaks(void);
1656 extern NCURSES_EXPORT(void) _nc_codes_leaks(void);
1657 extern NCURSES_EXPORT(void) _nc_comp_captab_leaks(void);
1658 extern NCURSES_EXPORT(void) _nc_comp_scan_leaks(void);
1659 extern NCURSES_EXPORT(void) _nc_keyname_leaks(void);
1660 extern NCURSES_EXPORT(void) _nc_names_leaks(void);
1661 extern NCURSES_EXPORT(void) _nc_tgetent_leaks(void);
1665 extern NCURSES_EXPORT(NCURSES_CH_T) _nc_render (WINDOW *, NCURSES_CH_T);
1666 extern NCURSES_EXPORT(int) _nc_waddch_nosync (WINDOW *, const NCURSES_CH_T);
1667 extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, NCURSES_SIZE_T const, NCURSES_SIZE_T const, NCURSES_CH_T);
1670 #if USE_WIDEC_SUPPORT && !defined(USE_TERMLIB)
1671 extern NCURSES_EXPORT(size_t) _nc_wcrtomb (char *, wchar_t, mbstate_t *);
1675 extern NCURSES_EXPORT(void) _nc_update_screensize (SCREEN *);
1679 extern NCURSES_EXPORT(void) _nc_resize_margins (WINDOW *);
1681 #define _nc_resize_margins(wp) /* nothing */
1684 #ifdef NCURSES_WGETCH_EVENTS
1685 extern NCURSES_EXPORT(int) _nc_eventlist_timeout(_nc_eventlist *);
1687 #define wgetch_events(win, evl) wgetch(win)
1688 #define wgetnstr_events(win, str, maxlen, evl) wgetnstr(win, str, maxlen)
1692 * Not everyone has vsscanf(), but we'd like to use it for scanw().
1695 extern int vsscanf(const char *str, const char *format, va_list __arg);
1698 /* scroll indices */
1699 extern NCURSES_EXPORT_VAR(int *) _nc_oldnums;
1701 #define USE_SETBUF_0 0
1703 #define NC_BUFFERED(flag) _nc_set_buffer(SP->_ofp, flag)
1705 #define NC_OUTPUT ((SP_PARM != 0) ? SP_PARM->_ofp : stdout)
1708 * On systems with a broken linker, define 'SP' as a function to force the
1709 * linker to pull in the data-only module with 'SP'.
1712 #define SP _nc_screen()
1713 extern NCURSES_EXPORT(SCREEN *) _nc_screen (void);
1714 extern NCURSES_EXPORT(int) _nc_alloc_screen (void);
1715 extern NCURSES_EXPORT(void) _nc_set_screen (SCREEN *);
1717 /* current screen is private data; avoid possible linking conflicts too */
1718 extern NCURSES_EXPORT_VAR(SCREEN *) SP;
1719 #define _nc_alloc_screen() ((SP = typeCalloc(SCREEN, 1)) != 0)
1720 #define _nc_set_screen(sp) SP = sp
1723 #define CURRENT_SCREEN SP
1726 * We don't want to use the lines or columns capabilities internally, because
1727 * if the application is running multiple screens under X, it's quite possible
1728 * they could all have type xterm but have different sizes! So...
1730 #define screen_lines SP->_lines
1731 #define screen_columns SP->_columns
1733 extern NCURSES_EXPORT(int) _nc_slk_initialize (WINDOW *, int);
1736 * Some constants related to SLK's
1738 #define MAX_SKEY_OLD 8 /* count of soft keys */
1739 #define MAX_SKEY_LEN_OLD 8 /* max length of soft key text */
1740 #define MAX_SKEY_PC 12 /* This is what most PC's have */
1741 #define MAX_SKEY_LEN_PC 5
1743 /* Macro to check whether or not we use a standard format */
1744 #define SLK_STDFMT(fmt) (fmt < 3)
1745 /* Macro to determine height of label window */
1746 #define SLK_LINES(fmt) (SLK_STDFMT(fmt) ? 1 : ((fmt) - 2))
1748 #define MAX_SKEY(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_OLD : MAX_SKEY_PC)
1749 #define MAX_SKEY_LEN(fmt) (SLK_STDFMT(fmt)? MAX_SKEY_LEN_OLD : MAX_SKEY_LEN_PC)
1751 extern NCURSES_EXPORT(int) _nc_ripoffline (int line, int (*init)(WINDOW *,int));
1754 * Common error messages
1756 #define MSG_NO_MEMORY "Out of memory"
1757 #define MSG_NO_INPUTS "Premature EOF"
1759 /* timed_wait flag definitions */
1763 #define TW_ANY (TW_INPUT | TW_MOUSE)
1767 * Exported entrypoints beyond the published API
1769 #if NCURSES_SP_FUNCS
1770 extern NCURSES_EXPORT(WINDOW *) _nc_curscr_of(SCREEN*);
1771 extern NCURSES_EXPORT(WINDOW *) _nc_newscr_of(SCREEN*);
1772 extern NCURSES_EXPORT(WINDOW *) _nc_stdscr_of(SCREEN*);
1773 extern NCURSES_EXPORT(int) _nc_outc_wrapper(SCREEN*,int);
1775 extern NCURSES_EXPORT(TERMINAL*) NCURSES_SP_NAME(_nc_set_curterm)(SCREEN*,TERMINAL*);
1776 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_del_curterm)(SCREEN*,TERMINAL*);
1778 #if NCURSES_EXT_FUNCS
1779 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_set_tabsize)(SCREEN*, int);
1782 extern NCURSES_EXPORT(chtype) NCURSES_SP_NAME(_nc_acs_char)(SCREEN*,int);
1785 * We put the safe versions of various calls here as they are not published
1786 * part of the API up to now
1788 extern NCURSES_EXPORT(SCREEN*) _nc_SP(void);
1790 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_vidputs)(SCREEN*,chtype,int(*) (SCREEN*, int));
1791 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_vidattr)(SCREEN *, chtype);
1793 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_scr_restore)(SCREEN*, const char*);
1794 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_scr_init)(SCREEN*,const char*);
1796 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_restartterm)(SCREEN*,NCURSES_CONST char*,int,int*);
1797 extern NCURSES_EXPORT(bool) NCURSES_SP_NAME(_nc_is_term_resized)(SCREEN*,int,int);
1798 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_resize_term)(SCREEN*,int,int);
1799 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_resizeterm)(SCREEN*,int,int);
1801 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_outch)(SCREEN*, int ch);
1802 extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_flush)(SCREEN*);
1803 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_putp)(SCREEN*, const char *, const char *);
1804 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_putp_flush)(SCREEN*, const char *, const char *);
1805 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_tgetent)(SCREEN*,char*,const char *);
1806 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_tputs)(SCREEN*,const char*,int,int(*)(SCREEN*, int));
1807 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_savetty)(SCREEN*);
1808 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_resetty)(SCREEN*);
1810 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_mcprint)(SCREEN*,char*, int);
1811 extern NCURSES_EXPORT(char *) NCURSES_SP_NAME(_nc_tgetstr)(SCREEN*,NCURSES_CONST char*,char**);
1812 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_tgetflag)(SCREEN*,NCURSES_CONST char*);
1813 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_tgetnum)(SCREEN*,NCURSES_CONST char*);
1814 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_tigetflag)(SCREEN*,NCURSES_CONST char*);
1815 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_tigetnum)(SCREEN*,NCURSES_CONST char*);
1816 extern NCURSES_EXPORT(char *) NCURSES_SP_NAME(_nc_tigetstr)(SCREEN*, NCURSES_CONST char*);
1817 extern NCURSES_EXPORT(void) _nc_cookie_init(SCREEN *sp);
1818 extern NCURSES_EXPORT(int) _nc_tinfo_doupdate(SCREEN *sp);
1819 extern NCURSES_EXPORT(int) _nc_tinfo_mcprint(SCREEN*,char*,int);
1820 #if USE_WIDEC_SUPPORT
1821 extern NCURSES_EXPORT(wchar_t *) NCURSES_SP_NAME(_nc_wunctrl)(SCREEN*, cchar_t *);
1824 /* FIXME - move these to curses.h.in */
1825 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(getmouse) (SCREEN*, MEVENT *);
1826 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(ungetmouse) (SCREEN*, MEVENT *);
1827 extern NCURSES_EXPORT(mmask_t) NCURSES_SP_NAME(mousemask) (SCREEN*, mmask_t, mmask_t *);
1828 extern NCURSES_EXPORT(int) NCURSES_SP_NAME(mouseinterval) (SCREEN*, int);
1829 extern NCURSES_EXPORT(bool) NCURSES_SP_NAME(has_mouse) (SCREEN*);
1830 #endif /* NCURSES_SP_FUNCS */
1836 #endif /* CURSES_PRIV_H */