]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/curses.priv.h
ncurses 5.9 - patch 20130324
[ncurses.git] / ncurses / curses.priv.h
index 0db05ddf986b946a5bcfb9dfc68b082f7cbf8c6f..281bb4b700fcfbc5b63517e76167ad501be75a20 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.              *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
@@ -34,7 +34,7 @@
  ****************************************************************************/
 
 /*
- * $Id: curses.priv.h,v 1.472 2011/01/01 23:01:40 tom Exp $
+ * $Id: curses.priv.h,v 1.523 2013/01/26 21:51:56 tom Exp $
  *
  *     curses.priv.h
  *
@@ -65,6 +65,7 @@ extern "C" {
 #include <stdlib.h>
 #include <string.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 
 #if HAVE_UNISTD_H
 #include <unistd.h>
@@ -85,6 +86,12 @@ extern "C" {
 
 #include <errno.h>
 
+#if defined __hpux
+#  ifndef EILSEQ
+#    define EILSEQ 47
+#  endif
+#endif
+
 #ifndef PATH_MAX
 # if defined(_POSIX_PATH_MAX)
 #  define PATH_MAX _POSIX_PATH_MAX
@@ -111,6 +118,14 @@ extern int errno;
 #define USE_FUNC_POLL 0
 #endif
 
+#if HAVE_INTTYPES_H
+# include <inttypes.h>
+#else
+# if HAVE_STDINT_H
+#  include <stdint.h>
+# endif
+#endif
+
 /* include signal.h before curses.h to work-around defect in glibc 2.1.3 */
 #include <signal.h>
 
@@ -135,6 +150,15 @@ extern int errno;
 #define USE_EMX_MOUSE 0
 #endif
 
+/* kLIBC keyboard/mouse support */
+#if defined(__OS2__) && defined(__KLIBC__)
+#define USE_KLIBC_KBD   1
+#define USE_KLIBC_MOUSE 1
+#else
+#define USE_KLIBC_KBD   0
+#define USE_KLIBC_MOUSE 0
+#endif
+
 #define DEFAULT_MAXCLICK 166
 #define EV_MAX         8       /* size of mouse circular event queue */
 
@@ -191,6 +215,18 @@ extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t);
 #define end_va_copy(dst)       /* nothing */
 #endif
 
+/*
+ * Either/both S_ISxxx and/or S_IFxxx are defined in sys/types.h; some systems
+ * lack one or the other.
+ */
+#ifndef S_ISDIR
+#define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR)
+#endif
+
+#ifndef S_ISREG
+#define S_ISREG(mode) ((mode & S_IFMT) == S_IFREG)
+#endif
+
 /*
  * Scroll hints are useless when hashmap is used
  */
@@ -208,6 +244,8 @@ extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t);
 #define if_USE_SCROLL_HINTS(stmt) /*nothing*/
 #endif
 
+#include <nc_string.h>
+
 /*
  * Options for terminal drivers, etc...
  */
@@ -325,6 +363,7 @@ color_t;
 #endif
 
 #include <term.h>
+#include <nc_termios.h>
 
 /*
  * Reduce dependency on cur_term global by using terminfo data from SCREEN's
@@ -365,7 +404,7 @@ color_t;
 #define if_EXT_COLORS(stmt)    stmt
 #define SetPair(value,p)       SetPair2((value).ext_color, AttrOf(value), p)
 #define SetPair2(c,a,p)                c = (p), \
-                               a = (unColor2(a) | (A_COLOR & ColorPair(oldColor(c))))
+                               a = (unColor2(a) | (A_COLOR & (unsigned) ColorPair(oldColor(c))))
 #define GetPair(value)         GetPair2((value).ext_color, AttrOf(value))
 #define GetPair2(c,a)          ((c) ? (c) : PairNumber(a))
 #define oldColor(p)            (((p) > 255) ? 255 : (p))
@@ -373,11 +412,7 @@ color_t;
 #define SET_WINDOW_PAIR(w,p)   (w)->_color = (p)
 #define SameAttrOf(a,b)                (AttrOf(a) == AttrOf(b) && GetPair(a) == GetPair(b))
 
-#if NCURSES_SP_FUNCS
-#define VIDATTR(sp,attr,pair)  NCURSES_SP_NAME(vid_attr)(sp, attr, pair, 0)
-#else
-#define VIDATTR(sp,attr,pair)  vid_attr(attr, pair, 0)
-#endif
+#define VIDATTR(sp,attr,pair)  NCURSES_SP_NAME(vid_puts)(NCURSES_SP_ARGx attr, (short) pair, 0, NCURSES_OUTC_FUNC)
 
 #else /* !NCURSES_EXT_COLORS */
 
@@ -390,14 +425,14 @@ color_t;
                                WINDOW_ATTRS(w) |= (A_COLOR & (attr_t) ColorPair(p))
 #define SameAttrOf(a,b)                (AttrOf(a) == AttrOf(b))
 
-#if NCURSES_SP_FUNCS
-#define VIDATTR(sp,attr,pair)  NCURSES_SP_NAME(vidattr)(sp, attr)
-#else
-#define VIDATTR(sp,attr,pair)  vidattr(attr)
-#endif
+#define VIDATTR(sp,attr,pair)  NCURSES_SP_NAME(vidputs)(NCURSES_SP_ARGx attr, NCURSES_OUTC_FUNC)
 
 #endif /* NCURSES_EXT_COLORS */
 
+#define NCURSES_OUTC_FUNC       NCURSES_SP_NAME(_nc_outch)
+#define NCURSES_PUTP2(name,value)    NCURSES_SP_NAME(_nc_putp)(NCURSES_SP_ARGx name, value)
+#define NCURSES_PUTP2_FLUSH(name,value)    NCURSES_SP_NAME(_nc_putp_flush)(NCURSES_SP_ARGx name, value)
+
 #if NCURSES_NO_PADDING
 #define GetNoPadding(sp)       ((sp) ? (sp)->_no_padding : _nc_prescreen._no_padding)
 #define SetNoPadding(sp)       _nc_set_no_padding(sp)
@@ -467,6 +502,9 @@ NCURSES_EXPORT(int *)        _nc_ptr_Escdelay (SCREEN *);
 #  endif
 #  define _declare(name)       __extension__ extern __typeof__(name) name
 #  define weak_symbol(name)    _weak_pragma(name) _declare(name) __attribute__((weak))
+#else
+#  undef USE_WEAK_SYMBOLS
+#  define USE_WEAK_SYMBOLS 0
 #endif
 #endif
 
@@ -490,6 +528,7 @@ extern NCURSES_EXPORT(int) _nc_mutex_unlock(pthread_mutex_t *);
 #ifdef USE_PTHREADS
 #  if USE_WEAK_SYMBOLS
 weak_symbol(pthread_sigmask);
+weak_symbol(pthread_kill);
 weak_symbol(pthread_self);
 weak_symbol(pthread_equal);
 weak_symbol(pthread_mutex_init);
@@ -664,6 +703,9 @@ typedef     struct {
 #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 */
@@ -765,17 +807,23 @@ struct DriverTCB; /* Terminal Control Block forward declaration */
 #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;
 
-       const char      *comp_sourcename;
+       char            *comp_sourcename;
        char            *comp_termtype;
 
        bool            have_tic_directory;
@@ -797,6 +845,12 @@ typedef struct {
        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];
+
 #ifndef USE_SP_WINDOWLIST
        WINDOWLIST      *_nc_windowlist;
 #define WindowList(sp) _nc_globals._nc_windowlist
@@ -890,6 +944,7 @@ typedef struct {
        const char      *_tputs_trace;
 #endif
 #endif
+       bool            use_tioctl;
 } NCURSES_PRESCREEN;
 
 /*
@@ -910,11 +965,13 @@ extern NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen;
  */
 
 struct screen {
-       int             _ifd;           /* input file ptr for screen        */
+       int             _ifd;           /* input file descriptor for screen */
+       int             _ofd;           /* output file descriptor for screen */
        FILE            *_ofp;          /* output file ptr for screen       */
-       char            *_setbuf;       /* buffered I/O for output          */
+       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            _buffered;      /* setvbuf uses _setbuf data        */
        bool            _prescreen;     /* is in prescreen phase            */
        bool            _use_env;       /* LINES & COLS from environment?   */
        int             _checkfd;       /* filedesc for typeahead check     */
@@ -1014,6 +1071,7 @@ struct screen {
        int             _pair_count;    /* count of color pairs              */
        int             _pair_limit;    /* actual limit of color-pairs       */
 #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        */
@@ -1031,6 +1089,10 @@ struct screen {
        bool            _use_rmso;      /* true if we may use 'rmso'         */
        bool            _use_rmul;      /* true if we may use 'rmul'         */
 
+#if USE_KLIBC_KBD
+       bool            _extended_key;  /* true if an extended key           */
+#endif
+
        /*
         * These data correspond to the state of the idcok() and idlok()
         * functions.  A caveat is in order here:  the XSI and SVr4
@@ -1054,7 +1116,9 @@ struct screen {
        void            (*_mouse_wrap)  (SCREEN *);
        int             _mouse_fd;      /* file-descriptor, if any */
        bool            _mouse_active;  /* true if initialized */
-       mmask_t         _mouse_mask;
+       mmask_t         _mouse_mask;    /* set via mousemask() */
+       mmask_t         _mouse_mask2;   /* OR's in press/release bits */
+       mmask_t         _mouse_bstate;
        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 */
@@ -1101,6 +1165,7 @@ struct screen {
         */
 #if USE_SIZECHANGE
        int             (*_resize)(NCURSES_SP_DCLx int y, int x);
+       int             (*_ungetch)(SCREEN *, int);
 #endif
 
        /*
@@ -1119,7 +1184,6 @@ struct screen {
        int             *_oldnum_list;
        int             _oldnum_size;
 
-       bool            _cleanup;       /* cleanup after int/quit signal */
        NCURSES_SP_OUTC _outch;         /* output handler if not putc */
 
        int             _legacy_coding; /* see use_legacy_coding() */
@@ -1157,7 +1221,10 @@ struct screen {
         * UTF-8, but do not permit ACS at the same time (see tty_update.c).
         */
        bool            _screen_acs_fix;
+       bool            _screen_unicode;
 #endif
+
+       bool            _use_tioctl;
 };
 
 extern NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain;
@@ -1167,7 +1234,7 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
        WINDOWLIST *next;
        SCREEN *screen;         /* screen containing the window */
        WINDOW  win;            /* WINDOW_EXT() needs to account for offset */
-#ifdef NCURSES_WIDECHAR
+#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[] */
@@ -1188,7 +1255,7 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
     sp->_endwin = TRUE;                         \
     sp->_cursor = -1;                           \
     WindowList(sp) = 0;                         \
-    sp->_outch = NCURSES_SP_NAME(_nc_outch);    \
+    sp->_outch = NCURSES_OUTC_FUNC;             \
     sp->jump = 0                                \
 
 /* usually in <limits.h> */
@@ -1321,9 +1388,9 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 #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,b)     do { if(!isWidecExt(ch)) {                                  \
+#define PUTC(ch)       do { if(!isWidecExt(ch)) {                                  \
                        if (Charable(ch)) {                                         \
-                           fputc(CharOf(ch), b);                                   \
+                           NCURSES_OUTC_FUNC (NCURSES_SP_ARGx CharOf(ch)); \
                            COUNT_OUTCHARS(1);                                      \
                        } else {                                                    \
                            PUTC_INIT;                                              \
@@ -1335,10 +1402,14 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
                                                       (ch).chars[PUTC_i], &PUT_st); \
                                if (PUTC_n <= 0) {                                  \
                                    if (PUTC_ch && is8bits(PUTC_ch) && PUTC_i == 0) \
-                                       putc(PUTC_ch,b);                            \
+                                       NCURSES_OUTC_FUNC (NCURSES_SP_ARGx CharOf(ch)); \
                                    break;                                          \
+                               } else {                                            \
+                                   int PUTC_j;                                     \
+                                   for (PUTC_j = 0; PUTC_j < PUTC_n; ++PUTC_j) {   \
+                                       NCURSES_OUTC_FUNC (NCURSES_SP_ARGx PUTC_buf[PUTC_j]); \
+                                   }                                               \
                                }                                                   \
-                               IGNORE_RC(fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b)); \
                            }                                                       \
                            COUNT_OUTCHARS(PUTC_i);                                 \
                        } } } while (0)
@@ -1361,7 +1432,7 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
                                AttrOf(dst) |= (attr_t) (ext + 1)
 
 #define if_WIDEC(code)  code
-#define Charable(ch)   ((SP_PARM != 0 && SP_PARM->_legacy_coding)      \
+#define Charable(ch)   ((SP_PARM->_legacy_coding)                      \
                         || (AttrOf(ch) & A_ALTCHARSET)                 \
                         || (!isWidecExt(ch) &&                         \
                             (ch).chars[1] == L'\0' &&                  \
@@ -1382,8 +1453,8 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 #define CHDEREF(wch)   wch
 #define ARG_CH_T       NCURSES_CH_T
 #define CARG_CH_T      NCURSES_CH_T
-#define PUTC_DATA      int data = 0
-#define PUTC(ch,b)     do { data = CharOf(ch); putc(data,b); } while (0)
+#define PUTC_DATA      /* nothing */
+#define PUTC(ch)       NCURSES_OUTC_FUNC (NCURSES_SP_ARGx (int) ch)
 
 #define BLANK          (' '|A_NORMAL)
 #define ZEROS          ('\0'|A_NORMAL)
@@ -1411,25 +1482,25 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 
 #define CHANGED_CELL(line,col) \
        if (line->firstchar == _NOCHANGE) \
-               line->firstchar = line->lastchar = (NCURSES_SIZE_T) col; \
+               line->firstchar = line->lastchar = (NCURSES_SIZE_T) (col); \
        else if ((col) < line->firstchar) \
-               line->firstchar = (NCURSES_SIZE_T) col; \
+               line->firstchar = (NCURSES_SIZE_T) (col); \
        else if ((col) > line->lastchar) \
-               line->lastchar = (NCURSES_SIZE_T) col
+               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; \
+               line->firstchar = (NCURSES_SIZE_T) (start); \
        if (line->lastchar == _NOCHANGE \
         || line->lastchar < (end)) \
-               line->lastchar = (NCURSES_SIZE_T) 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
+               line->firstchar = (NCURSES_SIZE_T) (start); \
+       line->lastchar = (NCURSES_SIZE_T) (end)
 
 #define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
 
@@ -1442,6 +1513,20 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 
 #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) \
+       name = typeMalloc(type, size); \
+       if (name == 0) \
+           _nc_err_abort(MSG_NO_MEMORY)
+
+#define TYPE_REALLOC(type, size, name) \
+       name = typeRealloc(type, size, name); \
+       if (name == 0) \
+           _nc_err_abort(MSG_NO_MEMORY)
+
 /*
  * TTY bit definition for converting tabs to spaces.
  */
@@ -1527,7 +1612,7 @@ extern NCURSES_EXPORT(void)       _nc_locked_tracef (const char *, ...) GCC_PRINTFLIKE
 #define returnVoidPtr(code)    TRACE_RETURN(code,void_ptr)
 #define returnWin(code)                TRACE_RETURN(code,win)
 
-extern NCURSES_EXPORT(NCURSES_BOOL)     _nc_retrace_bool (NCURSES_BOOL);
+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 *);
@@ -1538,7 +1623,7 @@ 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 (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);
@@ -1710,7 +1795,7 @@ extern NCURSES_EXPORT(int) NCURSES_SP_NAME(_nc_InsCharCost) (NCURSES_SP_DCLx int
 #undef  UpdateAttrs
 #define UpdateAttrs(sp,c) NCURSES_SP_NAME(_nc_UpdateAttrs)(NCURSES_SP_ARGx CHREF(c))
 
-#if defined(NEED_NCURSES_CH_T)
+#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);
@@ -1794,6 +1879,8 @@ 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);
@@ -1815,12 +1902,31 @@ extern NCURSES_EXPORT(bool) _nc_has_mouse (SCREEN *);
 extern NCURSES_EXPORT(char *) _nc_get_locale(void);
 extern NCURSES_EXPORT(int)    _nc_unicode_locale(void);
 extern NCURSES_EXPORT(int)    _nc_locale_breaks_acs(TERMINAL *);
-extern NCURSES_EXPORT(int)    _nc_setupterm(NCURSES_CONST char *, int, int *, bool);
-extern NCURSES_EXPORT(void)   _nc_tinfo_cmdch(TERMINAL *, char);
+extern NCURSES_EXPORT(int)    _nc_setupterm(NCURSES_CONST char *, int, int *, int);
+extern NCURSES_EXPORT(void)   _nc_tinfo_cmdch(TERMINAL *, int);
 
 /* lib_set_term.c */
 extern NCURSES_EXPORT(int)    _nc_ripoffline(int, int(*)(WINDOW*, int));
 
+/* lib_setup.c */
+#define ret_error(code, fmt, arg)      if (errret) {\
+                                           *errret = code;\
+                                           returnCode(ERR);\
+                                       } else {\
+                                           fprintf(stderr, fmt, arg);\
+                                           exit(EXIT_FAILURE);\
+                                       }
+
+#define ret_error1(code, fmt, arg)     ret_error(code, "'%s': " fmt, arg)
+
+#define ret_error0(code, msg)          if (errret) {\
+                                           *errret = code;\
+                                           returnCode(ERR);\
+                                       } else {\
+                                           fprintf(stderr, msg);\
+                                           exit(EXIT_FAILURE);\
+                                       }
+
 /* lib_tstp.c */
 #if USE_SIGWINCH
 extern NCURSES_EXPORT(int) _nc_handle_sigwinch(SCREEN *);
@@ -1874,16 +1980,17 @@ extern NCURSES_EXPORT(int) _nc_access (const char *, int);
 extern NCURSES_EXPORT(int) _nc_baudrate (int);
 extern NCURSES_EXPORT(int) _nc_freewin (WINDOW *);
 extern NCURSES_EXPORT(int) _nc_getenv_num (const char *);
-extern NCURSES_EXPORT(int) _nc_keypad (SCREEN *, bool);
+extern NCURSES_EXPORT(int) _nc_keypad (SCREEN *, int);
 extern NCURSES_EXPORT(int) _nc_ospeed (int);
 extern NCURSES_EXPORT(int) _nc_outch (int);
+extern NCURSES_EXPORT(int) _nc_putchar (int);
 extern NCURSES_EXPORT(int) _nc_putp(const char *, const char *);
 extern NCURSES_EXPORT(int) _nc_putp_flush(const char *, const char *);
 extern NCURSES_EXPORT(int) _nc_read_termcap_entry (const char *const, TERMTYPE *const);
-extern NCURSES_EXPORT(int) _nc_setupscreen (int, int, FILE *, bool, int);
 extern NCURSES_EXPORT(int) _nc_setup_tinfo(const char *, TERMTYPE *);
+extern NCURSES_EXPORT(int) _nc_setupscreen (int, int, FILE *, int, int);
 extern NCURSES_EXPORT(int) _nc_timed_wait (SCREEN *, int, int, int * EVENTLIST_2nd(_nc_eventlist *));
-extern NCURSES_EXPORT(void) _nc_do_color (short, short, bool, NCURSES_OUTC);
+extern NCURSES_EXPORT(void) _nc_do_color (int, int, int, NCURSES_OUTC);
 extern NCURSES_EXPORT(void) _nc_flush (void);
 extern NCURSES_EXPORT(void) _nc_free_and_exit (int) GCC_NORETURN;
 extern NCURSES_EXPORT(void) _nc_free_entry (ENTRY *, TERMTYPE *);
@@ -1894,8 +2001,9 @@ extern NCURSES_EXPORT(void) _nc_keep_tic_dir (const char *);
 extern NCURSES_EXPORT(void) _nc_make_oldhash (int i);
 extern NCURSES_EXPORT(void) _nc_scroll_oldhash (int n, int top, int bot);
 extern NCURSES_EXPORT(void) _nc_scroll_optimize (void);
-extern NCURSES_EXPORT(void) _nc_set_buffer (FILE *, bool);
-extern NCURSES_EXPORT(void) _nc_signal_handler (bool);
+extern NCURSES_EXPORT(void) _nc_set_buffer (FILE *, int);
+extern NCURSES_EXPORT(void) _nc_setenv_num (const char *, int);
+extern NCURSES_EXPORT(void) _nc_signal_handler (int);
 extern NCURSES_EXPORT(void) _nc_synchook (WINDOW *);
 extern NCURSES_EXPORT(void) _nc_trace_tries (TRIES *);
 
@@ -1904,7 +2012,9 @@ extern NCURSES_EXPORT(void) _nc_alloc_entry_leaks(void);
 extern NCURSES_EXPORT(void) _nc_captoinfo_leaks(void);
 extern NCURSES_EXPORT(void) _nc_codes_leaks(void);
 extern NCURSES_EXPORT(void) _nc_comp_captab_leaks(void);
+extern NCURSES_EXPORT(void) _nc_comp_error_leaks(void);
 extern NCURSES_EXPORT(void) _nc_comp_scan_leaks(void);
+extern NCURSES_EXPORT(void) _nc_db_iterator_leaks(void);
 extern NCURSES_EXPORT(void) _nc_keyname_leaks(void);
 extern NCURSES_EXPORT(void) _nc_names_leaks(void);
 extern NCURSES_EXPORT(void) _nc_tgetent_leaks(void);
@@ -1913,7 +2023,7 @@ extern NCURSES_EXPORT(void) _nc_tgetent_leaks(void);
 #if !(defined(USE_TERMLIB) || defined(USE_BUILD_CC))
 extern NCURSES_EXPORT(NCURSES_CH_T) _nc_render (WINDOW *, NCURSES_CH_T);
 extern NCURSES_EXPORT(int) _nc_waddch_nosync (WINDOW *, const NCURSES_CH_T);
-extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, NCURSES_SIZE_T const, NCURSES_SIZE_T const, NCURSES_CH_T);
+extern NCURSES_EXPORT(void) _nc_scroll_window (WINDOW *, int const, int const, int const, NCURSES_CH_T);
 #endif
 
 #if USE_WIDEC_SUPPORT
@@ -1945,8 +2055,26 @@ extern NCURSES_EXPORT(int) _nc_eventlist_timeout(_nc_eventlist *);
  * Wide-character macros to hide some platform-differences.
  */
 #if USE_WIDEC_SUPPORT
+
+#if defined(__MINGW32__)
+/*
+ * MinGW has wide-character functions, but they do not work correctly.
+ */
+
+extern int __MINGW_NOTHROW _nc_wctomb(char *, wchar_t);
+#define wctomb(s,wc) _nc_wctomb(s,wc)
+#define wcrtomb(s,wc,n) _nc_wctomb(s,wc)
+
+extern int __MINGW_NOTHROW _nc_mbtowc(wchar_t *, const char *, size_t);
+#define mbtowc(pwc,s,n) _nc_mbtowc(pwc,s,n)
+
+extern int __MINGW_NOTHROW _nc_mblen(const char *, size_t);
+#define mblen(s,n) _nc_mblen(s, n)
+
+#endif /* __MINGW32__ */
+
 #if HAVE_MBTOWC && HAVE_MBLEN
-#define reset_mbytes(state) IGNORE_RC(mblen(NULL, 0)), IGNORE_RC(mbtowc(NULL, NULL, 0))
+#define reset_mbytes(state) IGNORE_RC(mblen(NULL, (size_t) 0)), IGNORE_RC(mbtowc(NULL, NULL, (size_t) 0))
 #define count_mbytes(buffer,length,state) mblen(buffer,length)
 #define check_mbytes(wch,buffer,length,state) \
        (int) mbtowc(&wch, buffer, length)
@@ -1959,7 +2087,8 @@ extern NCURSES_EXPORT(int) _nc_eventlist_timeout(_nc_eventlist *);
 #else
 make an error
 #endif
-#endif
+
+#endif /* USE_WIDEC_SUPPORT */
 
 /*
  * Not everyone has vsscanf(), but we'd like to use it for scanw().
@@ -2048,9 +2177,9 @@ extern NCURSES_EXPORT(int) _nc_get_tty_mode(TTY *);
 
 #define SetSafeOutcWrapper(outc)           \
     SCREEN* sp = CURRENT_SCREEN;            \
+    struct screen outc_wrapper;                    \
     if (sp==0) {                            \
-       struct screen dummy;                \
-       sp = &dummy;                        \
+       sp = &outc_wrapper;                 \
        memset(sp,0,sizeof(struct screen)); \
        sp->_outch = _nc_outc_wrapper;      \
     }\
@@ -2083,39 +2212,39 @@ typedef struct _termInfo
 
 typedef struct term_driver {
     bool   isTerminfo;
-    bool   (*CanHandle)(struct DriverTCB*,const char*,int*);
+    bool   (*CanHandle)(struct DriverTCB*, const char*, int*);
     void   (*init)(struct DriverTCB*);
     void   (*release)(struct DriverTCB*);
     int    (*size)(struct DriverTCB*, int* Line, int *Cols);
-    int    (*sgmode)(struct DriverTCB*, bool setFlag, TTY*);
+    int    (*sgmode)(struct DriverTCB*, int setFlag, TTY*);
     chtype (*conattr)(struct DriverTCB*);
     int    (*hwcur)(struct DriverTCB*, int yold, int xold, int y, int x);
-    int    (*mode)(struct DriverTCB*, bool progFlag, bool defFlag);
+    int    (*mode)(struct DriverTCB*, int progFlag, int defFlag);
     bool   (*rescol)(struct DriverTCB*);
     bool   (*rescolors)(struct DriverTCB*);
-    void   (*color)(struct DriverTCB*,bool fore, int color, int(*)(SCREEN*,int));
-    int    (*doBeepOrFlash)(struct DriverTCB*, bool);
-    void   (*initpair)(struct DriverTCB*,short,short,short);
-    void   (*initcolor)(struct DriverTCB*,short,short,short,short);
-    void   (*docolor)(struct DriverTCB*,short,short,bool,int(*)(SCREEN*,int));
+    void   (*color)(struct DriverTCB*, int fore, int color, int(*)(SCREEN*, int));
+    int    (*doBeepOrFlash)(struct DriverTCB*, int);
+    void   (*initpair)(struct DriverTCB*, int, int, int);
+    void   (*initcolor)(struct DriverTCB*, int, int, int, int);
+    void   (*docolor)(struct DriverTCB*, int, int, int, int(*)(SCREEN*, int));
     void   (*initmouse)(struct DriverTCB*);
-    int    (*testmouse)(struct DriverTCB*,int);
+    int    (*testmouse)(struct DriverTCB*, int EVENTLIST_2nd(_nc_eventlist*));
     void   (*setfilter)(struct DriverTCB*);
-    void   (*hwlabel)(struct DriverTCB*,int,char*);
-    void   (*hwlabelOnOff)(struct DriverTCB*,bool);
+    void   (*hwlabel)(struct DriverTCB*, int, char*);
+    void   (*hwlabelOnOff)(struct DriverTCB*, int);
     int    (*update)(struct DriverTCB*);
-    int    (*defaultcolors)(struct DriverTCB*,int,int);
-    int    (*print)(struct DriverTCB*,char*,int);
-    int    (*getsize)(struct DriverTCB*,int*,int*);
-    int    (*setsize)(struct DriverTCB*,int,int);
-    void   (*initacs)(struct DriverTCB*,chtype*,chtype*);
+    int    (*defaultcolors)(struct DriverTCB*, int, int);
+    int    (*print)(struct DriverTCB*, char*, int);
+    int    (*getsize)(struct DriverTCB*, int*, int*);
+    int    (*setsize)(struct DriverTCB*, int, int);
+    void   (*initacs)(struct DriverTCB*, chtype*, chtype*);
     void   (*scinit)(SCREEN *);
     void   (*scexit)(SCREEN *);
-    int    (*twait)(struct DriverTCB*,int,int,int* EVENTLIST_2nd(_nc_eventlist*));
-    int    (*read)(struct DriverTCB*,int*);
-    int    (*nap)(struct DriverTCB*,int);
-    int    (*kpad)(struct DriverTCB*, bool);
-    int    (*kyOk)(struct DriverTCB*, int, bool);
+    int    (*twait)(struct DriverTCB*, int, int, int* EVENTLIST_2nd(_nc_eventlist*));
+    int    (*read)(struct DriverTCB*, int*);
+    int    (*nap)(struct DriverTCB*, int);
+    int    (*kpad)(struct DriverTCB*, int);
+    int    (*kyOk)(struct DriverTCB*, int, int);
     bool   (*kyExist)(struct DriverTCB*, int);
 } TERM_DRIVER;
 
@@ -2165,7 +2294,7 @@ extern NCURSES_EXPORT(int)      TINFO_MVCUR(SCREEN*, int, int, int, int);
 #else
 #define TINFO_HAS_KEY           NCURSES_SP_NAME(has_key)
 #define TINFO_DOUPDATE          NCURSES_SP_NAME(doupdate)
-#define TINFO_MVCUR             NCURSES_SP_NAME(mvcur)
+#define TINFO_MVCUR             NCURSES_SP_NAME(_nc_mvcur)
 #endif
 
 /*
@@ -2173,7 +2302,7 @@ extern NCURSES_EXPORT(int)      TINFO_MVCUR(SCREEN*, int, int, int, int);
  */
 #ifdef USE_TERM_DRIVER
 extern NCURSES_EXPORT(void)   _nc_get_screensize(SCREEN *, TERMINAL *, int *, int *);
-extern NCURSES_EXPORT(int)    _nc_setupterm_ex(TERMINAL **, NCURSES_CONST char *, int , int *, bool);
+extern NCURSES_EXPORT(int)    _nc_setupterm_ex(TERMINAL **, NCURSES_CONST char *, int , int *, int);
 #define TINFO_GET_SIZE(sp, tp, lp, cp) \
        _nc_get_screensize(sp, tp, lp, cp)
 #define TINFO_SET_CURTERM(sp, tp) \
@@ -2238,7 +2367,9 @@ extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_curs_set)(SCREEN*,int);
 extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_get_tty_mode)(SCREEN*,TTY*);
 extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_mcprint)(SCREEN*,char*, int);
 extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_msec_cost)(SCREEN*, const char *, int);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_mvcur)(SCREEN*, int, int, int, int);
 extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_outch)(SCREEN*, int);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_putchar)(SCREEN*, int);
 extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_putp)(SCREEN*, const char *, const char*);
 extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_putp_flush)(SCREEN*, const char *, const char *);
 extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_resetty)(SCREEN*);
@@ -2249,12 +2380,12 @@ extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_scr_init)(SCREEN*,const char
 extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_scr_restore)(SCREEN*, const char*);
 extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_scrolln)(SCREEN*, int, int, int, int);
 extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_set_tty_mode)(SCREEN*, TTY*);
-extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_setupscreen)(SCREEN**, int, int, FILE *, bool, int);
+extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_setupscreen)(SCREEN**, int, int, FILE *, int, int);
 extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_tgetent)(SCREEN*,char*,const char *);
 extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_tigetnum)(SCREEN*,NCURSES_CONST char*);
 extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_vid_attr)(SCREEN *, attr_t, short, void *);
 extern NCURSES_EXPORT(int)      NCURSES_SP_NAME(_nc_vidputs)(SCREEN*,chtype,int(*) (SCREEN*, int));
-extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_do_color)(SCREEN*, short, short, bool, NCURSES_SP_OUTC);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_do_color)(SCREEN*, int, int, int, NCURSES_SP_OUTC);
 extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_do_xmc_glitch)(SCREEN*, attr_t);
 extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_flush)(SCREEN*);
 extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_free_and_exit)(SCREEN*, int) GCC_NORETURN;
@@ -2270,7 +2401,7 @@ extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_screen_resume)(SCREEN*);
 extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_screen_wrap)(SCREEN*);
 extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_scroll_oldhash)(SCREEN*, int n, int top, int bot);
 extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_scroll_optimize)(SCREEN*);
-extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_set_buffer)(SCREEN*, FILE *, bool);
+extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_set_buffer)(SCREEN*, FILE *, int);
 
 extern NCURSES_EXPORT(void)     _nc_cookie_init(SCREEN *sp);