X-Git-Url: https://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=ncurses%2Fcurses.priv.h;h=60199f909b15f87f12b57978547e54e56b078a36;hb=HEAD;hp=294ec594c8e2edf474b78db6b6b52fe36a32b570;hpb=6fd6dd99d32385a01ca639d1d56b90b13e9c1d33;p=ncurses.git diff --git a/ncurses/curses.priv.h b/ncurses/curses.priv.h index 294ec594..6d0dbcdf 100644 --- a/ncurses/curses.priv.h +++ b/ncurses/curses.priv.h @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2022,2023 Thomas E. Dickey * + * Copyright 2018-2023,2024 Thomas E. Dickey * * Copyright 1998-2017,2018 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -35,7 +35,7 @@ ****************************************************************************/ /* - * $Id: curses.priv.h,v 1.664 2023/04/29 19:10:30 tom Exp $ + * $Id: curses.priv.h,v 1.689 2024/05/11 19:05:45 tom Exp $ * * curses.priv.h * @@ -72,12 +72,6 @@ extern "C" { #include #endif -#if HAVE_LIMITS_H -# include -#elif HAVE_SYS_PARAM_H -# include -#endif - #include #include @@ -89,16 +83,6 @@ extern "C" { # endif #endif -#ifndef PATH_MAX -# if defined(_POSIX_PATH_MAX) -# define PATH_MAX _POSIX_PATH_MAX -# elif defined(MAXPATHLEN) -# define PATH_MAX MAXPATHLEN -# else -# define PATH_MAX 255 /* the Posix minimum path-size */ -# endif -#endif - #if DECL_ERRNO extern int errno; #endif @@ -141,8 +125,18 @@ extern int errno; # 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" +# undef CASTxPTR +# define CASTxPTR(n) (long)(void*)(n) #endif /* include signal.h before curses.h to work-around defect in glibc 2.1.3 */ @@ -303,7 +297,6 @@ extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t); #define NO_TERMINAL "unknown" #define USE_SP_RIPOFF 1 #define USE_SP_TERMTYPE 1 -#define USE_SP_WINDOWLIST 1 #else #define NO_TERMINAL 0 #endif @@ -314,6 +307,12 @@ extern NCURSES_EXPORT(void *) _nc_memmove (void *, const void *, size_t); : no_terminal), \ NonEmpty(term_env)) +/* + * Originally a terminal-driver option, the window-list is per-screen to allow + * freeing memory used for windows when a screen is deleted. + */ +#define USE_SP_WINDOWLIST 1 + /* * Note: ht/cbt expansion flakes out randomly under Linux 1.1.47, but only * when we're throwing control codes at the screen at high volume. To see @@ -336,6 +335,11 @@ typedef TRIES { */ #define StringOf(ch) {ch, 0} +#define CSI_CHR 0x9b +#define ESC_CHR 0x1b + +#define L_BLOCK '[' +#define R_BLOCK ']' #define L_BRACE '{' #define R_BRACE '}' #define S_QUOTE '\'' @@ -565,10 +569,10 @@ extern NCURSES_EXPORT(void) _nc_set_no_padding(SCREEN *); #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 @@ -866,6 +870,18 @@ typedef int (*TYPE_Gpm_GetEvent) (Gpm_Event *); #endif /* HAVE_LIBDL */ #endif /* USE_GPM_SUPPORT */ +/* + * Limit delay-times to 30 seconds, which is consistent with signed 16-bit + * numbers in legacy terminfo. + */ +#define MAX_DELAY_MSECS 30000 + +/* + * Limit screen dimensions read from environment variables. + */ +#define MAX_ENV_LINES 512 +#define MAX_ENV_COLUMNS 512 + /* * When converting from terminfo to termcap, check for cases where we can trim * octal escapes down to 2-character form. It is useful for terminfo format @@ -896,6 +912,7 @@ typedef int (*TYPE_Gpm_GetEvent) (Gpm_Event *); * string is less than 80 columns, but this buffer size is an absolute * limit. */ +#define TRACECHR_BUF 40 #define TRACEMSE_MAX (80 + (5 * 10) + (32 * 15)) #define TRACEMSE_FMT "id %2d at (%2d, %2d, %2d) state %4lx = {" /* } */ @@ -931,7 +948,8 @@ extern NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals; extern NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen; typedef enum { - ewInitial = 0, + ewUnknown = 0, + ewInitial, ewRunning, ewSuspend } ENDWIN; @@ -1225,7 +1243,7 @@ typedef struct screen { #endif #ifdef TRACE - char tracechr_buf[40]; + char tracechr_buf[TRACECHR_BUF]; char tracemse_buf[TRACEMSE_MAX]; #if USE_REENTRANT long _outchars; @@ -1283,12 +1301,12 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch; /* Checks for isprint() should be done on 8-bit characters (non-wide) */ #define is8bits(c) ((unsigned)(c) <= UCHAR_MAX) -#ifndef min -#define min(a,b) ((a) > (b) ? (b) : (a)) +#ifndef Min +#define Min(a,b) ((a) > (b) ? (b) : (a)) #endif -#ifndef max -#define max(a,b) ((a) < (b) ? (b) : (a)) +#ifndef Max +#define Max(a,b) ((a) < (b) ? (b) : (a)) #endif /* usually in */ @@ -1352,11 +1370,8 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch; #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 - #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)) @@ -1367,7 +1382,20 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch; #define NulColor /* nothing */ #endif -#define NulChar 0,0,0,0 /* FIXME: see CCHARW_MAX */ +#if CCHARW_MAX > 6 +#define NulChar 0,0,0,0,0 +#elif CCHARW_MAX > 5 +#define NulChar 0,0,0,0 /* ncurses7 */ +#elif CCHARW_MAX > 4 +#define NulChar 0,0,0 /* ncurses6 */ +#elif CCHARW_MAX > 3 +#define NulChar 0,0 +#elif CCHARW_MAX > 2 +#define NulChar 0 +#else +#define NulChar /* nothing */ +#endif + #define CharOf(c) ((c).chars[0]) #define AttrOf(c) ((c).attr) @@ -1378,16 +1406,12 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch; #define NewChar2(c,a) { a, { c, NulChar } NulColor } #define NewChar(ch) NewChar2(ChCharOf(ch), ChAttrOf(ch)) -#if CCHARW_MAX == 5 +#if CCHARW_MAX > 1 #define CharEq(a,b) (((a).attr == (b).attr) \ - && (a).chars[0] == (b).chars[0] \ - && (a).chars[1] == (b).chars[1] \ - && (a).chars[2] == (b).chars[2] \ - && (a).chars[3] == (b).chars[3] \ - && (a).chars[4] == (b).chars[4] \ + && !memcmp((a).chars, \ + (b).chars, \ + CCHARW_MAX * sizeof((b).chars[0])) \ if_EXT_COLORS(&& (a).ext_color == (b).ext_color)) -#elif CCHARW_MAX > 0 -#error Inconsistent values for CCHARW_MAX #else #define CharEq(a,b) (!memcmp(&(a), &(b), sizeof(a))) #endif @@ -1488,7 +1512,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 Charable(ch) (CharOf(ch) >= ' ' && CharOf(ch) <= '~') #define L(ch) ch #endif /* } */ @@ -1530,6 +1554,9 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch; #define SIZEOF(v) (sizeof(v)/sizeof(v[0])) +#include +#include + #define FreeIfNeeded(p) if ((p) != 0) free(p) /* FreeAndNull() is not a comma-separated expression because some compilers @@ -1537,8 +1564,18 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch; */ #define FreeAndNull(p) do { free(p); p = 0; } while (0) -#include -#include +#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 @@ -1958,7 +1995,7 @@ 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 */ @@ -2071,7 +2108,7 @@ typedef struct { /* 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 *); @@ -2112,7 +2149,7 @@ extern NCURSES_EXPORT(int) _nc_read_termcap_entry (const char *const, TERMTYPE2 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 *, char *); +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); @@ -2137,7 +2174,7 @@ extern NCURSES_EXPORT(const TERMTYPE2 *) _nc_fallback2 (const char *); #define _nc_fallback2(tp) _nc_fallback(tp) #endif -NCURSES_EXPORT(void) _nc_copy_termtype(TERMTYPE *, const TERMTYPE *); +extern NCURSES_EXPORT(void) _nc_copy_termtype(TERMTYPE *, const TERMTYPE *); #if NCURSES_EXT_NUMBERS extern NCURSES_EXPORT(void) _nc_copy_termtype2 (TERMTYPE2 *, const TERMTYPE2 *); @@ -2161,7 +2198,7 @@ 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); -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 @@ -2219,7 +2256,7 @@ extern int __MINGW_NOTHROW _nc_mblen(const char *, size_t); #if defined(_NC_WINDOWS) || defined(_NC_MINGW) /* see wcwidth.c */ -NCURSES_EXPORT(int) mk_wcwidth(wchar_t); +extern NCURSES_EXPORT(int) mk_wcwidth(uint32_t); #define wcwidth(ucs) _nc_wcwidth(ucs) #endif @@ -2500,6 +2537,14 @@ extern NCURSES_EXPORT_VAR(TERM_DRIVER) _nc_TINFO_DRIVER; #define NC_ISATTY(fd) isatty(fd) #endif +/* + * Perhaps not "real" but possibly not "fake". + */ +#define IsRealTty(fd,value) \ + (NC_ISATTY(fd) \ + && (value = ttyname(fd)) != NULL \ + && strncmp(value, "/dev/pts/", 9)) + #ifdef USE_TERM_DRIVER # define IsTermInfo(sp) ((TCBOf(sp) != 0) && ((TCBOf(sp)->drv->isTerminfo))) # define HasTInfoTerminal(sp) ((0 != TerminalOf(sp)) && IsTermInfo(sp)) @@ -2611,8 +2656,8 @@ 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); +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