]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/curses.priv.h
ncurses 6.0 - patch 20160130
[ncurses.git] / ncurses / curses.priv.h
index 67dcdcf8840d20238ed802bf1b41e9d8a2328ccc..b79602df8256e60f3c8dec93d834c8257cd93d6c 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2015,2016 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.496 2012/02/22 22:10:37 tom Exp $
+ * $Id: curses.priv.h,v 1.551 2016/01/24 01:39:09 tom Exp $
  *
  *     curses.priv.h
  *
@@ -86,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
@@ -173,6 +179,18 @@ extern int errno;
 #define USE_SIGWINCH 0
 #endif
 
+/*
+ * When building in the MSYS2 environment, the automatic discovery of
+ * the path separator in configure doesn't work properly. So, if building
+ * for MinGW, we enforce the correct Windows PATH separator
+ */
+#ifdef __MINGW32__
+#  ifdef NCURSES_PATHSEP
+#    undef NCURSES_PATHSEP
+#  endif
+#  define NCURSES_PATHSEP ';'
+#endif
+
 /*
  * If desired, one can configure this, disabling environment variables that
  * point to custom terminfo/termcap locations.
@@ -282,14 +300,6 @@ typedef TRIES {
  * Structure for palette tables
  */
 
-typedef struct
-{
-    short red, green, blue;    /* what color_content() returns */
-    short r, g, b;             /* params to init_color() */
-    int init;                  /* true if we called init_color() */
-}
-color_t;
-
 #define MAXCOLUMNS    135
 #define MAXLINES      66
 #define FIFO_SIZE     MAXCOLUMNS+2  /* for nocbreak mode input */
@@ -304,7 +314,7 @@ color_t;
 #undef _XOPEN_SOURCE_EXTENDED
 #undef _XPG5
 #define _nc_bkgd    _bkgd
-#define wgetbkgrnd(win, wch)   *wch = win->_bkgd
+#define wgetbkgrnd(win, wch)   ((*wch = win->_bkgd) != 0 ? OK : ERR)
 #define wbkgrnd            wbkgd
 #endif
 
@@ -314,6 +324,14 @@ color_t;
 
 #include <curses.h>    /* we'll use -Ipath directive to get the right one! */
 
+typedef struct
+{
+    NCURSES_COLOR_T red, green, blue;  /* what color_content() returns */
+    NCURSES_COLOR_T r, g, b;           /* params to init_color() */
+    int init;                  /* true if we called init_color() */
+}
+color_t;
+
 /*
  * If curses.h did not expose the SCREEN-functions, then we do not need the
  * parameter in the corresponding unextended functions.
@@ -344,7 +362,7 @@ color_t;
 #define HasTerminal(sp)      (((sp) != 0) && (0 != ((sp)->_term)))
 #define IsValidScreen(sp)    (HasTerminal(sp) && !IsPreScreen(sp))
 
-#if BROKEN_LINKER || USE_REENTRANT
+#if USE_REENTRANT
 #define CurTerm              _nc_prescreen._cur_term
 #else
 #define CurTerm              cur_term
@@ -373,6 +391,16 @@ color_t;
 
 #include <nc_tparm.h>
 
+/*
+ * Simplify ifdef's for the "*_ATTR" macros in case italics are not configured.
+ */
+#ifdef A_ITALIC
+#define USE_ITALIC 1
+#else
+#define USE_ITALIC 0
+#define A_ITALIC 0
+#endif
+
 /*
  * Use these macros internally, to make tracing less verbose.  But leave the
  * option for compiling the tracing into the library.
@@ -398,7 +426,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))
@@ -406,11 +434,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 */
 
@@ -423,14 +447,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)
@@ -500,6 +524,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
 
@@ -649,6 +676,14 @@ typedef enum {
 #endif
 } MouseType;
 
+typedef enum {
+       MF_X10 = 0              /* conventional 3-byte format */
+       , MF_SGR1006            /* xterm private mode 1006, SGR-style */
+#ifdef EXP_XTERM_1005
+       , MF_XTERM_1005         /* xterm UTF-8 private mode 1005 */
+#endif
+} MouseFormat;
+
 /*
  * Structures for scrolling.
  */
@@ -698,6 +733,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 */
@@ -808,6 +846,7 @@ typedef struct {
  * 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;
 
@@ -826,6 +865,7 @@ typedef struct {
 
        char            *first_name;
        char            **keyname_table;
+       int             init_keyname;
 
        int             slk_format;
 
@@ -935,6 +975,7 @@ typedef struct {
        const char      *_tputs_trace;
 #endif
 #endif
+       bool            use_tioctl;
 } NCURSES_PRESCREEN;
 
 /*
@@ -955,11 +996,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     */
@@ -1076,6 +1119,9 @@ struct screen {
        /* used in lib_vidattr.c */
        bool            _use_rmso;      /* true if we may use 'rmso'         */
        bool            _use_rmul;      /* true if we may use 'rmul'         */
+#if USE_ITALIC
+       bool            _use_ritm;      /* true if we may use 'ritm'         */
+#endif
 
 #if USE_KLIBC_KBD
        bool            _extended_key;  /* true if an extended key           */
@@ -1107,6 +1153,7 @@ struct screen {
        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 */
@@ -1153,6 +1200,7 @@ struct screen {
         */
 #if USE_SIZECHANGE
        int             (*_resize)(NCURSES_SP_DCLx int y, int x);
+       int             (*_ungetch)(SCREEN *, int);
 #endif
 
        /*
@@ -1171,7 +1219,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() */
@@ -1209,7 +1256,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;
@@ -1240,7 +1290,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> */
@@ -1318,8 +1368,8 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 
 #define UChar(c)       ((unsigned char)(c))
 #define UShort(c)      ((unsigned short)(c))
-#define ChCharOf(c)    ((c) & (chtype)A_CHARTEXT)
-#define ChAttrOf(c)    ((c) & (chtype)A_ATTRIBUTES)
+#define ChCharOf(c)    ((chtype)(c) & (chtype)A_CHARTEXT)
+#define ChAttrOf(c)    ((chtype)(c) & (chtype)A_ATTRIBUTES)
 
 #ifndef MB_LEN_MAX
 #define MB_LEN_MAX 8 /* should be >= MB_CUR_MAX, but that may be a function */
@@ -1373,24 +1423,28 @@ 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;                                              \
                            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) \
-                                       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, (size_t) PUTC_n, (size_t) 1, b)); \
                            }                                                       \
                            COUNT_OUTCHARS(PUTC_i);                                 \
                        } } } while (0)
@@ -1413,11 +1467,11 @@ 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) &&                         \
+                        || (!isWidecExt(ch))) &&                       \
                             (ch).chars[1] == L'\0' &&                  \
-                            _nc_is_charable(CharOf(ch))))
+                            _nc_is_charable(CharOf(ch)))
 
 #define L(ch)          L ## ch
 #else /* }{ */
@@ -1434,8 +1488,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)
@@ -1494,6 +1548,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.
  */
@@ -1557,27 +1625,31 @@ extern NCURSES_EXPORT(void)     _nc_locked_tracef (const char *, ...) GCC_PRINTFLIKE
 
 #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(value)
+#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)
 
-#define NonNull(s)     ((s) != 0 ? s : "<null>")
+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_RETURN(code,cptr)
-#define returnCVoidPtr(code)   TRACE_RETURN(code,cvoid_ptr)
+#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_RETURN(code,ptr)
-#define returnSP(code)         TRACE_RETURN(code,sp)
+#define returnPtr(code)                TRACE_RETURN1(code,ptr)
+#define returnSP(code)         TRACE_RETURN1(code,sp)
 #define returnVoid             T((T_RETURN(""))); return
-#define returnVoidPtr(code)    TRACE_RETURN(code,void_ptr)
-#define returnWin(code)                TRACE_RETURN(code,win)
+#define returnVoidPtr(code)    TRACE_RETURN1(code,void_ptr)
+#define returnWin(code)                TRACE_RETURN1(code,win)
 
 extern NCURSES_EXPORT(NCURSES_BOOL)     _nc_retrace_bool (int);
 extern NCURSES_EXPORT(NCURSES_CONST void *) _nc_retrace_cvoid_ptr (NCURSES_CONST void *);
@@ -1670,7 +1742,9 @@ extern    NCURSES_EXPORT(void) name (void); \
        NCURSES_EXPORT(void) name (void) { }
 
 #define ALL_BUT_COLOR ((chtype)~(A_COLOR))
-#define NONBLANK_ATTR (A_NORMAL|A_BOLD|A_DIM|A_BLINK)
+#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) {\
@@ -1846,6 +1920,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);
@@ -1874,9 +1950,10 @@ extern NCURSES_EXPORT(void)   _nc_tinfo_cmdch(TERMINAL *, int);
 extern NCURSES_EXPORT(int)    _nc_ripoffline(int, int(*)(WINDOW*, int));
 
 /* lib_setup.c */
+#define SETUP_FAIL ERR
 #define ret_error(code, fmt, arg)      if (errret) {\
                                            *errret = code;\
-                                           returnCode(ERR);\
+                                           returnCode(SETUP_FAIL);\
                                        } else {\
                                            fprintf(stderr, fmt, arg);\
                                            exit(EXIT_FAILURE);\
@@ -1886,7 +1963,7 @@ extern NCURSES_EXPORT(int)    _nc_ripoffline(int, int(*)(WINDOW*, int));
 
 #define ret_error0(code, msg)          if (errret) {\
                                            *errret = code;\
-                                           returnCode(ERR);\
+                                           returnCode(SETUP_FAIL);\
                                        } else {\
                                            fprintf(stderr, msg);\
                                            exit(EXIT_FAILURE);\
@@ -1941,6 +2018,7 @@ extern NCURSES_EXPORT(char *) _nc_trace_buf (int, size_t);
 extern NCURSES_EXPORT(char *) _nc_trace_bufcat (int, const char *);
 extern NCURSES_EXPORT(char *) _nc_tracechar (SCREEN *, int);
 extern NCURSES_EXPORT(char *) _nc_tracemouse (SCREEN *, MEVENT const *);
+extern NCURSES_EXPORT(char *) _nc_trace_mmask_t (SCREEN *, mmask_t);
 extern NCURSES_EXPORT(int) _nc_access (const char *, int);
 extern NCURSES_EXPORT(int) _nc_baudrate (int);
 extern NCURSES_EXPORT(int) _nc_freewin (WINDOW *);
@@ -1948,11 +2026,12 @@ extern NCURSES_EXPORT(int) _nc_getenv_num (const char *);
 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 *, int, 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 (int, int, int, NCURSES_OUTC);
 extern NCURSES_EXPORT(void) _nc_flush (void);
@@ -1966,6 +2045,7 @@ 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 *, 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 *);
@@ -2018,6 +2098,24 @@ 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, (size_t) 0)), IGNORE_RC(mbtowc(NULL, NULL, (size_t) 0))
 #define count_mbytes(buffer,length,state) mblen(buffer,length)
@@ -2032,7 +2130,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().
@@ -2046,8 +2145,6 @@ extern NCURSES_EXPORT_VAR(int *) _nc_oldnums;
 
 #define USE_SETBUF_0 0
 
-#define NC_BUFFERED(sp,flag) NCURSES_SP_NAME(_nc_set_buffer)(NCURSES_SP_ARGx sp->_ofp, flag)
-
 #define NC_OUTPUT(sp) ((sp != 0) ? sp->_ofp : stdout)
 
 /*
@@ -2121,16 +2218,15 @@ 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;      \
     }\
     sp->jump = outc
 
 #ifdef USE_TERM_DRIVER
-typedef void* TERM_HANDLE;
 
 typedef struct _termInfo
 {
@@ -2156,48 +2252,47 @@ typedef struct _termInfo
 
 typedef struct term_driver {
     bool   isTerminfo;
-    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*, int setFlag, TTY*);
-    chtype (*conattr)(struct DriverTCB*);
-    int    (*hwcur)(struct DriverTCB*, int yold, int xold, int y, int x);
-    int    (*mode)(struct DriverTCB*, int progFlag, int defFlag);
-    bool   (*rescol)(struct DriverTCB*);
-    bool   (*rescolors)(struct DriverTCB*);
-    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 EVENTLIST_2nd(_nc_eventlist*));
-    void   (*setfilter)(struct DriverTCB*);
-    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*);
-    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*, int);
-    int    (*kyOk)(struct DriverTCB*, int, int);
-    bool   (*kyExist)(struct DriverTCB*, int);
+    const char* (*td_name)(struct DriverTCB*);
+    bool   (*td_CanHandle)(struct DriverTCB*, const char*, int*);
+    void   (*td_init)(struct DriverTCB*);
+    void   (*td_release)(struct DriverTCB*);
+    int    (*td_size)(struct DriverTCB*, int* Line, int *Cols);
+    int    (*td_sgmode)(struct DriverTCB*, int setFlag, TTY*);
+    chtype (*td_conattr)(struct DriverTCB*);
+    int    (*td_hwcur)(struct DriverTCB*, int yold, int xold, int y, int x);
+    int    (*td_mode)(struct DriverTCB*, int progFlag, int defFlag);
+    bool   (*td_rescol)(struct DriverTCB*);
+    bool   (*td_rescolors)(struct DriverTCB*);
+    void   (*td_color)(struct DriverTCB*, int fore, int color, int(*)(SCREEN*, int));
+    int    (*td_doBeepOrFlash)(struct DriverTCB*, int);
+    void   (*td_initpair)(struct DriverTCB*, int, int, int);
+    void   (*td_initcolor)(struct DriverTCB*, int, int, int, int);
+    void   (*td_docolor)(struct DriverTCB*, int, int, int, int(*)(SCREEN*, int));
+    void   (*td_initmouse)(struct DriverTCB*);
+    int    (*td_testmouse)(struct DriverTCB*, int EVENTLIST_2nd(_nc_eventlist*));
+    void   (*td_setfilter)(struct DriverTCB*);
+    void   (*td_hwlabel)(struct DriverTCB*, int, char*);
+    void   (*td_hwlabelOnOff)(struct DriverTCB*, int);
+    int    (*td_update)(struct DriverTCB*);
+    int    (*td_defaultcolors)(struct DriverTCB*, int, int);
+    int    (*td_print)(struct DriverTCB*, char*, int);
+    int    (*td_getsize)(struct DriverTCB*, int*, int*);
+    int    (*td_setsize)(struct DriverTCB*, int, int);
+    void   (*td_initacs)(struct DriverTCB*, chtype*, chtype*);
+    void   (*td_scinit)(SCREEN *);
+    void   (*td_scexit)(SCREEN *);
+    int    (*td_twait)(struct DriverTCB*, int, int, int* EVENTLIST_2nd(_nc_eventlist*));
+    int    (*td_read)(struct DriverTCB*, int*);
+    int    (*td_nap)(struct DriverTCB*, int);
+    int    (*td_kpad)(struct DriverTCB*, int);
+    int    (*td_kyOk)(struct DriverTCB*, int, int);
+    bool   (*td_kyExist)(struct DriverTCB*, int);
+    int    (*td_cursorSet)(struct DriverTCB*, int);
 } TERM_DRIVER;
 
 typedef struct DriverTCB
 {
     TERMINAL      term;   /* needs to be the first Element !!! */
-    TERM_HANDLE   inp;    /* The input handle of the Terminal */
-    TERM_HANDLE   out;    /* The output handle of the Terminal in shell mode */
-    TERM_HANDLE   hdl;    /* The output handle of the Terminal in prog  mode */
     TERM_DRIVER*  drv;    /* The driver for that Terminal */
     SCREEN*       csp;    /* The screen that owns that Terminal */
     TerminalInfo  info;   /* Driver independent core capabilities of the Terminal */
@@ -2238,7 +2333,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
 
 /*
@@ -2264,20 +2359,44 @@ extern NCURSES_EXPORT(void)   _nc_get_screensize(SCREEN *, int *, int *);
 #endif /* !USE_TERM_DRIVER */
 
 #ifdef USE_TERM_DRIVER
-#ifdef __MINGW32__
+#if defined(USE_WIN32CON_DRIVER)
 #include <nc_mingw.h>
 extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_WIN_DRIVER;
+extern NCURSES_EXPORT(int)  _nc_mingw_isatty(int fd);
+extern NCURSES_EXPORT(int)  _nc_mingw_isconsole(int fd);
+extern NCURSES_EXPORT(int) _nc_mingw_console_read(
+    SCREEN *sp,
+    HANDLE  fd,
+    int *buf);
+extern NCURSES_EXPORT(int) _nc_mingw_testmouse(
+    SCREEN * sp,
+    HANDLE fd,
+    int delay);
+#else
 #endif
 extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_TINFO_DRIVER;
 #endif
 
+#if defined(USE_TERM_DRIVER) && defined(USE_WIN32CON_DRIVER)
+#define NC_ISATTY(fd) _nc_mingw_isatty(fd)
+#else
+#define NC_ISATTY(fd) isatty(fd)
+#endif
+
 #ifdef USE_TERM_DRIVER
-#define IsTermInfo(sp)       (TCBOf(sp) && ((TCBOf(sp)->drv->isTerminfo)))
+#  define IsTermInfo(sp)       ((TCBOf(sp) != 0) && ((TCBOf(sp)->drv->isTerminfo)))
+#  define HasTInfoTerminal(sp) ((0 != TerminalOf(sp)) && IsTermInfo(sp))
+#  if defined(USE_WIN32CON_DRIVER)
+#    define IsTermInfoOnConsole(sp) (IsTermInfo(sp)&&_nc_mingw_isconsole(TerminalOf(sp)->Filedes))
 #else
-#define IsTermInfo(sp)       TRUE
+#    define IsTermInfoOnConsole(sp) FALSE
+#  endif
+#else
+#  define IsTermInfo(sp)       TRUE
+#  define HasTInfoTerminal(sp) (0 != TerminalOf(sp))
+#  define IsTermInfoOnConsole(sp) FALSE
 #endif
 
-#define HasTInfoTerminal(sp) ((0 != TerminalOf(sp)) && IsTermInfo(sp))
 #define IsValidTIScreen(sp)  (HasTInfoTerminal(sp))
 
 /*
@@ -2311,7 +2430,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*);
@@ -2325,7 +2446,7 @@ 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 *, 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_vid_attr)(SCREEN *, attr_t, NCURSES_COLOR_T, 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*, int, int, int, NCURSES_SP_OUTC);
 extern NCURSES_EXPORT(void)     NCURSES_SP_NAME(_nc_do_xmc_glitch)(SCREEN*, attr_t);
@@ -2375,6 +2496,11 @@ extern NCURSES_EXPORT(NCURSES_CONST char *) _nc_unctrl (SCREEN *, chtype);
 
 #endif
 
+#ifdef EXP_XTERM_1005
+NCURSES_EXPORT(int) _nc_conv_to_utf8(unsigned char *, unsigned, unsigned);
+NCURSES_EXPORT(int) _nc_conv_to_utf32(unsigned *, const char *, unsigned);
+#endif
+
 #ifdef __cplusplus
 }
 #endif