/****************************************************************************
- * Copyright 2018-2020,2021 Thomas E. Dickey *
+ * Copyright 2018-2022,2023 Thomas E. Dickey *
* Copyright 1998-2017,2018 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
****************************************************************************/
/*
- * $Id: curses.priv.h,v 1.644 2021/08/18 21:55:42 tom Exp $
+ * $Id: curses.priv.h,v 1.672 2023/09/09 23:13:32 tom Exp $
*
* curses.priv.h
*
# endif
#endif
+#if (defined(__USE_MINGW_ANSI_STDIO) && __USE_MINGW_ANSI_STDIO != 0) && (defined(__GNUC__) && (__GNUC__ < 12))
+# undef PRIxPTR /* gcc bug fixed in 12.x */
+# define PRIxPTR "lX"
+# define CASTxPTR(n) (unsigned long)(intptr_t)(void*)(n)
+#else
+# define CASTxPTR(n) (intptr_t)(n)
+#endif
+
+#ifndef PRIxPTR
+# define PRIxPTR "lx"
+# define CASTxPTR(n) (long)(void*)(n)
+#endif
+
/* include signal.h before curses.h to work-around defect in glibc 2.1.3 */
#include <signal.h>
# define NCURSES_PATHSEP ';'
#endif
+/*
+ * When the standard handles have been redirected (such as inside a text editor
+ * or the less utility), keystrokes must be read from the console rather than
+ * the redirected handle. The standard output handle suffers from a similar
+ * problem. Both handles are not closed once opened. The console shall be
+ * considered reachable throughout the process.
+ */
+#if defined(_NC_WINDOWS)
+#define GetDirectHandle(fileName, shareMode) \
+ CreateFile(TEXT(fileName), \
+ GENERIC_READ | GENERIC_WRITE, \
+ shareMode, \
+ 0, \
+ OPEN_EXISTING, \
+ 0, \
+ 0)
+#endif
+
/*
* Not all platforms have memmove; some have an equivalent bcopy. (Some may
* have neither).
#define SET_SCREEN_PAIR(s,p) SetPair(SCREEN_ATTRS(s), p)
#if USE_REENTRANT || NCURSES_SP_FUNCS
-NCURSES_EXPORT(int *) _nc_ptr_Lines (SCREEN *);
-NCURSES_EXPORT(int *) _nc_ptr_Cols (SCREEN *);
-NCURSES_EXPORT(int *) _nc_ptr_Tabsize (SCREEN *);
-NCURSES_EXPORT(int *) _nc_ptr_Escdelay (SCREEN *);
+extern NCURSES_EXPORT(int *) _nc_ptr_Lines (SCREEN *);
+extern NCURSES_EXPORT(int *) _nc_ptr_Cols (SCREEN *);
+extern NCURSES_EXPORT(int *) _nc_ptr_Tabsize (SCREEN *);
+extern NCURSES_EXPORT(int *) _nc_ptr_Escdelay (SCREEN *);
#endif
#if USE_REENTRANT
#endif
+#define IS_SUBWIN(w) ((w)->_flags & _SUBWIN)
+#define IS_PAD(w) ((w)->_flags & _ISPAD)
+#define IS_WRAPPED(w) ((w)->_flags & _WRAPPED)
+
#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, \
#define _nc_lock_global(name) /* nothing */
#define _nc_try_global(name) 0
#define _nc_unlock_global(name) /* nothing */
-
#endif /* USE_PTHREADS */
+#if USE_PTHREADS_EINTR
+extern NCURSES_EXPORT(void) _nc_set_read_thread(bool);
+#else
+#define _nc_set_read_thread(enable) /* nothing */
+#endif
+
/*
* When using sp-funcs, locks are targeted to SCREEN-level granularity.
* So the locking is done in the non-sp-func (which calls the sp-func) rather
#endif
-#if HAVE_GETTIMEOFDAY
+#if HAVE_CLOCK_GETTIME
+# define PRECISE_GETTIME 1
+# define GetClockTime(t) clock_gettime(CLOCK_REALTIME, t)
+# define TimeType struct timespec
+# define TimeScale 1000000000L /* 1e9 */
+# define sub_secs tv_nsec
+#elif HAVE_GETTIMEOFDAY
# define PRECISE_GETTIME 1
+# define GetClockTime(t) gettimeofday(t, 0)
# define TimeType struct timeval
+# define TimeScale 1000000L /* 1e6 */
+# define sub_secs tv_usec
#else
# define PRECISE_GETTIME 0
# define TimeType time_t
ewSuspend
} ENDWIN;
+typedef struct {
+ int _nl; /* True if NL -> CR/NL is on */
+ int _raw; /* True if in raw mode */
+ int _cbreak; /* 1 if in cbreak mode */
+ /* > 1 if in halfdelay mode */
+ int _echo; /* True if echo on */
+} TTY_FLAGS;
+
+#define IsNl(sp) (sp)->_tty_flags._nl
+#define IsRaw(sp) (sp)->_tty_flags._raw
+#define IsCbreak(sp) (sp)->_tty_flags._cbreak
+#define IsEcho(sp) (sp)->_tty_flags._echo
+
/*
* The SCREEN structure.
*/
-
-struct screen {
+typedef struct screen {
int _ifd; /* input file descriptor for screen */
int _ofd; /* output file descriptor for screen */
FILE *_ofp; /* output file ptr for screen */
int _cursrow; /* physical cursor row */
int _curscol; /* physical cursor column */
bool _notty; /* true if we cannot switch non-tty */
- int _nl; /* True if NL -> CR/NL is on */
- int _raw; /* True if in raw mode */
- int _cbreak; /* 1 if in cbreak mode */
- /* > 1 if in halfdelay mode */
- int _echo; /* True if echo on */
+ TTY_FLAGS _tty_flags;
int _use_meta; /* use the meta key? */
struct _SLK *_slk; /* ptr to soft key struct / NULL */
int slk_format; /* selected format for this screen */
const char *_tputs_trace;
#endif
#endif
-};
+#undef SCREEN
+} SCREEN;
extern NCURSES_EXPORT_VAR(SCREEN *) _nc_screen_chain;
extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch;
#endif
#define SP_PRE_INIT(sp) \
- sp->_cursrow = -1; \
- sp->_curscol = -1; \
- sp->_nl = TRUE; \
- sp->_raw = FALSE; \
- sp->_cbreak = 0; \
- sp->_echo = TRUE; \
- sp->_fifohead = -1; \
- sp->_endwin = ewSuspend; \
- sp->_cursor = -1; \
+ sp->_cursrow = -1; \
+ sp->_curscol = -1; \
+ IsNl(sp) = TRUE; \
+ IsRaw(sp) = FALSE; \
+ IsCbreak(sp) = 0; \
+ IsEcho(sp) = TRUE; \
+ sp->_fifohead = -1; \
+ sp->_endwin = ewSuspend; \
+ sp->_cursor = -1; \
SP_INIT_WINDOWLIST(sp); \
- sp->_outch = NCURSES_OUTC_FUNC; \
- sp->jump = 0 \
+ sp->_outch = NCURSES_OUTC_FUNC; \
+ sp->jump = 0 \
/* usually in <limits.h> */
#ifndef UCHAR_MAX
#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 */
+#define MB_LEN_MAX 16 /* should be >= MB_CUR_MAX, but that may be a function */
#endif
#if USE_WIDEC_SUPPORT /* { */
+/* true if the status/errno indicate an illegal multibyte sequence */
#define isEILSEQ(status) (((size_t)status == (size_t)-1) && (errno == EILSEQ))
#define init_mb(state) memset(&(state), 0, sizeof(state))
#define isWidecExt(ch) (0)
#define if_WIDEC(code) /* nothing */
-#define Charable(ch) ((ch) >= ' ' && (ch) <= '~')
+#define Charable(ch) (CharOf(ch) >= ' ' && CharOf(ch) <= '~')
#define L(ch) ch
#endif /* } */
#define SIZEOF(v) (sizeof(v)/sizeof(v[0]))
+#include <nc_alloc.h>
+#include <nc_access.h>
+
#define FreeIfNeeded(p) if ((p) != 0) free(p)
/* FreeAndNull() is not a comma-separated expression because some compilers
*/
#define FreeAndNull(p) do { free(p); p = 0; } while (0)
-#include <nc_alloc.h>
-#include <nc_access.h>
+#ifdef EXP_OOM_TESTING
+extern NCURSES_EXPORT(void *) _nc_oom_malloc(size_t size);
+extern NCURSES_EXPORT(void *) _nc_oom_calloc(size_t nmemb, size_t size);
+extern NCURSES_EXPORT(void *) _nc_oom_realloc(void *ptr, size_t size);
+extern NCURSES_EXPORT(void) _nc_oom_free(void *ptr);
+extern NCURSES_EXPORT(char *) _nc_oom_strdup(const char *ptr);
+#define malloc(size) _nc_oom_malloc(size)
+#define calloc(nmemb, size) _nc_oom_calloc(nmemb, size)
+#define realloc(ptr, size) _nc_oom_realloc(ptr, size)
+#define free(ptr) _nc_oom_free(ptr)
+#define strdup(ptr) _nc_oom_strdup(ptr)
+#endif
/*
* Use these for tic/infocmp malloc failures. Generally the ncurses library
_nc_err_abort(MSG_NO_MEMORY); \
} while (0)
+#define TYPE_CALLOC(type, size, name) \
+ do { \
+ name = typeCalloc(type, size); \
+ if (name == 0) \
+ _nc_err_abort(MSG_NO_MEMORY); \
+ } while (0)
+
#define TYPE_REALLOC(type, size, name) \
do { \
name = typeRealloc(type, size, name); \
#define returnMMask(code) TRACE_RETURN_SP(code,mmask_t)
#define returnPtr(code) TRACE_RETURN1(code,ptr)
#define returnSP(code) TRACE_RETURN1(code,sp)
-#define returnVoid T((T_RETURN(""))); return
+#define returnVoid { T((T_RETURN(""))); return; }
#define returnVoidPtr(code) TRACE_RETURN1(code,void_ptr)
#define returnWin(code) TRACE_RETURN1(code,win)
#define returnDB(rc) do { TR(TRACE_DATABASE,(T_RETURN("code %d"), (rc))); return (rc); } while (0)
+#define returnPtrDB(rc) do { TR(TRACE_DATABASE,(T_RETURN("%p"), (rc))); return (rc); } while (0)
+#define returnVoidDB do { TR(TRACE_DATABASE,(T_RETURN(""))); return; } while (0)
extern NCURSES_EXPORT(NCURSES_BOOL) _nc_retrace_bool (int);
extern NCURSES_EXPORT(NCURSES_CONST void *) _nc_retrace_cvoid_ptr (NCURSES_CONST void *);
#define returnWin(code) return code
#define returnDB(code) return code
+#define returnPtrDB(rc) return rc
+#define returnVoidDB return
#endif /* TRACE/!TRACE */
/* lib_acs.c */
extern NCURSES_EXPORT(void) _nc_init_acs (void); /* corresponds to traditional 'init_acs()' */
-extern NCURSES_EXPORT(int) _nc_msec_cost (const char *const, int); /* used by 'tack' program */
+extern NCURSES_EXPORT(int) _nc_msec_cost (const char *const, int);
/* lib_addch.c */
#if USE_WIDEC_SUPPORT
-NCURSES_EXPORT(int) _nc_build_wch(WINDOW *win, ARG_CH_T ch);
+extern NCURSES_EXPORT(int) _nc_build_wch(WINDOW *win, ARG_CH_T ch);
#endif
/* lib_addstr.c */
/* strings.c */
extern NCURSES_EXPORT(string_desc *) _nc_str_init (string_desc *, char *, size_t);
extern NCURSES_EXPORT(string_desc *) _nc_str_null (string_desc *, size_t);
-extern NCURSES_EXPORT(string_desc *) _nc_str_copy (string_desc *, string_desc *);
+extern NCURSES_EXPORT(string_desc *) _nc_str_copy (string_desc *, const string_desc *);
extern NCURSES_EXPORT(bool) _nc_safe_strcat (string_desc *, const char *);
extern NCURSES_EXPORT(bool) _nc_safe_strcpy (string_desc *, const char *);
extern NCURSES_EXPORT(int) _nc_setup_tinfo(const char *, TERMTYPE2 *);
extern NCURSES_EXPORT(int) _nc_setupscreen (int, int, FILE *, int, int);
extern NCURSES_EXPORT(int) _nc_timed_wait (SCREEN *, int, int, int * EVENTLIST_2nd(_nc_eventlist *));
+extern NCURSES_EXPORT(int) _nc_trans_string (char *, const char *);
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_init_keytry (SCREEN *);
extern NCURSES_EXPORT(void) _nc_keep_tic_dir (const char *);
extern NCURSES_EXPORT(void) _nc_make_oldhash (int i);
+extern NCURSES_EXPORT(void) _nc_reset_input (FILE *, char *);
extern NCURSES_EXPORT(void) _nc_scroll_oldhash (int n, int top, int bot);
extern NCURSES_EXPORT(void) _nc_scroll_optimize (void);
extern NCURSES_EXPORT(void) _nc_set_buffer (FILE *, int);
#define _nc_fallback2(tp) _nc_fallback(tp)
#endif
+extern NCURSES_EXPORT(void) _nc_copy_termtype(TERMTYPE *, const TERMTYPE *);
+
#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_db_iterator_leaks(void);
extern NCURSES_EXPORT(void) _nc_keyname_leaks(void);
extern NCURSES_EXPORT(void) _nc_names_leaks(void);
-extern NCURSES_EXPORT(void) _nc_tgetent_leak(TERMINAL *);
+extern NCURSES_EXPORT(void) _nc_tgetent_leak(const TERMINAL *);
extern NCURSES_EXPORT(void) _nc_tgetent_leaks(void);
#endif
#endif /* _NC_WINDOWS && !_NC_MSC */
+#if defined(_NC_WINDOWS) || defined(_NC_MINGW)
+/* see wcwidth.c */
+extern NCURSES_EXPORT(int) mk_wcwidth(wchar_t);
+#define wcwidth(ucs) _nc_wcwidth(ucs)
+#endif
+
#if HAVE_MBTOWC && HAVE_MBLEN
#define reset_mbytes(state) IGNORE_RC(mblen(NULL, (size_t) 0)), IGNORE_RC(mbtowc(NULL, NULL, (size_t) 0))
#define count_mbytes(buffer,length,state) mblen(buffer,length)
/*
* We don't want to use the lines or columns capabilities internally, because
- * if the application is running multiple screens under X, it's quite possible
+ * if the application is running multiple screens under X, it is quite possible
* they could all have type xterm but have different sizes! So...
*/
#define screen_lines(sp) (sp)->_lines
#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);
+extern NCURSES_EXPORT(int) _nc_conv_to_utf8(unsigned char *, unsigned, unsigned);
+extern NCURSES_EXPORT(int) _nc_conv_to_utf32(unsigned *, const char *, unsigned);
#endif
#ifdef __cplusplus