]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/curses.priv.h
ncurses 6.1 - patch 20190223
[ncurses.git] / ncurses / curses.priv.h
index 0186578d221078132f5ebadb18e72c5a5aa9db0e..4807761c7e55d4a120f62c54bb176d7cee73160f 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.600 2018/04/14 19:28:44 tom Exp $
+ * $Id: curses.priv.h,v 1.616 2019/02/23 17:54:39 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
@@ -539,6 +539,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 +918,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 +1007,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 +1546,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 +1626,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 /* } */
 
@@ -1658,7 +1673,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>
 
@@ -1667,14 +1682,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.
@@ -1693,6 +1712,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
  */
@@ -1709,6 +1736,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
@@ -1746,8 +1776,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)
@@ -1786,6 +1817,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);
@@ -1819,6 +1852,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
@@ -2043,9 +2077,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 *));
 
@@ -2267,7 +2305,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.
  */
@@ -2282,7 +2320,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))