+#ifdef __cplusplus
+#define NCURSES_VOID /* nothing */
+#else
+#define NCURSES_VOID (void)
+#endif
+
+#ifndef HAVE_STRLCAT
+#define HAVE_STRLCAT 0
+#endif
+
+#ifndef HAVE_STRLCPY
+#define HAVE_STRLCPY 0
+#endif
+
+#ifndef HAVE_SNPRINTF
+#define HAVE_SNPRINTF 0
+#endif
+
+#ifndef USE_STRING_HACKS
+#define USE_STRING_HACKS 0
+#endif
+
+#ifndef NCURSES_CAST
+#ifdef __cplusplus
+extern "C" {
+#define NCURSES_CAST(type,value) static_cast<type>(value)
+#else
+#define NCURSES_CAST(type,value) (type)(value)
+#endif
+#endif
+
+#if USE_STRING_HACKS && HAVE_STRLCAT
+#define _nc_STRCAT(d,s,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,n))
+#define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strlcat((d),(s),NCURSES_CAST(size_t,m))
+#else
+#define _nc_STRCAT(d,s,n) NCURSES_VOID strcat((d),(s))
+#define _nc_STRNCAT(d,s,m,n) NCURSES_VOID strncat((d),(s),(n))
+#endif
+
+#if USE_STRING_HACKS && HAVE_STRLCPY
+#define _nc_STRCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
+#define _nc_STRNCPY(d,s,n) NCURSES_VOID strlcpy((d),(s),NCURSES_CAST(size_t,n))
+#else
+#define _nc_STRCPY(d,s,n) NCURSES_VOID strcpy((d),(s))
+#define _nc_STRNCPY(d,s,n) NCURSES_VOID strncpy((d),(s),(n))
+#endif
+
+#if USE_STRING_HACKS && HAVE_SNPRINTF
+#define _nc_SPRINTF NCURSES_VOID snprintf
+#define _nc_SLIMIT(n) NCURSES_CAST(size_t,n),
+#else
+#define _nc_SPRINTF NCURSES_VOID sprintf
+#define _nc_SLIMIT(n) /* nothing */
+#endif
+
+/*
+ * X/Open Curses does not define the arrays of terminfo/termcap names as SVr4
+ * curses did, and some implementations provide them anyway, but undeclared.
+ */
+#ifdef DECL_CURSES_DATA_BOOLNAMES
+extern char *boolnames[], *boolcodes[], *boolfnames[];
+extern char *numnames[], *numcodes[], *numfnames[];
+extern char *strnames[], *strcodes[], *strfnames[];
+#endif
+
+/*
+ * Again, an SVr4 curses feature latent in the libraries but not in headers.
+ */
+#ifndef DECL_CURSES_DATA_TABSIZE
+#define DECL_CURSES_DATA_TABSIZE 0
+#endif
+
+#if DECL_CURSES_DATA_TABSIZE
+extern int TABSIZE;
+#undef HAVE_CURSES_DATA_TABSIZE
+#define HAVE_CURSES_DATA_TABSIZE 1
+#endif
+
+#ifndef HAVE_CURSES_DATA_TABSIZE
+#define HAVE_CURSES_DATA_TABSIZE 0
+#endif
+
+/*
+ * X/Open Curses provides termname(), whose return value is analogous to the
+ * SVr4 curses variable ttytype[].
+ */
+#ifndef HAVE_CURSES_DATA_TTYTYPE
+#define HAVE_CURSES_DATA_TTYTYPE 0
+#endif
+
+#ifndef DECL_CURSES_DATA_TTYTYPE
+#define DECL_CURSES_DATA_TTYTYPE 0
+#endif
+
+#if !defined(ttytype) && (!HAVE_CURSES_DATA_TTYTYPE || DECL_CURSES_DATA_TTYTYPE)
+#define ttytype termname()
+#endif
+
+#define colored_chtype(ch, attr, pair) \
+ ((chtype) (ch) | (chtype) (attr) | (chtype) COLOR_PAIR(pair))
+
+/*
+ * Workaround for HPUX
+ */
+#if defined(__hpux) && !defined(NCURSES_VERSION)
+#define getbegx(w) __getbegx(w)
+#define getbegy(w) __getbegy(w)
+#define getcurx(w) __getcurx(w)
+#define getcury(w) __getcury(w)
+#define getmaxx(w) __getmaxx(w)
+#define getmaxy(w) __getmaxy(w)
+#define getparx(w) __getparx(w)
+#define getpary(w) __getpary(w)
+#endif
+
+/*
+ * Workaround in case getcchar() returns a positive value when the source
+ * string produces only a L'\0'.
+ */
+#define TEST_CCHAR(s, count, then_stmt, else_stmt) \
+ if ((count = getcchar(s, NULL, NULL, NULL, NULL)) > 0) { \
+ wchar_t test_wch[CCHARW_MAX + 2]; \
+ attr_t test_attrs; \
+ NCURSES_PAIRS_T test_pair; \
+ \
+ if (getcchar( s, test_wch, &test_attrs, &test_pair, NULL) == OK \
+ && test_wch[0] != L'\0') { \
+ then_stmt \
+ } else { \
+ else_stmt \
+ } \
+ } else { \
+ else_stmt \
+ }
+/*
+ * These usually are implemented as macros, but may be functions.
+ */
+#if !defined(getcurx) && !HAVE_GETCURX
+#define getcurx(win) ((win) ? ((int)(win)->_curx) : ERR)
+#define getcury(win) ((win) ? ((int)(win)->_cury) : ERR)
+#endif
+
+#if !defined(getbegx) && !HAVE_GETBEGX
+#define getbegx(win) ((win) ? ((int)(win)->_begx) : ERR)
+#define getbegy(win) ((win) ? ((int)(win)->_begy) : ERR)
+#endif
+
+#if !defined(getmaxx) && !HAVE_GETMAXX
+#define getmaxx(win) ((win) ? ((int)(win)->_maxx + 1) : ERR)
+#define getmaxy(win) ((win) ? ((int)(win)->_maxy + 1) : ERR)
+#endif
+
+/*
+ * Solaris 10 xpg4:
+#define __m_getparx(w) ((w)->_parent == (WINDOW *) 0 ? -1 \
+ : (w)->_begx - (w)->_parent->_begx)
+ */
+#if !defined(getparx) && !HAVE_GETPARX
+#ifdef __m_getparx
+#define getparx(win) __m_getparx(win)
+#define getpary(win) __m_getpary(win)
+#else
+#define getparx(win) ((win)?((win)->_parx + 1):ERR)
+#define getpary(win) ((win)?((win)->_pary + 1):ERR)
+#endif
+#endif
+
+#if !defined(mvwvline) && !HAVE_MVWVLINE
+#define mvwvline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : wvline(w,ch,n))
+#define mvwhline(w,y,x,ch,n) (move(y,x) == ERR ? ERR : whline(w,ch,n))
+#endif
+
+#if !defined(mvvline) && !HAVE_MVVLINE
+#define mvvline(y,x,ch,n) (move(y,x) == ERR ? ERR : vline(ch,n))
+#define mvhline(y,x,ch,n) (move(y,x) == ERR ? ERR : hline(ch,n))
+#endif
+
+/*
+ * Try to accommodate curses implementations that have no terminfo support.
+ */
+#if HAVE_TIGETNUM
+#define TIGETNUM(ti,tc) tigetnum(ti)
+#else
+#define TIGETNUM(ti,tc) tgetnum(tc)