]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/curses.priv.h
ncurses 6.1 - patch 20180825
[ncurses.git] / ncurses / curses.priv.h
index 7dc49e03a7011cf0145839323830a78c40b749bd..89bc4a709663c1ed26d52c4a04f82f5fb8838b44 100644 (file)
@@ -34,7 +34,7 @@
  ****************************************************************************/
 
 /*
- * $Id: curses.priv.h,v 1.587 2018/01/21 02:13:41 tom Exp $
+ * $Id: curses.priv.h,v 1.604 2018/06/30 21:59:10 tom Exp $
  *
  *     curses.priv.h
  *
@@ -71,7 +71,7 @@ extern "C" {
 #include <unistd.h>
 #endif
 
-#if HAVE_SYS_BSDTYPES_H
+#if HAVE_SYS_BSDTYPES_H && !(defined(_WIN32) || defined(_WIN64))
 #include <sys/bsdtypes.h>      /* needed for ISC */
 #endif
 
@@ -184,7 +184,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 __MINGW32__
+#ifdef _WIN32
 #  ifdef NCURSES_PATHSEP
 #    undef NCURSES_PATHSEP
 #  endif
@@ -598,6 +598,9 @@ weak_symbol(pthread_mutexattr_init);
 extern NCURSES_EXPORT(int) _nc_sigprocmask(int, const sigset_t *, sigset_t *);
 #    undef  sigprocmask
 #    define sigprocmask(a, b, c) _nc_sigprocmask(a, b, c)
+#    define GetThreadID() (((pthread_self)) ? pthread_self() : (pthread_t) getpid())
+#  else
+#    define GetThreadID() pthread_self()
 #  endif
 #endif
 
@@ -676,11 +679,6 @@ extern NCURSES_EXPORT(int) _nc_sigprocmask(int, const sigset_t *, sigset_t *);
 
 #include <new_pair.h>
 
-/*
- * As an extension, support color values and color pairs past 2^16.
- */
-#define USE_EXTENDED_COLORS    USE_NEW_PAIR
-
 #define isDefaultColor(c)      ((c) < 0)
 #define COLOR_DEFAULT          -1
 
@@ -832,9 +830,6 @@ typedef struct {
 #define NUM_VARS 26
 
 typedef struct {
-#ifdef TRACE
-       const char      *tname;
-#endif
        const char      *tparam_base;
 
        STACK_FRAME     stack[STACKSIZE];
@@ -849,6 +844,9 @@ typedef struct {
 
        int             dynamic_var[NUM_VARS];
        int             static_vars[NUM_VARS];
+#ifdef TRACE
+       const char      *tname;
+#endif
 } TPARM_STATE;
 
 typedef struct {
@@ -931,6 +929,10 @@ typedef struct {
        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
@@ -945,8 +947,22 @@ typedef struct {
        int             safeprint_rows;
 #endif
 
-#ifdef USE_TERM_DRIVER
-       int             (*term_driver)(struct DriverTCB*, const char*, int*);
+#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
@@ -977,27 +993,10 @@ typedef struct {
        int             nested_tracef;
 #endif
 #endif /* TRACE */
+
 #if NO_LEAKS
        bool            leak_checking;
 #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
-#endif
-#if USE_PTHREADS_EINTR
-       pthread_t       read_thread;            /* The reading thread */
-#endif
-#if USE_WIDEC_SUPPORT
-       char            key_name[MB_LEN_MAX + 1];
-#endif
 } NCURSES_GLOBALS;
 
 extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals;
@@ -1025,16 +1024,17 @@ typedef struct {
        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
-       TPARM_STATE     tparm_state;
-       TTY             *saved_tty;     /* savetty/resetty information      */
 #if NCURSES_NO_PADDING
        bool            _no_padding;    /* flag to set if padding disabled  */
 #endif
-       NCURSES_SP_OUTC _outch;         /* output handler if not putc */
 #if BROKEN_LINKER || USE_REENTRANT
        chtype          *real_acs_map;
        int             _LINES;
@@ -1042,12 +1042,13 @@ typedef struct {
        int             _TABSIZE;
        int             _ESCDELAY;
        TERMINAL        *_cur_term;
+#endif
 #ifdef TRACE
+#if BROKEN_LINKER || USE_REENTRANT
        long            _outchars;
        const char      *_tputs_trace;
 #endif
 #endif
-       bool            use_tioctl;
 } NCURSES_PRESCREEN;
 
 /*
@@ -1129,18 +1130,11 @@ struct screen {
        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 */
-#if NCURSES_NO_PADDING
-       bool            _no_padding;    /* flag to set if padding disabled  */
-#endif
        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)           */
-#if USE_HARD_TABS
-       int             _ht_cost;       /* cost of (tab)                    */
-       int             _cbt_cost;      /* cost of (backtab)                */
-#endif /* USE_HARD_TABS */
        int             _cub1_cost;     /* cost of (cursor_left)            */
        int             _cuf1_cost;     /* cost of (cursor_right)           */
        int             _cud1_cost;     /* cost of (cursor_down)            */
@@ -1181,14 +1175,6 @@ struct screen {
        int             _pair_count;    /* same as COLOR_PAIRS               */
        int             _pair_limit;    /* actual limit of color-pairs       */
        int             _pair_alloc;    /* current table-size 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        */
-       int             _default_bg;    /* assumed default background        */
-       int             _default_pairs; /* count pairs using default color   */
-#endif
        chtype          _ok_attributes; /* valid attributes for terminal     */
        chtype          _xmc_suppress;  /* attributes to suppress if xmc     */
        chtype          _xmc_triggers;  /* attributes to process if xmc      */
@@ -1199,13 +1185,6 @@ 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           */
-#endif
 
        /*
         * These data correspond to the state of the idcok() and idlok()
@@ -1238,6 +1217,60 @@ struct screen {
        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;
@@ -1283,25 +1316,10 @@ struct screen {
        int             (*_ungetch)(SCREEN *, int);
 #endif
 
-       /*
-        * 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 */
-
-       int             _legacy_coding; /* see use_legacy_coding() */
+#ifdef USE_SP_WINDOWLIST
+       WINDOWLIST*     _windowlist;
+#define WindowList(sp)  (sp)->_windowlist
+#endif
 
 #if USE_REENTRANT
        char            _ttytype[NAMESIZE];
@@ -1309,24 +1327,7 @@ struct screen {
        int             _TABSIZE;
        int             _LINES;
        int             _COLS;
-#ifdef TRACE
-       long            _outchars;
-       const char      *_tputs_trace;
-#endif
-#endif
-
-#ifdef TRACE
-       char            tracechr_buf[40];
-       char            tracemse_buf[TRACEMSE_MAX];
-#endif
-#ifdef USE_SP_WINDOWLIST
-       WINDOWLIST*     _windowlist;
-#define WindowList(sp)  (sp)->_windowlist
 #endif
-       NCURSES_OUTC    jump;
-
-       ripoff_t        rippedoff[N_RIPS];
-       ripoff_t        *rsp;
 
 #if NCURSES_SP_FUNCS
        bool            use_tioctl;
@@ -1342,11 +1343,21 @@ struct screen {
        bool            _screen_acs_fix;
        bool            _screen_unicode;
 #endif
-#if NCURSES_EXT_FUNCS && USE_NEW_PAIR
+
+#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;
@@ -1464,6 +1475,8 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 #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
@@ -1520,6 +1533,7 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 #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 {                                                    \
@@ -1532,11 +1546,13 @@ 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) \
+                                       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]); \
                                    }                                               \
                                }                                                   \
@@ -1584,7 +1600,10 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 #define ARG_CH_T       NCURSES_CH_T
 #define CARG_CH_T      NCURSES_CH_T
 #define PUTC_DATA      /* nothing */
-#define PUTC(ch)       NCURSES_OUTC_FUNC (NCURSES_SP_ARGx (int) ch)
+#define PUTC(ch)       { \
+                           TR_PUTC(ch); \
+                           NCURSES_OUTC_FUNC (NCURSES_SP_ARGx (int) ch); \
+                       }
 
 #define BLANK          (' '|A_NORMAL)
 #define ZEROS          ('\0'|A_NORMAL)
@@ -1639,7 +1658,7 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 /* FreeAndNull() is not a comma-separated expression because some compilers
  * do not accept a mixture of void with values.
  */
-#define FreeAndNull(p)   free(p); p = 0
+#define FreeAndNull(p)   do { free(p); p = 0; } while (0)
 
 #include <nc_alloc.h>
 
@@ -1648,14 +1667,18 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
  * 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)
+       do { \
+           name = typeMalloc(type, size); \
+           if (name == 0) \
+               _nc_err_abort(MSG_NO_MEMORY); \
+       } while (0)
 
 #define TYPE_REALLOC(type, size, name) \
-       name = typeRealloc(type, size, name); \
-       if (name == 0) \
-           _nc_err_abort(MSG_NO_MEMORY)
+       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.
@@ -1728,7 +1751,7 @@ extern NCURSES_EXPORT(void)       _nc_locked_tracef (const char *, ...) GCC_PRINTFLIKE
 typedef void VoidFunc(void);
 
 #define TR_FUNC(value)          ((const char*) (value))
-#define NonNull(s)             ((s) != 0 ? s : "<null>")
+#define NonNull(s)              ((s) != 0 ? s : "<null>")
 
 #define returnAttr(code)       TRACE_RETURN(code,attr_t)
 #define returnBits(code)       TRACE_RETURN(code,unsigned)
@@ -2059,7 +2082,7 @@ 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 *, int);
+extern NCURSES_EXPORT(int)    _nc_setupterm(const char *, int, int *, int);
 extern NCURSES_EXPORT(void)   _nc_tinfo_cmdch(TERMINAL *, int);
 
 #ifdef USE_PTHREADS
@@ -2190,11 +2213,9 @@ extern NCURSES_EXPORT(const TERMTYPE2 *) _nc_fallback2 (const char *);
 #if NCURSES_EXT_NUMBERS
 extern NCURSES_EXPORT(void) _nc_copy_termtype2 (TERMTYPE2 *, const TERMTYPE2 *);
 extern NCURSES_EXPORT(void) _nc_export_termtype2(TERMTYPE *, const TERMTYPE2 *);
-extern NCURSES_EXPORT(void) _nc_import_termtype2(TERMTYPE2 *, const TERMTYPE *);
 #else
 #define _nc_copy_termtype2(dst,src) _nc_copy_termtype((dst),(src))
 #define _nc_export_termtype2(dst,src) /* nothing */
-#define _nc_import_termtype2(dst,src) /* nothing */
 #define _nc_free_termtype2(t) _nc_free_termtype(t)
 /* also... */
 #define _nc_read_entry2 _nc_read_entry
@@ -2250,7 +2271,7 @@ extern NCURSES_EXPORT(int) _nc_eventlist_timeout(_nc_eventlist *);
  */
 #if USE_WIDEC_SUPPORT
 
-#if defined(__MINGW32__)
+#if defined(_WIN32)
 /*
  * MinGW has wide-character functions, but they do not work correctly.
  */
@@ -2265,7 +2286,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 /* __MINGW32__ */
+#endif /* _WIN32 */
 
 #if HAVE_MBTOWC && HAVE_MBLEN
 #define reset_mbytes(state) IGNORE_RC(mblen(NULL, (size_t) 0)), IGNORE_RC(mbtowc(NULL, NULL, (size_t) 0))
@@ -2492,7 +2513,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 *, int);
+extern NCURSES_EXPORT(int)    _nc_setupterm_ex(TERMINAL **, 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) \
@@ -2522,7 +2543,7 @@ extern NCURSES_EXPORT(int) _nc_mingw_console_read(
 extern NCURSES_EXPORT(int) _nc_mingw_testmouse(
     SCREEN * sp,
     HANDLE fd,
-    int delay);
+    int delay EVENTLIST_2nd(_nc_eventlist*));
 #else
 #endif
 extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_TINFO_DRIVER;