]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/curses.priv.h
ncurses 6.1 - patch 20191026
[ncurses.git] / ncurses / curses.priv.h
index fa523e579d878198f6a922d73f6a2d64c5e50887..f619c5c967e5bcb4fed445108e1165febd737066 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2017,2018 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2018,2019 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.602 2018/06/23 21:35:06 tom Exp $
+ * $Id: curses.priv.h,v 1.625 2019/07/28 18:32:05 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
 
@@ -239,6 +239,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
  */
@@ -470,7 +482,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 +502,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 */
 
@@ -539,6 +558,8 @@ NCURSES_EXPORT(int *)        _nc_ptr_Escdelay (SCREEN *);
 
 #endif
 
+#define HasHardTabs()  (NonEmpty(clear_all_tabs) && NonEmpty(set_tab))
+
 #define TR_MUTEX(data) _tracef("%s@%d: me:%08lX COUNT:%2u/%2d/%6d/%2d/%s%9u: " #data, \
            __FILE__, __LINE__, \
            (unsigned long) (pthread_self()), \
@@ -916,6 +937,8 @@ typedef struct {
 
        int             slk_format;
 
+       int             getstr_limit;   /* getstr_limit based on POSIX LINE_MAX */
+
        char            *safeprint_buf;
        size_t          safeprint_used;
 
@@ -1003,6 +1026,15 @@ extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals;
 
 #define N_RIPS 5
 
+/* The limit reserves one byte for a terminating NUL */
+#define my_getstr_limit        (_nc_globals.getstr_limit - 1)
+#define _nc_getstr_limit(n) \
+       (((n) < 0) \
+        ? my_getstr_limit \
+        : (((n) > my_getstr_limit) \
+           ? my_getstr_limit \
+           : (n)))
+
 #ifdef USE_PTHREADS
 typedef struct _prescreen_list {
        struct _prescreen_list *next;
@@ -1533,26 +1565,27 @@ 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)); \
+                           TR_PUTC(CharOf(ch));                                    \
+                           NCURSES_OUTC_FUNC (NCURSES_SP_ARGx CharOf(ch));         \
                            COUNT_OUTCHARS(1);                                      \
                        } else {                                                    \
                            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_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) \
-                                       TR_PUTC(CharOf(ch)); \
+                                   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]); \
+                                       TR_PUTC(PUTC_buf[PUTC_j]);                  \
                                        NCURSES_OUTC_FUNC (NCURSES_SP_ARGx PUTC_buf[PUTC_j]); \
                                    }                                               \
                                }                                                   \
@@ -1612,6 +1645,7 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 #define isWidecExt(ch) (0)
 #define if_WIDEC(code) /* nothing */
 
+#define Charable(ch)   ((ch) >= ' ' && (ch) <= '~')
 #define L(ch)          ch
 #endif /* } */
 
@@ -1697,6 +1731,14 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 # endif
 #endif
 
+#ifdef __TANDEM
+#define ROOT_UID 65535
+#endif
+
+#ifndef ROOT_UID
+#define ROOT_UID 0
+#endif
+
 /*
  * Standardize/simplify common loops
  */
@@ -1713,6 +1755,9 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
 #define T_CREATE(fmt) "create :" fmt
 #define T_RETURN(fmt) "return }" fmt
 
+#define NonNull(s)              ((s) != 0 ? s : "<null>")
+#define NonEmpty(s)             ((s) != 0 && *(s) != '\0')
+
 #ifdef TRACE
 
 #if USE_REENTRANT
@@ -1721,12 +1766,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); \
        }
+#else
+#define START_TRACE() /* nothing */
+#endif
 
 /*
  * Many of the _tracef() calls use static buffers; lock the trace state before
@@ -1750,8 +1799,9 @@ 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 TR_FUNC_LEN            ((sizeof(void *) + sizeof(void (*)(void))) * 2 + 4)
+#define TR_FUNC_BFR(max)       char tr_func_data[max][TR_FUNC_LEN]
+#define TR_FUNC_ARG(num,func)  _nc_fmt_funcptr(&tr_func_data[num][0], (const char *)&(func), sizeof((func)))
 
 #define returnAttr(code)       TRACE_RETURN(code,attr_t)
 #define returnBits(code)       TRACE_RETURN(code,unsigned)
@@ -1790,6 +1840,8 @@ extern NCURSES_EXPORT(unsigned)         _nc_retrace_unsigned (unsigned);
 extern NCURSES_EXPORT(void *)           _nc_retrace_void_ptr (void *);
 extern NCURSES_EXPORT(void)             _nc_fifo_dump (SCREEN *);
 
+extern NCURSES_EXPORT(char *)           _nc_fmt_funcptr(char *, const char *, size_t);
+
 #if USE_REENTRANT
 NCURSES_WRAPPED_VAR(long, _nc_outchars);
 NCURSES_WRAPPED_VAR(const char *, _nc_tputs_trace);
@@ -1823,6 +1875,7 @@ extern NCURSES_EXPORT(const char *) _nc_viscbuf (const NCURSES_CH_T *, int);
 #define T(a)
 #define TR(n, a)
 #define TPUTS_TRACE(s)
+#define TR_FUNC_BFR(max)
 
 #define returnAttr(code)       return code
 #define returnBits(code)       return code
@@ -1909,7 +1962,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", \
@@ -1921,7 +1974,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
 
@@ -1996,6 +2049,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);
@@ -2018,6 +2077,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);
@@ -2047,9 +2116,13 @@ extern NCURSES_EXPORT(int) _nc_init_color(SCREEN *, int, int, int, int);
 extern NCURSES_EXPORT(int) _nc_init_pair(SCREEN *, int, int, int);
 extern NCURSES_EXPORT(int) _nc_pair_content(SCREEN *, int, int *, int *);
 extern NCURSES_EXPORT(bool) _nc_reset_colors(void);
-extern NCURSES_EXPORT(colorpair_t *) _nc_reserve_pairs(SCREEN *, int);
+extern NCURSES_EXPORT(void) _nc_reserve_pairs(SCREEN *, int);
 extern NCURSES_EXPORT(void) _nc_change_pair(SCREEN *, int);
 
+#define ReservePairs(sp,want) \
+           if ((sp->_color_pairs == 0) || (want >= sp->_pair_alloc)) \
+               _nc_reserve_pairs(sp, want)
+
 /* lib_getch.c */
 extern NCURSES_EXPORT(int) _nc_wgetch(WINDOW *, int *, int EVENTLIST_2nd(_nc_eventlist *));
 
@@ -2105,18 +2178,20 @@ extern NCURSES_EXPORT(int)    _nc_ripoffline(int, int(*)(WINDOW*, int));
 
 #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);\
@@ -2228,6 +2303,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);