+/*
+ * Structures for soft labels.
+ */
+
+struct _SLK;
+
+#if !(defined(USE_TERMLIB) || defined(USE_BUILD_CC))
+
+typedef struct
+{
+ char *ent_text; /* text for the label */
+ char *form_text; /* formatted text (left/center/...) */
+ int ent_x; /* x coordinate of this field */
+ char dirty; /* this label has changed */
+ char visible; /* field is visible */
+} slk_ent;
+
+typedef struct _SLK {
+ bool dirty; /* all labels have changed */
+ bool hidden; /* soft labels are hidden */
+ WINDOW *win;
+ slk_ent *ent;
+ short maxlab; /* number of available labels */
+ short labcnt; /* number of allocated labels */
+ short maxlen; /* length of labels */
+ NCURSES_CH_T attr; /* soft label attribute */
+} SLK;
+
+#endif /* USE_TERMLIB */
+
+typedef struct {
+ WINDOW *win; /* the window used in the hook */
+ int line; /* lines to take, < 0 => from bottom*/
+ int (*hook)(WINDOW *, int); /* callback for user */
+} ripoff_t;
+
+#if USE_GPM_SUPPORT
+#undef buttons /* term.h defines this, and gpm uses it! */
+#include <gpm.h>
+#if USE_WEAK_SYMBOLS
+weak_symbol(Gpm_Wgetch);
+#endif
+
+#ifdef HAVE_LIBDL
+/* link dynamically to GPM */
+typedef int *TYPE_gpm_fd;
+typedef int (*TYPE_Gpm_Open) (Gpm_Connect *, int);
+typedef int (*TYPE_Gpm_Close) (void);
+typedef int (*TYPE_Gpm_GetEvent) (Gpm_Event *);
+
+#define my_gpm_fd SP_PARM->_mouse_gpm_fd
+#define my_Gpm_Open SP_PARM->_mouse_Gpm_Open
+#define my_Gpm_Close SP_PARM->_mouse_Gpm_Close
+#define my_Gpm_GetEvent SP_PARM->_mouse_Gpm_GetEvent
+#else
+/* link statically to GPM */
+#define my_gpm_fd &gpm_fd
+#define my_Gpm_Open Gpm_Open
+#define my_Gpm_Close Gpm_Close
+#define my_Gpm_GetEvent Gpm_GetEvent
+#endif /* HAVE_LIBDL */
+#endif /* USE_GPM_SUPPORT */
+
+typedef struct {
+ long sequence;
+ bool last_used;
+ char *fix_sgr0; /* this holds the filtered sgr0 string */
+ char *last_bufp; /* help with fix_sgr0 leak */
+ TERMINAL *last_term;
+} TGETENT_CACHE;
+
+#define TGETENT_MAX 4
+
+/*
+ * When converting from terminfo to termcap, check for cases where we can trim
+ * octal escapes down to 2-character form. It is useful for terminfo format
+ * also, but not as important.
+ */
+#define MAX_TC_FIXUPS 10
+#define MIN_TC_FIXUPS 4
+
+#define isoctal(c) ((c) >= '0' && (c) <= '7')
+
+/*
+ * State of tparm().
+ */
+#define STACKSIZE 20
+
+typedef struct {
+ union {
+ int num;
+ char *str;
+ } data;
+ bool num_type;
+} STACK_FRAME;
+
+#define NUM_VARS 26
+
+typedef struct {
+ const char *tparam_base;
+
+ STACK_FRAME stack[STACKSIZE];
+ int stack_ptr;
+
+ char *out_buff;
+ size_t out_size;
+ size_t out_used;
+
+ char *fmt_buff;
+ size_t fmt_size;
+
+ int dynamic_var[NUM_VARS];
+ int static_vars[NUM_VARS];
+#ifdef TRACE
+ const char *tname;
+#endif
+} TPARM_STATE;
+
+typedef struct {
+ char *text;
+ size_t size;
+} TRACEBUF;
+
+/*
+ * The filesystem database normally uses a single-letter for the lower level
+ * of directories. Use a hexadecimal code for filesystems which do not
+ * preserve mixed-case names.
+ */
+#if MIXEDCASE_FILENAMES
+#define LEAF_FMT "%c"
+#define LEAF_LEN 1
+#else
+#define LEAF_FMT "%02x"
+#define LEAF_LEN 2
+#endif
+
+/*
+ * TRACEMSE_FMT is no longer than 80 columns, there are 5 numbers that
+ * could at most have 10 digits, and the mask contains no more than 32 bits
+ * with each bit representing less than 15 characters. Usually the whole
+ * string is less than 80 columns, but this buffer size is an absolute
+ * limit.
+ */
+#define TRACEMSE_MAX (80 + (5 * 10) + (32 * 15))
+#define TRACEMSE_FMT "id %2d at (%2d, %2d, %2d) state %4lx = {" /* } */
+
+#ifdef USE_TERM_DRIVER
+struct DriverTCB; /* Terminal Control Block forward declaration */
+#define INIT_TERM_DRIVER() _nc_globals.term_driver = _nc_get_driver
+#else
+#define INIT_TERM_DRIVER() /* nothing */
+#endif
+
+typedef struct {
+ const char *name;
+ char *value;
+} ITERATOR_VARS;
+
+/*
+ * Global data which is not specific to a screen.
+ */
+typedef struct {
+ SIG_ATOMIC_T have_sigtstp;
+ SIG_ATOMIC_T have_sigwinch;
+ SIG_ATOMIC_T cleanup_nested;
+
+ bool init_signals;
+ bool init_screen;
+
+ char *comp_sourcename;
+ char *comp_termtype;
+
+ bool have_tic_directory;
+ bool keep_tic_directory;
+ const char *tic_directory;
+
+ char *dbi_list;
+ int dbi_size;
+
+ char *first_name;
+ char **keyname_table;
+ int init_keyname;
+
+ int slk_format;
+
+ char *safeprint_buf;
+ size_t safeprint_used;
+
+ TGETENT_CACHE tgetent_cache[TGETENT_MAX];
+ int tgetent_index;
+ long tgetent_sequence;
+
+ char *dbd_blob; /* string-heap for dbd_list[] */
+ char **dbd_list; /* distinct places to look for data */
+ int dbd_size; /* length of dbd_list[] */
+ time_t dbd_time; /* cache last updated */
+ ITERATOR_VARS dbd_vars[dbdLAST];
+
+#ifdef USE_TERM_DRIVER
+ int (*term_driver)(struct DriverTCB*, const char*, int*);
+#endif
+
+#ifndef USE_SP_WINDOWLIST
+ WINDOWLIST *_nc_windowlist;
+#define WindowList(sp) _nc_globals._nc_windowlist
+#endif
+
+#if USE_HOME_TERMINFO
+ char *home_terminfo;
+#endif
+
+#if !USE_SAFE_SPRINTF
+ int safeprint_cols;
+ int safeprint_rows;
+#endif
+
+#ifdef USE_PTHREADS
+ pthread_mutex_t mutex_curses;
+ pthread_mutex_t mutex_prescreen;
+ pthread_mutex_t mutex_screen;
+ pthread_mutex_t mutex_update;
+ pthread_mutex_t mutex_tst_tracef;
+ pthread_mutex_t mutex_tracef;
+ int nested_tracef;
+ int use_pthreads;
+#define _nc_use_pthreads _nc_globals.use_pthreads
+#if USE_PTHREADS_EINTR
+ pthread_t read_thread; /* The reading thread */
+#endif
+#endif
+#if USE_WIDEC_SUPPORT
+ char key_name[MB_LEN_MAX + 1];
+#endif
+
+#ifdef TRACE
+ bool trace_opened;
+ char trace_fname[PATH_MAX];
+ int trace_level;
+ FILE *trace_fp;
+ int trace_fd;
+
+ char *tracearg_buf;
+ size_t tracearg_used;
+
+ TRACEBUF *tracebuf_ptr;
+ size_t tracebuf_used;
+
+ char tracechr_buf[40];
+
+ char *tracedmp_buf;
+ size_t tracedmp_used;
+
+ unsigned char *tracetry_buf;
+ size_t tracetry_used;
+
+ char traceatr_color_buf[2][80];
+ int traceatr_color_sel;
+ int traceatr_color_last;
+#if !defined(USE_PTHREADS) && USE_REENTRANT
+ int nested_tracef;
+#endif
+#endif /* TRACE */
+
+#if NO_LEAKS
+ bool leak_checking;
+#endif
+} NCURSES_GLOBALS;
+
+extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals;
+
+#define N_RIPS 5
+
+#ifdef USE_PTHREADS
+typedef struct _prescreen_list {
+ struct _prescreen_list *next;
+ pthread_t id;
+ struct screen *sp;
+} PRESCREEN_LIST;
+#endif
+
+/*
+ * Global data which can be swept up into a SCREEN when one is created.
+ * It may be modified before the next SCREEN is created.
+ */
+typedef struct {
+#ifdef USE_PTHREADS
+ PRESCREEN_LIST *allocated;
+#else
+ struct screen * allocated;
+#endif
+ bool use_env;
+ bool filter_mode;
+ attr_t previous_attr;
+ TPARM_STATE tparm_state;
+ TTY *saved_tty; /* savetty/resetty information */
+ bool use_tioctl;
+ NCURSES_SP_OUTC _outch; /* output handler if not putc */
+#ifndef USE_SP_RIPOFF
+ ripoff_t rippedoff[N_RIPS];
+ ripoff_t *rsp;
+#endif
+#if NCURSES_NO_PADDING
+ bool _no_padding; /* flag to set if padding disabled */
+#endif
+#if BROKEN_LINKER || USE_REENTRANT
+ chtype *real_acs_map;
+ int _LINES;
+ int _COLS;
+ int _TABSIZE;
+ int _ESCDELAY;
+ TERMINAL *_cur_term;
+#endif
+#ifdef TRACE
+#if BROKEN_LINKER || USE_REENTRANT
+ long _outchars;
+ const char *_tputs_trace;
+#endif
+#endif
+} NCURSES_PRESCREEN;
+
+/*
+ * Use screen-specific ripoff data (for softkeys) rather than global.
+ */
+#ifdef USE_SP_RIPOFF
+#define safe_ripoff_sp (sp)->rsp
+#define safe_ripoff_stack (sp)->rippedoff
+#else
+#define safe_ripoff_sp _nc_prescreen.rsp
+#define safe_ripoff_stack _nc_prescreen.rippedoff
+#endif
+
+extern NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen;
+
+typedef enum {
+ ewInitial = 0,
+ ewRunning,
+ ewSuspend
+} ENDWIN;
+
+/*
+ * The SCREEN structure.
+ */
+
+struct screen {
+ int _ifd; /* input file descriptor for screen */
+ int _ofd; /* output file descriptor for screen */
+ FILE *_ofp; /* output file ptr for screen */
+ char *out_buffer; /* output buffer */
+ size_t out_limit; /* output buffer size */
+ size_t out_inuse; /* output buffer current use */
+ bool _filtered; /* filter() was called */
+ bool _prescreen; /* is in prescreen phase */
+ bool _use_env; /* LINES & COLS from environment? */
+ int _checkfd; /* filedesc for typeahead check */
+ TERMINAL *_term; /* terminal type information */
+ TTY _saved_tty; /* savetty/resetty information */
+ NCURSES_SIZE_T _lines; /* screen lines */
+ NCURSES_SIZE_T _columns; /* screen columns */
+
+ NCURSES_SIZE_T _lines_avail; /* lines available for stdscr */
+ NCURSES_SIZE_T _topstolen; /* lines stolen from top */
+
+ WINDOW *_curscr; /* current screen */
+ WINDOW *_newscr; /* virtual screen to be updated to */
+ WINDOW *_stdscr; /* screen's full-window context */
+
+#define CurScreen(sp) (sp)->_curscr
+#define NewScreen(sp) (sp)->_newscr
+#define StdScreen(sp) (sp)->_stdscr
+
+ TRIES *_keytry; /* "Try" for use with keypad mode */
+ TRIES *_key_ok; /* Disabled keys via keyok(,FALSE) */
+ bool _tried; /* keypad mode was initialized */
+ bool _keypad_on; /* keypad mode is currently on */
+
+ bool _called_wgetch; /* check for recursion in wgetch() */
+ int _fifo[FIFO_SIZE]; /* input push-back buffer */
+ short _fifohead, /* head of fifo queue */
+ _fifotail, /* tail of fifo queue */
+ _fifopeek, /* where to peek for next char */
+ _fifohold; /* set if breakout marked */
+
+ int _endwin; /* are we out of window mode? */
+ NCURSES_CH_T *_current_attr; /* holds current attributes set */
+ int _coloron; /* is color enabled? */
+ int _color_defs; /* are colors modified */
+ int _cursor; /* visibility of the cursor */
+ int _cursrow; /* physical cursor row */
+ int _curscol; /* physical cursor column */
+ bool _notty; /* true if we cannot switch non-tty */
+ int _nl; /* True if NL -> CR/NL is on */
+ int _raw; /* True if in raw mode */
+ int _cbreak; /* 1 if in cbreak mode */
+ /* > 1 if in halfdelay mode */
+ int _echo; /* True if echo on */
+ int _use_meta; /* use the meta key? */
+ struct _SLK *_slk; /* ptr to soft key struct / NULL */
+ int slk_format; /* selected format for this screen */
+ /* cursor movement costs; units are 10ths of milliseconds */
+ int _char_padding; /* cost of character put */
+ int _cr_cost; /* cost of (carriage_return) */
+ int _cup_cost; /* cost of (cursor_address) */
+ int _home_cost; /* cost of (cursor_home) */
+ int _ll_cost; /* cost of (cursor_to_ll) */
+ int _cub1_cost; /* cost of (cursor_left) */
+ int _cuf1_cost; /* cost of (cursor_right) */
+ int _cud1_cost; /* cost of (cursor_down) */
+ int _cuu1_cost; /* cost of (cursor_up) */
+ int _cub_cost; /* cost of (parm_cursor_left) */
+ int _cuf_cost; /* cost of (parm_cursor_right) */
+ int _cud_cost; /* cost of (parm_cursor_down) */
+ int _cuu_cost; /* cost of (parm_cursor_up) */
+ int _hpa_cost; /* cost of (column_address) */
+ int _vpa_cost; /* cost of (row_address) */
+ /* used in tty_update.c, must be chars */
+ int _ed_cost; /* cost of (clr_eos) */
+ int _el_cost; /* cost of (clr_eol) */
+ int _el1_cost; /* cost of (clr_bol) */
+ int _dch1_cost; /* cost of (delete_character) */
+ int _ich1_cost; /* cost of (insert_character) */
+ int _dch_cost; /* cost of (parm_dch) */
+ int _ich_cost; /* cost of (parm_ich) */
+ int _ech_cost; /* cost of (erase_chars) */
+ int _rep_cost; /* cost of (repeat_char) */
+ int _hpa_ch_cost; /* cost of (column_address) */
+ int _cup_ch_cost; /* cost of (cursor_address) */
+ int _cuf_ch_cost; /* cost of (parm_cursor_right) */
+ int _inline_cost; /* cost of inline-move */
+ int _smir_cost; /* cost of (enter_insert_mode) */
+ int _rmir_cost; /* cost of (exit_insert_mode) */
+ int _ip_cost; /* cost of (insert_padding) */
+ /* used in lib_mvcur.c */
+ char * _address_cursor;
+ /* used in tty_update.c */
+ int _scrolling; /* 1 if terminal's smart enough to */
+
+ /* used in lib_color.c */
+ rgb_bits_t _direct_color; /* RGB overrides color-table */
+ color_t *_color_table; /* screen's color palette */
+ int _color_count; /* count of colors in palette */
+ colorpair_t *_color_pairs; /* screen's color pair list */
+ int _pair_count; /* same as COLOR_PAIRS */
+ int _pair_limit; /* actual limit of color-pairs */
+ int _pair_alloc; /* current table-size of color-pairs */
+ chtype _ok_attributes; /* valid attributes for terminal */
+ chtype _xmc_suppress; /* attributes to suppress if xmc */
+ chtype _xmc_triggers; /* attributes to process if xmc */
+ chtype * _acs_map; /* the real alternate-charset map */
+ bool * _screen_acs_map;
+
+
+ /* used in lib_vidattr.c */
+ bool _use_rmso; /* true if we may use 'rmso' */
+ bool _use_rmul; /* true if we may use 'rmul' */
+
+ /*
+ * These data correspond to the state of the idcok() and idlok()
+ * functions. A caveat is in order here: the XSI and SVr4
+ * documentation specify that these functions apply to the window which
+ * is given as an argument. However, ncurses implements this logic
+ * only for the newscr/curscr update process, _not_ per-window.
+ */
+ bool _nc_sp_idlok;
+ bool _nc_sp_idcok;
+
+ /*
+ * These are the data that support the mouse interface.
+ */
+ bool _mouse_initialized;
+ MouseType _mouse_type;
+ int _maxclick;
+ bool (*_mouse_event) (SCREEN *);
+ bool (*_mouse_inline)(SCREEN *);
+ bool (*_mouse_parse) (SCREEN *, int);
+ void (*_mouse_resume)(SCREEN *);
+ void (*_mouse_wrap) (SCREEN *);
+ int _mouse_fd; /* file-descriptor, if any */
+ bool _mouse_active; /* true if initialized */
+ mmask_t _mouse_mask; /* set via mousemask() */
+ mmask_t _mouse_mask2; /* OR's in press/release bits */
+ mmask_t _mouse_bstate;
+ MouseFormat _mouse_format; /* type of xterm mouse protocol */
+ NCURSES_CONST char *_mouse_xtermcap; /* string to enable/disable mouse */
+ MEVENT _mouse_events[EV_MAX]; /* hold the last mouse event seen */
+ MEVENT *_mouse_eventp; /* next free slot in event queue */
+
+ /*
+ * These are data that support the proper handling of the panel stack on an
+ * per screen basis.
+ */
+ struct panelhook _panelHook;
+
+ bool _sig_winch;
+ SCREEN *_next_screen;
+
+ /* hashes for old and new lines */
+ unsigned long *oldhash, *newhash;
+ HASHMAP *hashtab;
+ int hashtab_len;
+ int *_oldnum_list;
+ int _oldnum_size;
+
+ NCURSES_SP_OUTC _outch; /* output handler if not putc */
+ NCURSES_OUTC jump;
+
+ ripoff_t rippedoff[N_RIPS];
+ ripoff_t *rsp;
+
+ int _legacy_coding; /* see use_legacy_coding() */
+
+#if NCURSES_NO_PADDING
+ bool _no_padding; /* flag to set if padding disabled */
+#endif
+
+#if USE_HARD_TABS
+ int _ht_cost; /* cost of (tab) */
+ int _cbt_cost; /* cost of (backtab) */
+#endif /* USE_HARD_TABS */
+
+ /* used in lib_vidattr.c */
+#if USE_ITALIC
+ bool _use_ritm; /* true if we may use 'ritm' */
+#endif
+
+ /* used in getch/twait */
+#if USE_KLIBC_KBD
+ bool _extended_key; /* true if an extended key */
+#endif
+
+ /* used in lib_color.c */
+#if NCURSES_EXT_FUNCS
+ bool _assumed_color; /* use assumed colors */
+ bool _default_color; /* use default colors */
+ bool _has_sgr_39_49; /* has ECMA default color support */
+ int _default_fg; /* assumed default foreground */
+ int _default_bg; /* assumed default background */
+ int _default_pairs; /* count pairs using default color */
+#endif
+
+ /* system-dependent mouse data */
+#if USE_GPM_SUPPORT
+ bool _mouse_gpm_loaded;
+ bool _mouse_gpm_found;
+#ifdef HAVE_LIBDL
+ void *_dlopen_gpm;
+ TYPE_gpm_fd _mouse_gpm_fd;
+ TYPE_Gpm_Open _mouse_Gpm_Open;
+ TYPE_Gpm_Close _mouse_Gpm_Close;
+ TYPE_Gpm_GetEvent _mouse_Gpm_GetEvent;
+#endif
+ Gpm_Connect _mouse_gpm_connect;
+#endif /* USE_GPM_SUPPORT */
+
+#if USE_EMX_MOUSE
+ int _emxmouse_wfd;
+ int _emxmouse_thread;
+ int _emxmouse_activated;
+ char _emxmouse_buttons[4];
+#endif
+
+#if USE_SYSMOUSE
+ MEVENT _sysmouse_fifo[FIFO_SIZE];
+ int _sysmouse_head;
+ int _sysmouse_tail;
+ int _sysmouse_char_width; /* character width */
+ int _sysmouse_char_height; /* character height */
+ int _sysmouse_old_buttons;
+ int _sysmouse_new_buttons;
+#endif
+
+#ifdef USE_TERM_DRIVER
+ MEVENT _drv_mouse_fifo[FIFO_SIZE];
+ int _drv_mouse_head;
+ int _drv_mouse_tail;
+ int _drv_mouse_old_buttons;
+ int _drv_mouse_new_buttons;
+#endif
+ /*
+ * This supports automatic resizing
+ */
+#if USE_SIZECHANGE
+ int (*_resize)(NCURSES_SP_DCLx int y, int x);
+ int (*_ungetch)(SCREEN *, int);
+#endif
+
+#ifdef USE_SP_WINDOWLIST
+ WINDOWLIST* _windowlist;
+#define WindowList(sp) (sp)->_windowlist
+#endif
+
+#if USE_REENTRANT
+ char _ttytype[NAMESIZE];
+ int _ESCDELAY;
+ int _TABSIZE;
+ int _LINES;
+ int _COLS;
+#endif
+
+#if NCURSES_SP_FUNCS
+ bool use_tioctl;
+#endif
+
+ /*
+ * ncurses/ncursesw are the same up to this point.
+ */
+#if USE_WIDEC_SUPPORT
+ /* recent versions of 'screen' have partially-working support for
+ * UTF-8, but do not permit ACS at the same time (see tty_update.c).
+ */
+ bool _screen_acs_fix;
+ bool _screen_unicode;
+#endif
+
+#if NCURSES_EXT_FUNCS && NCURSES_EXT_COLORS
+ void *_ordered_pairs; /* index used by alloc_pair() */
+ int _pairs_used; /* actual number of color-pairs used */
+ int _recent_pair; /* number for most recent free-pair */
+#endif
+
+#ifdef TRACE
+ char tracechr_buf[40];
+ char tracemse_buf[TRACEMSE_MAX];
+#if USE_REENTRANT
+ long _outchars;
+ const char *_tputs_trace;
+#endif
+#endif
+};
+
+extern NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain;
+extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
+
+ WINDOWLIST {
+ WINDOWLIST *next;
+ SCREEN *screen; /* screen containing the window */
+ WINDOW win; /* WINDOW_EXT() needs to account for offset */
+#if NCURSES_WIDECHAR
+ char addch_work[(MB_LEN_MAX * 9) + 1];
+ unsigned addch_used; /* number of bytes in addch_work[] */
+ int addch_x; /* x-position for addch_work[] */
+ int addch_y; /* y-position for addch_work[] */
+#endif
+};
+
+#define WINDOW_EXT(w,m) (((WINDOWLIST *)((void *)((char *)(w) - offsetof(WINDOWLIST, win))))->m)
+
+#ifdef USE_SP_WINDOWLIST
+#define SP_INIT_WINDOWLIST(sp) WindowList(sp) = 0
+#else
+#define SP_INIT_WINDOWLIST(sp) /* nothing */
+#endif
+
+#define SP_PRE_INIT(sp) \
+ sp->_cursrow = -1; \
+ sp->_curscol = -1; \
+ sp->_nl = TRUE; \
+ sp->_raw = FALSE; \
+ sp->_cbreak = 0; \
+ sp->_echo = TRUE; \
+ sp->_fifohead = -1; \
+ sp->_endwin = ewSuspend; \
+ sp->_cursor = -1; \
+ SP_INIT_WINDOWLIST(sp); \
+ sp->_outch = NCURSES_OUTC_FUNC; \
+ sp->jump = 0 \
+
+/* usually in <limits.h> */
+#ifndef UCHAR_MAX
+#define UCHAR_MAX 255
+#endif
+
+/* The terminfo source is assumed to be 7-bit ASCII */
+#define is7bits(c) ((unsigned)(c) < 128)
+
+/* Checks for isprint() should be done on 8-bit characters (non-wide) */
+#define is8bits(c) ((unsigned)(c) <= UCHAR_MAX)
+
+#ifndef min
+#define min(a,b) ((a) > (b) ? (b) : (a))
+#endif
+
+#ifndef max
+#define max(a,b) ((a) < (b) ? (b) : (a))
+#endif
+
+/* usually in <unistd.h> */
+#ifndef STDIN_FILENO
+#define STDIN_FILENO 0
+#endif
+
+#ifndef STDOUT_FILENO
+#define STDOUT_FILENO 1
+#endif
+
+#ifndef STDERR_FILENO
+#define STDERR_FILENO 2
+#endif
+
+#ifndef EXIT_SUCCESS
+#define EXIT_SUCCESS 0
+#endif
+
+#ifndef EXIT_FAILURE
+#define EXIT_FAILURE 1
+#endif
+
+#ifndef R_OK
+#define R_OK 4 /* Test for read permission. */
+#endif
+#ifndef W_OK
+#define W_OK 2 /* Test for write permission. */
+#endif
+#ifndef X_OK
+#define X_OK 1 /* Test for execute permission. */
+#endif
+#ifndef F_OK
+#define F_OK 0 /* Test for existence. */
+#endif
+
+#if HAVE_FCNTL_H
+#include <fcntl.h> /* may define O_BINARY */
+#endif
+
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+#ifdef TRACE
+#if USE_REENTRANT
+#define COUNT_OUTCHARS(n) _nc_count_outchars(n);
+#else
+#define COUNT_OUTCHARS(n) _nc_outchars += (n);
+#endif
+#else
+#define COUNT_OUTCHARS(n) /* nothing */
+#endif
+
+#define RESET_OUTCHARS() COUNT_OUTCHARS(-_nc_outchars)
+
+#define UChar(c) ((unsigned char)(c))
+#define UShort(c) ((unsigned short)(c))
+#define ChCharOf(c) ((chtype)(c) & (chtype)A_CHARTEXT)
+#define ChAttrOf(c) ((chtype)(c) & (chtype)A_ATTRIBUTES)
+
+#define TR_PUTC(c) TR(TRACE_CHARPUT, ("PUTC %#x", UChar(c)))
+
+#ifndef MB_LEN_MAX
+#define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */
+#endif
+
+#if USE_WIDEC_SUPPORT /* { */
+#define isEILSEQ(status) (((size_t)status == (size_t)-1) && (errno == EILSEQ))
+
+#define init_mb(state) memset(&state, 0, sizeof(state))
+
+#if NCURSES_EXT_COLORS
+#define NulColor , 0
+#else
+#define NulColor /* nothing */
+#endif
+
+#define NulChar 0,0,0,0 /* FIXME: see CCHARW_MAX */
+#define CharOf(c) ((c).chars[0])
+#define AttrOf(c) ((c).attr)
+
+#define AddAttr(c,a) AttrOf(c) |= ((a) & A_ATTRIBUTES)
+#define RemAttr(c,a) AttrOf(c) &= ~((a) & A_ATTRIBUTES)
+#define SetAttr(c,a) AttrOf(c) = ((a) & A_ATTRIBUTES) | WidecExt(c)
+
+#define NewChar2(c,a) { a, { c, NulChar } NulColor }
+#define NewChar(ch) NewChar2(ChCharOf(ch), ChAttrOf(ch))
+
+#if CCHARW_MAX == 5
+#define CharEq(a,b) (((a).attr == (b).attr) \
+ && (a).chars[0] == (b).chars[0] \
+ && (a).chars[1] == (b).chars[1] \
+ && (a).chars[2] == (b).chars[2] \
+ && (a).chars[3] == (b).chars[3] \
+ && (a).chars[4] == (b).chars[4] \
+ if_EXT_COLORS(&& (a).ext_color == (b).ext_color))
+#elif CCHARW_MAX > 0
+#error Inconsistent values for CCHARW_MAX
+#else
+#define CharEq(a,b) (!memcmp(&(a), &(b), sizeof(a)))
+#endif
+
+#define SetChar(ch,c,a) do { \
+ NCURSES_CH_T *_cp = &ch; \
+ memset(_cp, 0, sizeof(ch)); \
+ _cp->chars[0] = (wchar_t) (c); \
+ _cp->attr = (a); \
+ if_EXT_COLORS(SetPair(ch, PairNumber(a))); \
+ } while (0)
+#define CHREF(wch) (&wch)
+#define CHDEREF(wch) (*wch)
+#define ARG_CH_T NCURSES_CH_T *
+#define CARG_CH_T const NCURSES_CH_T *
+#define PUTC_DATA char PUTC_buf[MB_LEN_MAX]; int PUTC_i, PUTC_n; \
+ mbstate_t PUT_st; wchar_t PUTC_ch
+#define PUTC_INIT init_mb (PUT_st)
+#define PUTC(ch) do { if(!isWidecExt(ch)) { \
+ if (Charable(ch)) { \
+ TR_PUTC(CharOf(ch)); \
+ NCURSES_OUTC_FUNC (NCURSES_SP_ARGx CharOf(ch)); \
+ COUNT_OUTCHARS(1); \
+ } else { \
+ for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { \
+ PUTC_ch = (ch).chars[PUTC_i]; \
+ if (PUTC_ch == L'\0') \
+ break; \
+ PUTC_INIT; \
+ PUTC_n = (int) wcrtomb(PUTC_buf, \
+ (ch).chars[PUTC_i], &PUT_st); \
+ if (PUTC_n <= 0) { \
+ if (PUTC_ch && is8bits(PUTC_ch) && PUTC_i == 0) \
+ TR_PUTC(CharOf(ch)); \
+ NCURSES_OUTC_FUNC (NCURSES_SP_ARGx CharOf(ch)); \
+ break; \
+ } else { \
+ int PUTC_j; \
+ for (PUTC_j = 0; PUTC_j < PUTC_n; ++PUTC_j) { \
+ TR_PUTC(PUTC_buf[PUTC_j]); \
+ NCURSES_OUTC_FUNC (NCURSES_SP_ARGx PUTC_buf[PUTC_j]); \
+ } \
+ } \
+ } \
+ COUNT_OUTCHARS(PUTC_i); \
+ } } } while (0)
+
+#define BLANK NewChar2(' ', WA_NORMAL)
+#define ZEROS NewChar2('\0', WA_NORMAL)
+#define ISBLANK(ch) ((ch).chars[0] == L' ' && (ch).chars[1] == L'\0')
+
+ /*
+ * Wide characters cannot be represented in the A_CHARTEXT mask of
+ * attr_t's but an application might have set a narrow character there.
+ * But even in that case, it would only be a printable character, or
+ * zero. Otherwise we can use those bits to tell if a cell is the
+ * first or extension part of a wide character.
+ */
+#define WidecExt(ch) (int) (AttrOf(ch) & A_CHARTEXT)
+#define isWidecBase(ch) (WidecExt(ch) == 1)
+#define isWidecExt(ch) (WidecExt(ch) > 1 && WidecExt(ch) < 32)
+#define SetWidecExt(dst, ext) AttrOf(dst) &= ~A_CHARTEXT, \
+ AttrOf(dst) |= (attr_t) (ext + 1)
+
+#define if_WIDEC(code) code
+#define Charable(ch) (((SP_PARM->_legacy_coding) \
+ || (AttrOf(ch) & A_ALTCHARSET) \
+ || (!isWidecExt(ch))) && \
+ (ch).chars[1] == L'\0' && \
+ _nc_is_charable(CharOf(ch)))
+
+#define L(ch) L ## ch
+#else /* }{ */
+#define CharOf(c) ChCharOf(c)
+#define AttrOf(c) ChAttrOf(c)
+#define AddAttr(c,a) c |= (a)
+#define RemAttr(c,a) c &= ~((a) & A_ATTRIBUTES)
+#define SetAttr(c,a) c = ((c) & ~A_ATTRIBUTES) | (a)
+#define NewChar(ch) (ch)
+#define NewChar2(c,a) ((c) | (a))
+#define CharEq(a,b) ((a) == (b))
+#define SetChar(ch,c,a) ch = (c) | (a)
+#define CHREF(wch) wch
+#define CHDEREF(wch) wch
+#define ARG_CH_T NCURSES_CH_T
+#define CARG_CH_T NCURSES_CH_T
+#define PUTC_DATA /* nothing */
+#define PUTC(ch) { \
+ TR_PUTC(ch); \
+ NCURSES_OUTC_FUNC (NCURSES_SP_ARGx (int) ch); \
+ }
+
+#define BLANK (' '|A_NORMAL)
+#define ZEROS ('\0'|A_NORMAL)
+#define ISBLANK(ch) (CharOf(ch) == ' ')
+
+#define isWidecExt(ch) (0)
+#define if_WIDEC(code) /* nothing */
+
+#define L(ch) ch
+#endif /* } */
+
+#define AttrOfD(ch) AttrOf(CHDEREF(ch))
+#define CharOfD(ch) CharOf(CHDEREF(ch))
+#define SetChar2(wch,ch) SetChar(wch,ChCharOf(ch),ChAttrOf(ch))
+
+#define BLANK_ATTR A_NORMAL
+#define BLANK_TEXT L(' ')
+
+#define CHANGED -1
+
+#define LEGALYX(w, y, x) \
+ ((w) != 0 && \
+ ((x) >= 0 && (x) <= (w)->_maxx && \
+ (y) >= 0 && (y) <= (w)->_maxy))
+
+#define CHANGED_CELL(line,col) \
+ if (line->firstchar == _NOCHANGE) \
+ line->firstchar = line->lastchar = (NCURSES_SIZE_T) (col); \
+ else if ((col) < line->firstchar) \
+ line->firstchar = (NCURSES_SIZE_T) (col); \
+ else if ((col) > line->lastchar) \
+ line->lastchar = (NCURSES_SIZE_T) (col)
+
+#define CHANGED_RANGE(line,start,end) \
+ if (line->firstchar == _NOCHANGE \
+ || line->firstchar > (start)) \
+ line->firstchar = (NCURSES_SIZE_T) (start); \
+ if (line->lastchar == _NOCHANGE \
+ || line->lastchar < (end)) \
+ line->lastchar = (NCURSES_SIZE_T) (end)
+
+#define CHANGED_TO_EOL(line,start,end) \
+ if (line->firstchar == _NOCHANGE \
+ || line->firstchar > (start)) \
+ line->firstchar = (NCURSES_SIZE_T) (start); \
+ line->lastchar = (NCURSES_SIZE_T) (end)
+
+#define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
+
+#define FreeIfNeeded(p) if ((p) != 0) free(p)
+
+/* FreeAndNull() is not a comma-separated expression because some compilers
+ * do not accept a mixture of void with values.
+ */
+#define FreeAndNull(p) do { free(p); p = 0; } while (0)
+
+#include <nc_alloc.h>
+
+/*
+ * Use these for tic/infocmp malloc failures. Generally the ncurses library
+ * tries to limp along after a failure.
+ */
+#define TYPE_MALLOC(type, size, name) \
+ do { \
+ name = typeMalloc(type, size); \
+ if (name == 0) \
+ _nc_err_abort(MSG_NO_MEMORY); \
+ } while (0)
+
+#define TYPE_REALLOC(type, size, name) \
+ do { \
+ name = typeRealloc(type, size, name); \
+ if (name == 0) \
+ _nc_err_abort(MSG_NO_MEMORY); \
+ } while (0)
+
+/*
+ * TTY bit definition for converting tabs to spaces.
+ */
+#ifdef TAB3
+# define OFLAGS_TABS TAB3 /* POSIX specifies TAB3 */
+#else
+# ifdef XTABS
+# define OFLAGS_TABS XTABS /* XTABS is usually the "same" */
+# else
+# ifdef OXTABS
+# define OFLAGS_TABS OXTABS /* the traditional BSD equivalent */
+# else
+# define OFLAGS_TABS 0
+# endif
+# endif
+#endif
+
+/*
+ * Standardize/simplify common loops
+ */
+#define each_screen(p) p = _nc_screen_chain; p != 0; p = (p)->_next_screen
+#define each_window(sp,p) p = WindowList(sp); p != 0; p = (p)->next
+#define each_ripoff(p) p = safe_ripoff_stack; (p - safe_ripoff_stack) < N_RIPS; ++p
+
+/*
+ * Prefixes for call/return points of library function traces. We use these to
+ * instrument the public functions so that the traces can be easily transformed
+ * into regression scripts.
+ */
+#define T_CALLED(fmt) "called {" fmt
+#define T_CREATE(fmt) "create :" fmt
+#define T_RETURN(fmt) "return }" fmt
+
+#ifdef TRACE
+
+#if USE_REENTRANT
+#define TPUTS_TRACE(s) _nc_set_tputs_trace(s);
+#else
+#define TPUTS_TRACE(s) _nc_tputs_trace = s;
+#endif
+
+#define START_TRACE() \
+ if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
+ int t = _nc_getenv_num("NCURSES_TRACE"); \
+ if (t >= 0) \
+ trace((unsigned) t); \
+ }
+
+/*
+ * Many of the _tracef() calls use static buffers; lock the trace state before
+ * trying to fill them.
+ */
+#if USE_REENTRANT
+#define USE_TRACEF(mask) _nc_use_tracef(mask)
+extern NCURSES_EXPORT(int) _nc_use_tracef (unsigned);
+extern NCURSES_EXPORT(void) _nc_locked_tracef (const char *, ...) GCC_PRINTFLIKE(1,2);
+#else
+#define USE_TRACEF(mask) (_nc_tracing & (mask))
+#define _nc_locked_tracef _tracef
+#endif
+
+#define TR(n, a) if (USE_TRACEF(n)) _nc_locked_tracef a
+#define T(a) TR(TRACE_CALLS, a)
+#define TRACE_RETURN(value,type) return _nc_retrace_##type((type)(value))
+#define TRACE_RETURN1(value,dst) return _nc_retrace_##dst(value)
+#define TRACE_RETURN2(value,dst,src) return _nc_retrace_##dst##_##src(value)
+#define TRACE_RETURN_SP(value,type) return _nc_retrace_##type(SP_PARM, value)
+
+typedef void VoidFunc(void);
+
+#define TR_FUNC(value) ((const char*) (value))
+#define NonNull(s) ((s) != 0 ? s : "<null>")
+
+#define returnAttr(code) TRACE_RETURN(code,attr_t)
+#define returnBits(code) TRACE_RETURN(code,unsigned)
+#define returnBool(code) TRACE_RETURN(code,bool)
+#define returnCPtr(code) TRACE_RETURN1(code,cptr)
+#define returnCVoidPtr(code) TRACE_RETURN1(code,cvoid_ptr)
+#define returnChar(code) TRACE_RETURN(code,char)
+#define returnChtype(code) TRACE_RETURN(code,chtype)
+#define returnCode(code) TRACE_RETURN(code,int)
+#define returnIntAttr(code) TRACE_RETURN2(code,int,attr_t)
+#define returnMMask(code) TRACE_RETURN_SP(code,mmask_t)
+#define returnPtr(code) TRACE_RETURN1(code,ptr)
+#define returnSP(code) TRACE_RETURN1(code,sp)
+#define returnVoid T((T_RETURN(""))); return
+#define returnVoidPtr(code) TRACE_RETURN1(code,void_ptr)
+#define returnWin(code) TRACE_RETURN1(code,win)
+
+#define returnDB(rc) do { TR(TRACE_DATABASE,(T_RETURN("code %d"), (rc))); return (rc); } while (0)
+
+extern NCURSES_EXPORT(NCURSES_BOOL) _nc_retrace_bool (int);
+extern NCURSES_EXPORT(NCURSES_CONST void *) _nc_retrace_cvoid_ptr (NCURSES_CONST void *);
+extern NCURSES_EXPORT(SCREEN *) _nc_retrace_sp (SCREEN *);
+extern NCURSES_EXPORT(WINDOW *) _nc_retrace_win (WINDOW *);
+extern NCURSES_EXPORT(attr_t) _nc_retrace_attr_t (attr_t);
+extern NCURSES_EXPORT(char *) _nc_retrace_ptr (char *);
+extern NCURSES_EXPORT(char *) _nc_trace_ttymode(TTY *tty);
+extern NCURSES_EXPORT(char *) _nc_varargs (const char *, va_list);
+extern NCURSES_EXPORT(chtype) _nc_retrace_chtype (chtype);
+extern NCURSES_EXPORT(const char *) _nc_altcharset_name(attr_t, chtype);
+extern NCURSES_EXPORT(const char *) _nc_retrace_cptr (const char *);
+extern NCURSES_EXPORT(char) _nc_retrace_char (int);
+extern NCURSES_EXPORT(int) _nc_retrace_int (int);
+extern NCURSES_EXPORT(int) _nc_retrace_int_attr_t (attr_t);
+extern NCURSES_EXPORT(mmask_t) _nc_retrace_mmask_t (SCREEN *, mmask_t);
+extern NCURSES_EXPORT(unsigned) _nc_retrace_unsigned (unsigned);
+extern NCURSES_EXPORT(void *) _nc_retrace_void_ptr (void *);
+extern NCURSES_EXPORT(void) _nc_fifo_dump (SCREEN *);
+
+#if USE_REENTRANT
+NCURSES_WRAPPED_VAR(long, _nc_outchars);
+NCURSES_WRAPPED_VAR(const char *, _nc_tputs_trace);
+#define _nc_outchars NCURSES_PUBLIC_VAR(_nc_outchars())
+#define _nc_tputs_trace NCURSES_PUBLIC_VAR(_nc_tputs_trace())
+extern NCURSES_EXPORT(void) _nc_set_tputs_trace (const char *);
+extern NCURSES_EXPORT(void) _nc_count_outchars (long);
+#else
+extern NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace;
+extern NCURSES_EXPORT_VAR(long) _nc_outchars;
+#endif
+
+extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing;
+
+extern NCURSES_EXPORT(char *) _nc_tracebits (void);
+extern NCURSES_EXPORT(char *) _tracemouse (const MEVENT *);
+extern NCURSES_EXPORT(void) _tracedump (const char *, WINDOW *);
+
+#if USE_WIDEC_SUPPORT
+extern NCURSES_EXPORT(const char *) _nc_viswbuf2 (int, const wchar_t *);
+extern NCURSES_EXPORT(const char *) _nc_viswbufn (const wchar_t *, int);
+#endif
+
+extern NCURSES_EXPORT(const char *) _nc_viscbuf2 (int, const NCURSES_CH_T *, int);
+extern NCURSES_EXPORT(const char *) _nc_viscbuf (const NCURSES_CH_T *, int);
+
+#else /* !TRACE */
+
+#define START_TRACE() /* nothing */
+
+#define T(a)
+#define TR(n, a)
+#define TPUTS_TRACE(s)
+
+#define returnAttr(code) return code
+#define returnBits(code) return code
+#define returnBool(code) return code
+#define returnCPtr(code) return code
+#define returnCVoidPtr(code) return code
+#define returnChar(code) return ((char) code)
+#define returnChtype(code) return code
+#define returnCode(code) return code
+#define returnIntAttr(code) return code
+#define returnMMask(code) return code
+#define returnPtr(code) return code
+#define returnSP(code) return code
+#define returnVoid return
+#define returnVoidPtr(code) return code
+#define returnWin(code) return code
+
+#define returnDB(code) return code
+
+#endif /* TRACE/!TRACE */
+
+/*
+ * Workaround for defective implementation of gcc attribute warn_unused_result
+ */
+#if defined(__GNUC__) && defined(_FORTIFY_SOURCE)
+#define IGNORE_RC(func) errno = (int) func
+#else
+#define IGNORE_RC(func) (void) func
+#endif /* gcc workarounds */
+
+/*
+ * Return-codes for tgetent() and friends.
+ */
+#define TGETENT_YES 1 /* entry is found */
+#define TGETENT_NO 0 /* entry is not found */
+#define TGETENT_ERR -1 /* an error occurred */
+
+extern NCURSES_EXPORT(const char *) _nc_visbuf2 (int, const char *);
+extern NCURSES_EXPORT(const char *) _nc_visbufn (const char *, int);
+
+#define EMPTY_MODULE(name) \
+extern NCURSES_EXPORT(void) name (void); \
+ NCURSES_EXPORT(void) name (void) { }
+
+#define ALL_BUT_COLOR ((chtype)~(A_COLOR))
+#define NONBLANK_ATTR (A_BOLD | A_DIM | A_BLINK | A_ITALIC)
+#define TPARM_ATTR (A_STANDOUT | A_UNDERLINE | A_REVERSE | A_BLINK | A_DIM | A_BOLD | A_ALTCHARSET | A_INVIS | A_PROTECT)
+#define XMC_CONFLICT (A_STANDOUT | A_UNDERLINE | A_REVERSE | A_BLINK | A_DIM | A_BOLD | A_INVIS | A_PROTECT | A_ITALIC)
+#define XMC_CHANGES(c) ((c) & SP_PARM->_xmc_suppress)
+
+#define toggle_attr_on(S,at) {\
+ if (PairNumber(at) > 0) {\
+ (S) = ((S) & ALL_BUT_COLOR) | (attr_t) (at);\
+ } else {\
+ (S) |= (attr_t) (at);\
+ }\
+ TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
+
+
+#define toggle_attr_off(S,at) {\
+ if (PairNumber(at) > 0) {\
+ (S) &= ~(at|A_COLOR);\
+ } else {\
+ (S) &= ~(at);\
+ }\
+ TR(TRACE_ATTRS, ("new attribute is %s", _traceattr((S))));}
+
+#define DelCharCost(sp,count) \
+ ((parm_dch != 0) \
+ ? sp->_dch_cost \
+ : ((delete_character != 0) \
+ ? (sp->_dch1_cost * count) \
+ : INFINITY))
+
+#define InsCharCost(sp,count) \
+ ((parm_ich != 0) \
+ ? sp->_ich_cost \
+ : ((enter_insert_mode && exit_insert_mode) \
+ ? sp->_smir_cost + sp->_rmir_cost + (sp->_ip_cost * count) \
+ : ((insert_character != 0) \
+ ? ((sp->_ich1_cost + sp->_ip_cost) * count) \
+ : INFINITY)))
+
+#if USE_XMC_SUPPORT
+#define UpdateAttrs(sp,c) if (!SameAttrOf(SCREEN_ATTRS(sp), c)) { \
+ attr_t chg = AttrOf(SCREEN_ATTRS(sp)); \
+ VIDATTR(sp, AttrOf(c), GetPair(c)); \
+ if (magic_cookie_glitch > 0 \
+ && XMC_CHANGES((chg ^ AttrOf(SCREEN_ATTRS(sp))))) { \
+ T(("%s @%d before glitch %d,%d", \
+ __FILE__, __LINE__, \
+ sp->_cursrow, \
+ sp->_curscol)); \
+ NCURSES_SP_NAME(_nc_do_xmc_glitch)(NCURSES_SP_ARGx chg); \
+ } \
+ }
+#else
+#define UpdateAttrs(sp,c) if (!SameAttrOf(SCREEN_ATTRS(sp), c)) { \
+ VIDATTR(sp, AttrOf(c), GetPair(c)); \
+ }
+#endif
+
+/*
+ * Macros to make additional parameter to implement wgetch_events()
+ */
+#ifdef NCURSES_WGETCH_EVENTS
+#define EVENTLIST_0th(param) param
+#define EVENTLIST_1st(param) param
+#define EVENTLIST_2nd(param) , param
+#define TWAIT_MASK (TW_ANY | TW_EVENT)
+#else
+#define EVENTLIST_0th(param) void
+#define EVENTLIST_1st(param) /* nothing */
+#define EVENTLIST_2nd(param) /* nothing */
+#define TWAIT_MASK TW_ANY
+#endif
+
+#if NCURSES_EXPANDED && NCURSES_EXT_FUNCS
+
+#undef toggle_attr_on
+#define toggle_attr_on(S,at) _nc_toggle_attr_on(&(S), at)
+extern NCURSES_EXPORT(void) _nc_toggle_attr_on (attr_t *, attr_t);
+
+#undef toggle_attr_off
+#define toggle_attr_off(S,at) _nc_toggle_attr_off(&(S), at)
+extern NCURSES_EXPORT(void) _nc_toggle_attr_off (attr_t *, attr_t);
+
+#undef DelCharCost
+#define DelCharCost(sp, count) NCURSES_SP_NAME(_nc_DelCharCost)(NCURSES_SP_ARGx count)
+
+#undef InsCharCost
+#define InsCharCost(sp, count) NCURSES_SP_NAME(_nc_InsCharCost)(NCURSES_SP_ARGx count)
+
+extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_DelCharCost) (NCURSES_SP_DCLx int _c);
+extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_InsCharCost) (NCURSES_SP_DCLx int _c);
+
+#undef UpdateAttrs
+#define UpdateAttrs(sp,c) NCURSES_SP_NAME(_nc_UpdateAttrs)(NCURSES_SP_ARGx CHREF(c))
+
+#if USE_WIDEC_SUPPORT || defined(NEED_NCURSES_CH_T)
+extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_UpdateAttrs) (NCURSES_SP_DCLx CARG_CH_T _c);
+#else
+extern NCURSES_EXPORT(void) NCURSES_SP_NAME(_nc_UpdateAttrs) (NCURSES_SP_DCLx chtype c);
+#endif
+
+#if NCURSES_SP_FUNCS
+extern NCURSES_EXPORT(int) _nc_DelCharCost (int);
+extern NCURSES_EXPORT(int) _nc_InsCharCost (int);
+extern NCURSES_EXPORT(void) _nc_UpdateAttrs (CARG_CH_T);
+#endif /* NCURSES_SP_FUNCS */
+
+#else
+
+extern NCURSES_EXPORT(void) _nc_expanded (void);
+
+#endif
+
+#if !NCURSES_EXT_FUNCS
+#define set_escdelay(value) ESCDELAY = value
+#endif
+
+#if !HAVE_GETCWD
+#define getcwd(buf,len) getwd(buf)
+#endif
+
+#define save_ttytype(termp) \
+ if (TerminalType(termp).term_names != 0) { \
+ _nc_STRNCPY(ttytype, \
+ TerminalType(termp).term_names, \
+ NAMESIZE - 1); \
+ ttytype[NAMESIZE - 1] = '\0'; \
+ }
+
+/* charable.c */
+#if USE_WIDEC_SUPPORT
+extern NCURSES_EXPORT(bool) _nc_is_charable(wchar_t);
+extern NCURSES_EXPORT(int) _nc_to_char(wint_t);
+extern NCURSES_EXPORT(wint_t) _nc_to_widechar(int);
+#endif
+
+/* comp_captab.c */
+typedef struct {
+ short nte_name; /* offset of name to hash on */
+ int nte_type; /* BOOLEAN, NUMBER or STRING */
+ short nte_index; /* index of associated variable in its array */
+ short nte_link; /* index in table of next hash, or -1 */
+} name_table_data;
+
+typedef struct
+{
+ short from;
+ short to;
+ short source;
+} alias_table_data;
+
+/* doupdate.c */
+#if USE_XMC_SUPPORT
+extern NCURSES_EXPORT(void) _nc_do_xmc_glitch (attr_t);
+#endif
+
+/* hardscroll.c */
+#if defined(TRACE) || defined(SCROLLDEBUG) || defined(HASHDEBUG)
+extern NCURSES_EXPORT(void) _nc_linedump (void);
+#endif
+
+/* lib_acs.c */
+extern NCURSES_EXPORT(void) _nc_init_acs (void); /* corresponds to traditional 'init_acs()' */
+extern NCURSES_EXPORT(int) _nc_msec_cost (const char *const, int); /* used by 'tack' program */
+
+/* lib_addch.c */
+#if USE_WIDEC_SUPPORT
+NCURSES_EXPORT(int) _nc_build_wch(WINDOW *win, ARG_CH_T ch);
+#endif
+
+/* lib_addstr.c */
+#if USE_WIDEC_SUPPORT && !(defined(USE_TERMLIB) || defined(USE_BUILD_CC))
+extern NCURSES_EXPORT(int) _nc_wchstrlen(const cchar_t *);
+#endif
+
+/* lib_color.c */
+extern NCURSES_EXPORT(int) _nc_init_color(SCREEN *, int, int, int, int);
+extern NCURSES_EXPORT(int) _nc_init_pair(SCREEN *, int, int, int);
+extern NCURSES_EXPORT(int) _nc_pair_content(SCREEN *, int, int *, int *);
+extern NCURSES_EXPORT(bool) _nc_reset_colors(void);
+extern NCURSES_EXPORT(colorpair_t *) _nc_reserve_pairs(SCREEN *, int);
+extern NCURSES_EXPORT(void) _nc_change_pair(SCREEN *, int);
+
+/* lib_getch.c */
+extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, int *, int EVENTLIST_2nd(_nc_eventlist *));
+
+/* lib_insch.c */
+extern NCURSES_EXPORT(int) _nc_insert_ch(SCREEN *, WINDOW *, chtype);
+
+/* lib_mvcur.c */
+#define INFINITY 1000000 /* cost: too high to use */
+
+extern NCURSES_EXPORT(int) _nc_mvcur(int yold, int xold, int ynew, int xnew);
+
+extern NCURSES_EXPORT(void) _nc_mvcur_init (void);
+extern NCURSES_EXPORT(void) _nc_mvcur_resume (void);
+extern NCURSES_EXPORT(void) _nc_mvcur_wrap (void);
+
+extern NCURSES_EXPORT(int) _nc_scrolln (int, int, int, int);
+
+extern NCURSES_EXPORT(void) _nc_screen_init (void);
+extern NCURSES_EXPORT(void) _nc_screen_resume (void);
+extern NCURSES_EXPORT(void) _nc_screen_wrap (void);
+
+/* lib_mouse.c */
+extern NCURSES_EXPORT(bool) _nc_has_mouse (SCREEN *);
+
+/* lib_mvcur.c */