]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/curses.priv.h
ncurses 6.0 - patch 20170318
[ncurses.git] / ncurses / curses.priv.h
index 2c3df406cd2e31c1940236fdb0c9cc9ba152203a..0285c539d6aac8bf9b4edac342bfcd54f3138f40 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2016,2017 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.540 2014/09/27 21:44:28 tom Exp $
+ * $Id: curses.priv.h,v 1.563 2017/03/10 09:21:46 tom Exp $
  *
  *     curses.priv.h
  *
@@ -406,7 +406,7 @@ color_t;
  * option for compiling the tracing into the library.
  */
 #if 1
-#define ColorPair(n)           NCURSES_BITS(n, 0)
+#define ColorPair(n)           (NCURSES_BITS(n, 0) & A_COLOR)
 #define PairNumber(a)          (NCURSES_CAST(int,(((unsigned long)(a) & A_COLOR) >> NCURSES_ATTR_SHIFT)))
 #else
 #define ColorPair(pair)                COLOR_PAIR(pair)
@@ -416,6 +416,9 @@ color_t;
 #define unColor(n)             unColor2(AttrOf(n))
 #define unColor2(a)            ((a) & ALL_BUT_COLOR)
 
+#define XCURSES_PAIR_T         short
+#define MAX_XCURSES_PAIR       (int) ((1U << 15) - 1)
+
 /*
  * Extended-colors stores the color pair in a separate struct-member than the
  * attributes.  But for compatibility, we handle most cases where a program
@@ -426,7 +429,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 & (unsigned) ColorPair(oldColor(c))))
+                               a = (unColor2(a) | 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))
@@ -434,17 +437,17 @@ color_t;
 #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, (short) pair, 0, NCURSES_OUTC_FUNC)
+#define VIDATTR(sp,attr,pair)  NCURSES_SP_NAME(vid_puts)(NCURSES_SP_ARGx attr, (NCURSES_PAIRS_T) pair, 0, NCURSES_OUTC_FUNC)
 
 #else /* !NCURSES_EXT_COLORS */
 
 #define if_EXT_COLORS(stmt)    /* nothing */
 #define SetPair(value,p)       RemAttr(value, A_COLOR), \
-                               SetAttr(value, AttrOf(value) | (A_COLOR & (attr_t) ColorPair(p)))
+                               SetAttr(value, AttrOf(value) | ColorPair(p))
 #define GetPair(value)         PairNumber(AttrOf(value))
 #define GET_WINDOW_PAIR(w)     PairNumber(WINDOW_ATTRS(w))
 #define SET_WINDOW_PAIR(w,p)   WINDOW_ATTRS(w) &= ALL_BUT_COLOR, \
-                               WINDOW_ATTRS(w) |= (A_COLOR & (attr_t) ColorPair(p))
+                               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)
@@ -561,7 +564,7 @@ weak_symbol(pthread_mutexattr_settype);
 weak_symbol(pthread_mutexattr_init);
 extern NCURSES_EXPORT(int) _nc_sigprocmask(int, const sigset_t *, sigset_t *);
 #    undef  sigprocmask
-#    define sigprocmask _nc_sigprocmask
+#    define sigprocmask(a, b, c) _nc_sigprocmask(a, b, c)
 #  endif
 #endif
 
@@ -581,7 +584,7 @@ weak_symbol(pthread_self);
 weak_symbol(pthread_equal);
 extern NCURSES_EXPORT(int) _nc_sigprocmask(int, const sigset_t *, sigset_t *);
 #    undef  sigprocmask
-#    define sigprocmask _nc_sigprocmask
+#    define sigprocmask(a, b, c) _nc_sigprocmask(a, b, c)
 #  endif
 #endif /* USE_PTHREADS_EINTR */
 
@@ -635,15 +638,10 @@ extern NCURSES_EXPORT(int) _nc_sigprocmask(int, const sigset_t *, sigset_t *);
 /*
  * Definitions for color pairs
  */
-typedef unsigned colorpair_t;  /* type big enough to store PAIR_OF() */
-#define C_SHIFT 9              /* we need more bits than there are colors */
-#define C_MASK                 ((1 << C_SHIFT) - 1)
-#define PAIR_OF(fg, bg)                (colorpair_t) ((((fg) & C_MASK) << C_SHIFT) | ((bg) & C_MASK))
-#define FORE_OF(c)             (((c) >> C_SHIFT) & C_MASK)
-#define BACK_OF(c)             ((c) & C_MASK)
-#define isDefaultColor(c)      ((c) >= COLOR_DEFAULT || (c) < 0)
+#include <new_pair.h>
 
-#define COLOR_DEFAULT          C_MASK
+#define isDefaultColor(c)      ((c) < 0)
+#define COLOR_DEFAULT          -1
 
 #if defined(USE_BUILD_CC) || (defined(USE_TERMLIB) && !defined(NEED_NCURSES_CH_T))
 
@@ -676,6 +674,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.
  */
@@ -893,10 +899,11 @@ typedef struct {
 #endif
 
 #ifdef TRACE
-       bool            init_trace;
+       bool            trace_opened;
        char            trace_fname[PATH_MAX];
        int             trace_level;
        FILE            *trace_fp;
+       int             trace_fd;
 
        char            *tracearg_buf;
        size_t          tracearg_used;
@@ -931,6 +938,9 @@ typedef struct {
 #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;
@@ -1091,9 +1101,14 @@ struct screen {
        color_t         *_color_table;  /* screen's color palette            */
        int             _color_count;   /* count of colors in palette        */
        colorpair_t     *_color_pairs;  /* screen's color pair list          */
-       int             _pair_count;    /* count of color pairs              */
+       int             _pair_count;    /* same as COLOR_PAIRS               */
        int             _pair_limit;    /* actual limit of color-pairs       */
 #if NCURSES_EXT_FUNCS
+#if USE_NEW_PAIR
+       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
        bool            _assumed_color; /* use assumed colors                */
        bool            _default_color; /* use default colors                */
        bool            _has_sgr_39_49; /* has ECMA default color support    */
@@ -1145,6 +1160,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 */
@@ -1239,6 +1255,10 @@ struct screen {
        ripoff_t        rippedoff[N_RIPS];
        ripoff_t        *rsp;
 
+#if NCURSES_SP_FUNCS
+       bool            use_tioctl;
+#endif
+
        /*
         * ncurses/ncursesw are the same up to this point.
         */
@@ -1249,8 +1269,6 @@ struct screen {
        bool            _screen_acs_fix;
        bool            _screen_unicode;
 #endif
-
-       bool            _use_tioctl;
 };
 
 extern NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain;
@@ -1419,11 +1437,11 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
                            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) {                                  \
@@ -1616,27 +1634,33 @@ 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)
+
+#define returnDB(code)         do { TR(TRACE_DATABASE,(T_RETURN("code %d"), (code))); return (code); } while (0)
 
 extern NCURSES_EXPORT(NCURSES_BOOL)     _nc_retrace_bool (int);
 extern NCURSES_EXPORT(NCURSES_CONST void *) _nc_retrace_cvoid_ptr (NCURSES_CONST void *);
@@ -1671,6 +1695,10 @@ extern NCURSES_EXPORT_VAR(long)         _nc_outchars;
 
 extern NCURSES_EXPORT_VAR(unsigned)     _nc_tracing;
 
+extern NCURSES_EXPORT(char *) _nc_tracebits (void);
+extern NCURSES_EXPORT(char *) _tracemouse (const MEVENT *);
+extern NCURSES_EXPORT(void) _tracedump (const char *, WINDOW *);
+
 #if USE_WIDEC_SUPPORT
 extern NCURSES_EXPORT(const char *) _nc_viswbuf2 (int, const wchar_t *);
 extern NCURSES_EXPORT(const char *) _nc_viswbufn (const wchar_t *, int);
@@ -1703,6 +1731,8 @@ extern NCURSES_EXPORT(const char *) _nc_viscbuf (const NCURSES_CH_T *, int);
 #define returnVoidPtr(code)    return code
 #define returnWin(code)                return code
 
+#define returnDB(code)         return code
+
 #endif /* TRACE/!TRACE */
 
 /*
@@ -1897,6 +1927,7 @@ extern NCURSES_EXPORT(int) _nc_wchstrlen(const cchar_t *);
 
 /* lib_color.c */
 extern NCURSES_EXPORT(bool) _nc_reset_colors(void);
+extern NCURSES_EXPORT(void) _nc_change_pair(SCREEN *, int);
 
 /* lib_getch.c */
 extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, int *, int EVENTLIST_2nd(_nc_eventlist *));
@@ -1937,9 +1968,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);\
@@ -1949,7 +1981,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);\
@@ -2004,6 +2036,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 *);
@@ -2344,7 +2377,7 @@ 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);
@@ -2362,7 +2395,7 @@ extern NCURSES_EXPORT(int) _nc_mingw_testmouse(
 extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_TINFO_DRIVER;
 #endif
 
-#if defined(USE_TERM_DRIVER) && defined(__MINGW32__)
+#if defined(USE_TERM_DRIVER) && defined(USE_WIN32CON_DRIVER)
 #define NC_ISATTY(fd) _nc_mingw_isatty(fd)
 #else
 #define NC_ISATTY(fd) isatty(fd)
@@ -2371,7 +2404,7 @@ 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))
-#  ifdef __MINGW32__
+#  if defined(USE_WIN32CON_DRIVER)
 #    define IsTermInfoOnConsole(sp) (IsTermInfo(sp)&&_nc_mingw_isconsole(TerminalOf(sp)->Filedes))
 #else
 #    define IsTermInfoOnConsole(sp) FALSE
@@ -2481,6 +2514,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