]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/curses.priv.h
ncurses 6.2 - patch 20200907
[ncurses.git] / ncurses / curses.priv.h
index 4807761c7e55d4a120f62c54bb176d7cee73160f..0fea513c6538dc8da494fcf3ab462d9daff2675a 100644 (file)
@@ -1,5 +1,6 @@
 /****************************************************************************
- * Copyright (c) 1998-2018,2019 Free Software Foundation, Inc.              *
+ * Copyright 2018-2019,2020 Thomas E. Dickey                                *
+ * Copyright 1998-2017,2018 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 +35,7 @@
  ****************************************************************************/
 
 /*
- * $Id: curses.priv.h,v 1.616 2019/02/23 17:54:39 tom Exp $
+ * $Id: curses.priv.h,v 1.637 2020/09/07 14:27:13 tom Exp $
  *
  *     curses.priv.h
  *
@@ -71,10 +72,6 @@ extern "C" {
 #include <unistd.h>
 #endif
 
-#if HAVE_SYS_BSDTYPES_H && !(defined(_WIN32) || defined(_WIN64))
-#include <sys/bsdtypes.h>      /* needed for ISC */
-#endif
-
 #if HAVE_LIMITS_H
 # include <limits.h>
 #elif HAVE_SYS_PARAM_H
@@ -106,6 +103,24 @@ extern "C" {
 extern int errno;
 #endif
 
+/* Some Windows related defines */
+#undef _NC_WINDOWS
+#if (defined(_WIN32) || defined(_WIN64))
+#define _NC_WINDOWS
+#else
+#undef EXP_WIN32_DRIVER
+#endif
+
+#undef _NC_MINGW
+#if (defined(__MINGW32__) || defined(__MINGW64__))
+#define _NC_MINGW
+#endif
+
+#undef _NC_MSC
+#ifdef _MSC_VER
+#define _NC_MSC
+#endif
+
 /* Some systems have a broken 'select()', but workable 'poll()'.  Use that */
 #if HAVE_WORKING_POLL
 #define USE_FUNC_POLL 1
@@ -184,7 +199,7 @@ extern int errno;
  * the path separator in configure doesn't work properly. So, if building
  * for MinGW, we enforce the correct Windows PATH separator
  */
-#ifdef _WIN32
+#if defined(_NC_WINDOWS)
 #  ifdef NCURSES_PATHSEP
 #    undef NCURSES_PATHSEP
 #  endif
@@ -239,6 +254,18 @@ extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t);
 #define S_ISREG(mode) ((mode & S_IFMT) == S_IFREG)
 #endif
 
+/*
+ * POSIX ignores the "b", which c89 specified.  Some very old systems do not
+ * accept it.
+ */
+#if USE_FOPEN_BIN_R
+#define BIN_R  "rb"
+#define BIN_W  "wb"
+#else
+#define BIN_R  "r"
+#define BIN_W  "w"
+#endif
+
 /*
  * Scroll hints are useless when hashmap is used
  */
@@ -262,11 +289,20 @@ extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t);
  * Options for terminal drivers, etc...
  */
 #ifdef USE_TERM_DRIVER
+#define NO_TERMINAL "unknown"
 #define USE_SP_RIPOFF     1
 #define USE_SP_TERMTYPE   1
 #define USE_SP_WINDOWLIST 1
+#else
+#define NO_TERMINAL 0
 #endif
 
+#define VALID_TERM_ENV(term_env, no_terminal) \
+       (term_env = (NonEmpty(term_env) \
+                    ? term_env \
+                    : no_terminal), \
+        NonEmpty(term_env))
+
 /*
  * Note:  ht/cbt expansion flakes out randomly under Linux 1.1.47, but only
  * when we're throwing control codes at the screen at high volume.  To see
@@ -324,6 +360,10 @@ typedef TRIES {
 
 #include <curses.h>    /* we'll use -Ipath directive to get the right one! */
 
+#if !(defined(NCURSES_WGETCH_EVENTS) && defined(NEED_KEY_EVENT))
+#undef KEY_EVENT               /* reduce compiler-warnings with Visual C++ */
+#endif
+
 typedef struct
 {
     int red, green, blue;      /* what color_content() returns */
@@ -470,7 +510,14 @@ typedef union {
 #define SET_WINDOW_PAIR(w,p)   (w)->_color = (p)
 #define SameAttrOf(a,b)                (AttrOf(a) == AttrOf(b) && GetPair(a) == GetPair(b))
 
-#define VIDATTR(sp,attr,pair)  NCURSES_SP_NAME(vid_puts)(NCURSES_SP_ARGx attr, (NCURSES_PAIRS_T) pair, 0, NCURSES_OUTC_FUNC)
+#define VIDPUTS(sp,attr,pair)  do { \
+                                   int vid_pair = pair; \
+                                   NCURSES_SP_NAME(vid_puts)( \
+                                       NCURSES_SP_ARGx attr, \
+                                       (NCURSES_PAIRS_T) pair, \
+                                       &vid_pair, \
+                                       NCURSES_OUTC_FUNC); \
+                               } while (0)
 
 #else /* !NCURSES_EXT_COLORS */
 
@@ -483,7 +530,7 @@ typedef union {
                                WINDOW_ATTRS(w) |= ColorPair(p)
 #define SameAttrOf(a,b)                (AttrOf(a) == AttrOf(b))
 
-#define VIDATTR(sp,attr,pair)  NCURSES_SP_NAME(vidputs)(NCURSES_SP_ARGx attr, NCURSES_OUTC_FUNC)
+#define VIDPUTS(sp,attr,pair)  NCURSES_SP_NAME(vidputs)(NCURSES_SP_ARGx attr, NCURSES_OUTC_FUNC)
 
 #endif /* NCURSES_EXT_COLORS */
 
@@ -933,6 +980,11 @@ typedef struct {
        time_t          dbd_time;       /* cache last updated */
        ITERATOR_VARS   dbd_vars[dbdLAST];
 
+#if HAVE_TSEARCH
+       void            *cached_tparm;
+       int             count_tparm;
+#endif /* HAVE_TSEARCH */
+
 #ifdef USE_TERM_DRIVER
        int             (*term_driver)(struct DriverTCB*, const char*, int*);
 #endif
@@ -1314,7 +1366,7 @@ struct screen {
        int             _sysmouse_new_buttons;
 #endif
 
-#ifdef USE_TERM_DRIVER
+#if defined(USE_TERM_DRIVER) || defined(EXP_WIN32_DRIVER)
        MEVENT          _drv_mouse_fifo[FIFO_SIZE];
        int             _drv_mouse_head;
        int             _drv_mouse_tail;
@@ -1747,12 +1799,16 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 #define TPUTS_TRACE(s) _nc_tputs_trace = s;
 #endif
 
+#ifdef HAVE_CONSISTENT_GETENV
 #define START_TRACE() \
        if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \
            int t = _nc_getenv_num("NCURSES_TRACE"); \
            if (t >= 0) \
-               trace((unsigned) t); \
+               curses_trace((unsigned) t); \
        }
+#else
+#define START_TRACE() /* nothing */
+#endif
 
 /*
  * Many of the _tracef() calls use static buffers; lock the trace state before
@@ -1939,7 +1995,7 @@ extern    NCURSES_EXPORT(void) name (void); \
 #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)); \
+                               VIDPUTS(sp, AttrOf(c), GetPair(c)); \
                                if (magic_cookie_glitch > 0 \
                                 && XMC_CHANGES((chg ^ AttrOf(SCREEN_ATTRS(sp))))) { \
                                        T(("%s @%d before glitch %d,%d", \
@@ -1951,7 +2007,7 @@ extern    NCURSES_EXPORT(void) name (void); \
                        }
 #else
 #define UpdateAttrs(sp,c) if (!SameAttrOf(SCREEN_ATTRS(sp), c)) { \
-                                   VIDATTR(sp, AttrOf(c), GetPair(c)); \
+                                   VIDPUTS(sp, AttrOf(c), GetPair(c)); \
                        }
 #endif
 
@@ -2026,6 +2082,12 @@ extern NCURSES_EXPORT(void) _nc_expanded (void);
            ttytype[NAMESIZE - 1] = '\0'; \
        }
 
+#if !NCURSES_WCWIDTH_GRAPHICS
+extern NCURSES_EXPORT(int) _nc_wacs_width(unsigned);
+#else
+#define _nc_wacs_width(ch) wcwidth(ch)
+#endif
+
 /* charable.c */
 #if USE_WIDEC_SUPPORT
 extern NCURSES_EXPORT(bool) _nc_is_charable(wchar_t);
@@ -2048,6 +2110,16 @@ typedef struct
        short   source;
 } alias_table_data;
 
+/* comp_userdefs.c */
+typedef struct {
+       short   ute_name;       /* offset of name to hash on */
+       unsigned ute_type;      /* mask (BOOLEAN, NUMBER, STRING) */
+       unsigned ute_argc;      /* number of parameters */
+       unsigned ute_args;      /* bit-mask for string parameters */
+       short   ute_index;      /* index of associated variable in its array */
+       short   ute_link;       /* index in table of next hash, or -1 */
+} user_table_data;
+
 /* doupdate.c */
 #if USE_XMC_SUPPORT
 extern NCURSES_EXPORT(void) _nc_do_xmc_glitch (attr_t);
@@ -2131,26 +2203,24 @@ extern NCURSES_EXPORT(void)   _nc_forget_prescr(void);
 extern NCURSES_EXPORT(int)    _nc_ripoffline(int, int(*)(WINDOW*, int));
 
 /* lib_setup.c */
-#if NO_LEAKS
-#define ExitTerminfo(code)    _nc_free_tinfo(code)
-#else
-#define ExitTerminfo(code)    exit(code)
-#endif
+#define ExitTerminfo(code)    exit_terminfo(code)
 
 #define SETUP_FAIL ERR
 
-#define ret_error(code, fmt, arg)      if (errret) {\
-                                           *errret = code;\
+#define ret_error(rc, fmt, p, q)       if (errret) {\
+                                           *errret = rc;\
+                                           q;\
                                            returnCode(SETUP_FAIL);\
                                        } else {\
-                                           fprintf(stderr, fmt, arg);\
+                                           fprintf(stderr, fmt, p);\
+                                           q;\
                                            ExitTerminfo(EXIT_FAILURE);\
                                        }
 
-#define ret_error1(code, fmt, arg)     ret_error(code, "'%s': " fmt, arg)
+#define ret_error1(rc, fmt, p, q)      ret_error(rc, "'%s': " fmt, p, q)
 
-#define ret_error0(code, msg)          if (errret) {\
-                                           *errret = code;\
+#define ret_error0(rc, msg)            if (errret) {\
+                                           *errret = rc;\
                                            returnCode(SETUP_FAIL);\
                                        } else {\
                                            fprintf(stderr, msg);\
@@ -2223,7 +2293,6 @@ extern NCURSES_EXPORT(int) _nc_timed_wait (SCREEN *, int, int, int * EVENTLIST_2
 extern NCURSES_EXPORT(void) _nc_init_termtype (TERMTYPE2 *const);
 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 *, TERMTYPE2 *);
 extern NCURSES_EXPORT(void) _nc_freeall (void);
 extern NCURSES_EXPORT(void) _nc_hash_map (void);
@@ -2262,6 +2331,7 @@ 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_comp_userdefs_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);
@@ -2305,11 +2375,10 @@ extern NCURSES_EXPORT(int) _nc_eventlist_timeout(_nc_eventlist *);
  */
 #if USE_WIDEC_SUPPORT
 
-#if defined(_WIN32)
+#if defined(_NC_WINDOWS) && !defined(_NC_MSC)
 /*
  * 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)
@@ -2320,7 +2389,7 @@ extern int __MINGW_NOTHROW _nc_mbtowc(wchar_t *, const char *, size_t);
 extern int __MINGW_NOTHROW _nc_mblen(const char *, size_t);
 #define mblen(s,n) _nc_mblen(s, n)
 
-#endif /* _WIN32 */
+#endif /* _NC_WINDOWS && !_NC_MSC */
 
 #if HAVE_MBTOWC && HAVE_MBLEN
 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, (size_t) 0)), IGNORE_RC(mbtowc(NULL, NULL, (size_t) 0))
@@ -2542,6 +2611,10 @@ extern NCURSES_EXPORT(int)      TINFO_MVCUR(SCREEN*, int, int, int, int);
 #define TINFO_MVCUR             NCURSES_SP_NAME(_nc_mvcur)
 #endif
 
+#if defined(EXP_WIN32_DRIVER)
+#include <nc_win32.h>
+#endif
+
 /*
  * Entrypoints using an extra parameter with the terminal driver.
  */
@@ -2564,6 +2637,9 @@ extern NCURSES_EXPORT(void)   _nc_get_screensize(SCREEN *, int *, int *);
        _nc_setupterm(name, fd, err, reuse)
 #endif /* !USE_TERM_DRIVER */
 
+#ifdef EXP_WIN32_DRIVER
+extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_TINFO_DRIVER;
+#else
 #ifdef USE_TERM_DRIVER
 #if defined(USE_WIN32CON_DRIVER)
 #include <nc_mingw.h>
@@ -2581,9 +2657,12 @@ extern NCURSES_EXPORT(int) _nc_mingw_testmouse(
 #else
 #endif
 extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_TINFO_DRIVER;
-#endif
+#endif /* USE_TERM_DRIVER */
+#endif /* EXP_WIN32_DRIVER */
 
-#if defined(USE_TERM_DRIVER) && defined(USE_WIN32CON_DRIVER)
+#if defined(USE_TERM_DRIVER) && defined(EXP_WIN32_DRIVER)
+#define NC_ISATTY(fd) (0 != _nc_console_isatty(fd))
+#elif defined(USE_TERM_DRIVER) && defined(USE_WIN32CON_DRIVER)
 #define NC_ISATTY(fd) _nc_mingw_isatty(fd)
 #else
 #define NC_ISATTY(fd) isatty(fd)
@@ -2592,15 +2671,21 @@ extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_TINFO_DRIVER;
 #ifdef USE_TERM_DRIVER
 #  define IsTermInfo(sp)       ((TCBOf(sp) != 0) && ((TCBOf(sp)->drv->isTerminfo)))
 #  define HasTInfoTerminal(sp) ((0 != TerminalOf(sp)) && IsTermInfo(sp))
-#  if defined(USE_WIN32CON_DRIVER)
+#  if defined(EXP_WIN32_DRIVER)
+#    define IsTermInfoOnConsole(sp) (IsTermInfo(sp)&&_nc_console_test(TerminalOf(sp)->Filedes))
+#  elif defined(USE_WIN32CON_DRIVER)
 #    define IsTermInfoOnConsole(sp) (IsTermInfo(sp)&&_nc_mingw_isconsole(TerminalOf(sp)->Filedes))
-#else
+#  else
 #    define IsTermInfoOnConsole(sp) FALSE
 #  endif
 #else
 #  define IsTermInfo(sp)       TRUE
 #  define HasTInfoTerminal(sp) (0 != TerminalOf(sp))
-#  define IsTermInfoOnConsole(sp) FALSE
+#  if defined(EXP_WIN32_DRIVER)
+#    define IsTermInfoOnConsole(sp) _nc_console_test(TerminalOf(sp)->Filedes)
+#  else
+#    define IsTermInfoOnConsole(sp) FALSE
+#  endif
 #endif
 
 #define IsValidTIScreen(sp)  (HasTInfoTerminal(sp))