libncurses: Import https://ftp.gnu.org/pub/gnu/ncurses/ncurses-6.5.tar.gz changes
Change-Id: I3433d30ca01359fd2e3623ede96b531f0b39cbfa
Signed-off-by: micky387 <mickaelsaibi@free.fr>
diff --git a/ncurses/trace/README b/ncurses/trace/README
index e658fec..0a33300 100644
--- a/ncurses/trace/README
+++ b/ncurses/trace/README
@@ -1,5 +1,6 @@
-------------------------------------------------------------------------------
--- Copyright (c) 1998,2006 Free Software Foundation, Inc. --
+-- Copyright 2020 Thomas E. Dickey --
+-- Copyright 1998,2006 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 --
@@ -25,7 +26,7 @@
-- sale, use or other dealings in this Software without prior written --
-- authorization. --
-------------------------------------------------------------------------------
--- $Id: README,v 1.2 2006/04/22 22:19:37 tom Exp $
+-- $Id: README,v 1.3 2020/02/02 23:34:34 tom Exp $
-------------------------------------------------------------------------------
The files in this directory (trace) support both the terminfo and ncurses
diff --git a/ncurses/trace/lib_trace.c b/ncurses/trace/lib_trace.c
index cec01de..0904c13 100644
--- a/ncurses/trace/lib_trace.c
+++ b/ncurses/trace/lib_trace.c
@@ -1,5 +1,6 @@
/****************************************************************************
- * Copyright (c) 1998-2012,2013 Free Software Foundation, Inc. *
+ * Copyright 2018-2023,2024 Thomas E. Dickey *
+ * Copyright 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 *
@@ -36,7 +37,7 @@
/*
* lib_trace.c - Tracing/Debugging routines
*
- * The _tracef() function is originally from pcurses (by Pavel Curtis) in 1982.
+ * The _tracef() function is originally from pcurses (by Pavel Curtis) in 1982.
* pcurses allowed one to enable/disable tracing using traceon() and traceoff()
* functions. ncurses provides a trace() function which allows one to
* selectively enable or disable several tracing features.
@@ -47,7 +48,7 @@
#include <ctype.h>
-MODULE_ID("$Id: lib_trace.c,v 1.82 2013/07/06 19:42:09 tom Exp $")
+MODULE_ID("$Id: lib_trace.c,v 1.106 2024/02/24 18:28:19 tom Exp $")
NCURSES_EXPORT_VAR(unsigned) _nc_tracing = 0; /* always define this */
@@ -85,60 +86,130 @@
NCURSES_EXPORT_VAR(long) _nc_outchars = 0;
#endif
-#define TraceFP _nc_globals.trace_fp
-#define TracePath _nc_globals.trace_fname
-#define TraceLevel _nc_globals.trace_level
+#define MyFP _nc_globals.trace_fp
+#define MyFD _nc_globals.trace_fd
+#define MyInit _nc_globals.trace_opened
+#define MyLevel _nc_globals.trace_level
+#define MyNested _nc_globals.nested_tracef
+#endif /* TRACE */
-NCURSES_EXPORT(void)
-trace(const unsigned int tracelevel)
+#if USE_REENTRANT
+#define Locked(statement) \
+ do { \
+ _nc_lock_global(tst_tracef); \
+ statement; \
+ _nc_unlock_global(tst_tracef); \
+ } while (0)
+#else
+#define Locked(statement) statement
+#endif
+
+NCURSES_EXPORT(unsigned)
+curses_trace(unsigned tracelevel)
{
- if ((TraceFP == 0) && tracelevel) {
- const char *mode = _nc_globals.init_trace ? "ab" : "wb";
+ unsigned result;
- if (TracePath[0] == '\0') {
- size_t size = sizeof(TracePath) - 12;
- if (getcwd(TracePath, size) == 0) {
- perror("curses: Can't get working directory");
- exit(EXIT_FAILURE);
+#if defined(TRACE)
+ int bit;
+
+#define DATA(name) { name, #name }
+ static struct {
+ unsigned mask;
+ const char *name;
+ } trace_names[] = {
+ DATA(TRACE_TIMES),
+ DATA(TRACE_TPUTS),
+ DATA(TRACE_UPDATE),
+ DATA(TRACE_MOVE),
+ DATA(TRACE_CHARPUT),
+ DATA(TRACE_CALLS),
+ DATA(TRACE_VIRTPUT),
+ DATA(TRACE_IEVENT),
+ DATA(TRACE_BITS),
+ DATA(TRACE_ICALLS),
+ DATA(TRACE_CCALLS),
+ DATA(TRACE_DATABASE),
+ DATA(TRACE_ATTRS)
+ };
+#undef DATA
+
+ Locked(result = _nc_tracing);
+
+ if ((MyFP == 0) && tracelevel) {
+ MyInit = TRUE;
+ if (MyFD >= 0) {
+ MyFP = fdopen(MyFD, BIN_W);
+ } else {
+ char myFile[80];
+
+ _nc_STRCPY(myFile, "trace", sizeof(myFile));
+ if (_nc_is_dir_path(myFile)) {
+ _nc_STRCAT(myFile, ".log", sizeof(myFile));
}
- TracePath[size] = '\0';
- assert(strlen(TracePath) <= size);
- _nc_STRCAT(TracePath, "/trace", sizeof(TracePath));
- if (_nc_is_dir_path(TracePath)) {
- _nc_STRCAT(TracePath, ".log", sizeof(TracePath));
+#define SAFE_MODE (O_CREAT | O_EXCL | O_RDWR)
+ if (_nc_access(myFile, W_OK) < 0
+ || (MyFD = safe_open3(myFile, SAFE_MODE, 0600)) < 0
+ || (MyFP = fdopen(MyFD, BIN_W)) == 0) {
+ ; /* EMPTY */
}
}
-
- _nc_globals.init_trace = TRUE;
- _nc_tracing = tracelevel;
- if (_nc_access(TracePath, W_OK) < 0
- || (TraceFP = fopen(TracePath, mode)) == 0) {
- perror("curses: Can't open 'trace' file");
- exit(EXIT_FAILURE);
- }
+ Locked(_nc_tracing = tracelevel);
/* Try to set line-buffered mode, or (failing that) unbuffered,
* so that the trace-output gets flushed automatically at the
- * end of each line. This is useful in case the program dies.
+ * end of each line. This is useful in case the program dies.
*/
+ if (MyFP != 0) {
#if HAVE_SETVBUF /* ANSI */
- (void) setvbuf(TraceFP, (char *) 0, _IOLBF, (size_t) 0);
+ (void) setvbuf(MyFP, (char *) 0, _IOLBF, (size_t) 0);
#elif HAVE_SETBUF /* POSIX */
- (void) setbuffer(TraceFP, (char *) 0);
+ (void) setbuffer(MyFP, (char *) 0);
#endif
+ }
_tracef("TRACING NCURSES version %s.%d (tracelevel=%#x)",
NCURSES_VERSION,
NCURSES_VERSION_PATCH,
tracelevel);
- } else if (tracelevel == 0) {
- if (TraceFP != 0) {
- fclose(TraceFP);
- TraceFP = 0;
+
+#define SPECIAL_MASK(mask) \
+ if ((tracelevel & mask) == mask) \
+ _tracef("- %s (%u)", #mask, mask)
+
+ for (bit = 0; bit < TRACE_SHIFT; ++bit) {
+ unsigned mask = (1U << bit) & tracelevel;
+ if ((mask & trace_names[bit].mask) != 0) {
+ _tracef("- %s (%u)", trace_names[bit].name, mask);
+ }
}
- _nc_tracing = tracelevel;
+ SPECIAL_MASK(TRACE_MAXIMUM);
+ else
+ SPECIAL_MASK(TRACE_ORDINARY);
+
+ if (tracelevel > TRACE_MAXIMUM) {
+ _tracef("- DEBUG_LEVEL(%u)", tracelevel >> TRACE_SHIFT);
+ }
+ } else if (tracelevel == 0) {
+ if (MyFP != 0) {
+ MyFD = dup(MyFD); /* allow reopen of same file */
+ fclose(MyFP);
+ MyFP = 0;
+ }
+ Locked(_nc_tracing = tracelevel);
} else if (_nc_tracing != tracelevel) {
- _nc_tracing = tracelevel;
+ Locked(_nc_tracing = tracelevel);
_tracef("tracelevel=%#x", tracelevel);
}
+#else
+ (void) tracelevel;
+ result = 0;
+#endif
+ return result;
+}
+
+#if defined(TRACE)
+NCURSES_EXPORT(void)
+trace(const unsigned int tracelevel)
+{
+ curses_trace(tracelevel);
}
static void
@@ -151,16 +222,23 @@
bool after = FALSE;
unsigned doit = _nc_tracing;
int save_err = errno;
+ FILE *fp = MyFP;
+
+#ifdef TRACE
+ /* verbose-trace in the command-line utilities relies on this */
+ if (fp == 0 && !MyInit && _nc_tracing >= DEBUG_LEVEL(1))
+ fp = stderr;
+#endif
if (strlen(fmt) >= sizeof(Called) - 1) {
if (!strncmp(fmt, Called, sizeof(Called) - 1)) {
before = TRUE;
- TraceLevel++;
+ MyLevel++;
} else if (!strncmp(fmt, Return, sizeof(Return) - 1)) {
after = TRUE;
}
if (before || after) {
- if ((TraceLevel <= 1)
+ if ((MyLevel <= 1)
|| (doit & TRACE_ICALLS) != 0)
doit &= (TRACE_CALLS | TRACE_CCALLS);
else
@@ -168,9 +246,7 @@
}
}
- if (doit != 0) {
- if (TraceFP == 0)
- TraceFP = stderr;
+ if (doit != 0 && fp != 0) {
#ifdef USE_PTHREADS
/*
* TRACE_ICALLS is "really" needed to show normal use with threaded
@@ -184,30 +260,32 @@
# if USE_WEAK_SYMBOLS
if ((pthread_self))
# endif
-#ifdef __MINGW32__
- fprintf(TraceFP, "%#lx:", (long) (intptr_t) pthread_self().p);
+ fprintf(fp, "%#" PRIxPTR ":",
+#ifdef _NC_WINDOWS
+ CASTxPTR(pthread_self().p)
#else
- fprintf(TraceFP, "%#lx:", (long) (intptr_t) pthread_self());
+ CASTxPTR(pthread_self())
#endif
+ );
#endif
if (before || after) {
int n;
- for (n = 1; n < TraceLevel; n++)
- fputs("+ ", TraceFP);
+ for (n = 1; n < MyLevel; n++)
+ fputs("+ ", fp);
}
- vfprintf(TraceFP, fmt, ap);
- fputc('\n', TraceFP);
- fflush(TraceFP);
+ vfprintf(fp, fmt, ap);
+ fputc('\n', fp);
+ fflush(fp);
}
- if (after && TraceLevel)
- TraceLevel--;
+ if (after && MyLevel)
+ MyLevel--;
errno = save_err;
}
NCURSES_EXPORT(void)
-_tracef(const char *fmt,...)
+_tracef(const char *fmt, ...)
{
va_list ap;
@@ -296,6 +374,39 @@
return code;
}
+NCURSES_EXPORT(char *)
+_nc_fmt_funcptr(char *target, const char *source, size_t size)
+{
+ size_t n;
+ char *dst = target;
+ bool leading = TRUE;
+
+ union {
+ int value;
+ char bytes[sizeof(int)];
+ } byteorder;
+
+ byteorder.value = 0x1234;
+
+ *dst++ = '0';
+ *dst++ = 'x';
+
+ for (n = 0; n < size; ++n) {
+ unsigned ch = ((byteorder.bytes[0] == 0x34)
+ ? UChar(source[size - n - 1])
+ : UChar(source[n]));
+ if (ch != 0 || (n + 1) >= size)
+ leading = FALSE;
+ if (!leading) {
+ _nc_SPRINTF(dst, _nc_SLIMIT(TR_FUNC_LEN - (size_t) (dst - target))
+ "%02x", ch & 0xff);
+ dst += 2;
+ }
+ }
+ *dst = '\0';
+ return target;
+}
+
#if USE_REENTRANT
/*
* Check if the given trace-mask is enabled.
@@ -310,13 +421,13 @@
bool result = FALSE;
_nc_lock_global(tst_tracef);
- if (!_nc_globals.nested_tracef++) {
+ if (!MyNested++) {
if ((result = (_nc_tracing & (mask))) != 0
&& _nc_try_global(tracef) == 0) {
/* we will call _nc_locked_tracef(), no nesting so far */
} else {
/* we will not call _nc_locked_tracef() */
- _nc_globals.nested_tracef = 0;
+ MyNested = 0;
}
} else {
/* we may call _nc_locked_tracef(), but with nested_tracef > 0 */
@@ -331,7 +442,7 @@
* the tracef mutex.
*/
NCURSES_EXPORT(void)
-_nc_locked_tracef(const char *fmt,...)
+_nc_locked_tracef(const char *fmt, ...)
{
va_list ap;
@@ -339,7 +450,7 @@
_nc_va_tracef(fmt, ap);
va_end(ap);
- if (--(_nc_globals.nested_tracef) == 0) {
+ if (--(MyNested) == 0) {
_nc_unlock_global(tracef);
}
}
diff --git a/ncurses/trace/lib_traceatr.c b/ncurses/trace/lib_traceatr.c
index 24772d8..b362862 100644
--- a/ncurses/trace/lib_traceatr.c
+++ b/ncurses/trace/lib_traceatr.c
@@ -1,5 +1,6 @@
/****************************************************************************
- * Copyright (c) 1998-2013,2014 Free Software Foundation, Inc. *
+ * Copyright 2018-2022,2024 Thomas E. Dickey *
+ * Copyright 1998-2017,2018 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 *
@@ -43,7 +44,7 @@
#define CUR SP_TERMTYPE
#endif
-MODULE_ID("$Id: lib_traceatr.c,v 1.83 2015/04/04 13:41:37 tom Exp $")
+MODULE_ID("$Id: lib_traceatr.c,v 1.96 2024/02/04 00:11:35 tom Exp $")
#define COLOR_OF(c) ((c < 0) ? "default" : (c > 7 ? color_of(c) : colors[c].name))
@@ -67,7 +68,7 @@
if (c != my_cached) {
my_cached = c;
my_select = !my_select;
- if (c == COLOR_DEFAULT)
+ if (isDefaultColor(c))
_nc_STRCPY(my_buffer[my_select], "default",
COLOR_BUF_SIZE(my_select));
else
@@ -123,11 +124,10 @@
#endif /* !USE_TERMLIB */
;
#undef DATA
- size_t n;
- char temp[80];
char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
if (result != 0) {
+ size_t n;
unsigned save_nc_tracing = _nc_tracing;
_nc_tracing = 0;
@@ -135,12 +135,14 @@
_nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum));
for (n = 0; n < SIZEOF(names); n++) {
+
if ((newmode & names[n].val) != 0) {
if (result[1] != '\0')
(void) _nc_trace_bufcat(bufnum, "|");
result = _nc_trace_bufcat(bufnum, names[n].name);
if (names[n].val == A_COLOR) {
+ char temp[80];
short pairnum = (short) PairNumber(newmode);
#ifdef USE_TERMLIB
/* pair_content lives in libncurses */
@@ -254,7 +256,6 @@
if (SP_PARM != 0 && (attr & A_ALTCHARSET) && (acs_chars != 0)) {
char *cp;
char *found = 0;
- size_t n;
for (cp = acs_chars; cp[0] && cp[1]; cp += 2) {
if (ChCharOf(UChar(cp[1])) == ChCharOf(ch)) {
@@ -264,6 +265,8 @@
}
if (found != 0) {
+ size_t n;
+
ch = ChCharOf(UChar(*found));
for (n = 0; n < SIZEOF(names); ++n) {
if (names[n].val == ch) {
@@ -279,22 +282,25 @@
NCURSES_EXPORT(char *)
_tracechtype2(int bufnum, chtype ch)
{
- const char *found;
char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
if (result != 0) {
+ const char *found;
+ attr_t attr = ChAttrOf(ch);
+
_nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum));
- if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) {
+ if ((found = _nc_altcharset_name(attr, ch)) != 0) {
(void) _nc_trace_bufcat(bufnum, found);
+ attr &= ~A_ALTCHARSET;
} else
(void) _nc_trace_bufcat(bufnum,
_nc_tracechar(CURRENT_SCREEN,
(int) ChCharOf(ch)));
- if (ChAttrOf(ch) != A_NORMAL) {
+ if (attr != A_NORMAL) {
(void) _nc_trace_bufcat(bufnum, " | ");
(void) _nc_trace_bufcat(bufnum,
- _traceattr2(bufnum + 20, ChAttrOf(ch)));
+ _traceattr2(bufnum + 20, attr));
}
result = _nc_trace_bufcat(bufnum, r_brace);
@@ -321,13 +327,13 @@
_tracecchar_t2(int bufnum, const cchar_t *ch)
{
char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
- attr_t attr;
- const char *found;
if (result != 0) {
_nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum));
if (ch != 0) {
- attr = AttrOfD(ch);
+ const char *found;
+ attr_t attr = AttrOfD(ch);
+
if ((found = _nc_altcharset_name(attr, (chtype) CharOfD(ch))) != 0) {
(void) _nc_trace_bufcat(bufnum, found);
attr &= ~A_ALTCHARSET;
@@ -337,8 +343,8 @@
} else {
PUTC_DATA;
int n;
+ int assume_unicode = _nc_unicode_locale()? 128 : 255;
- PUTC_INIT;
(void) _nc_trace_bufcat(bufnum, "{ ");
for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
PUTC_ch = ch->chars[PUTC_i];
@@ -347,6 +353,7 @@
(void) _nc_trace_bufcat(bufnum, "\\000");
break;
}
+ PUTC_INIT;
PUTC_n = (int) wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st);
if (PUTC_n <= 0) {
if (PUTC_ch != L'\0') {
@@ -356,13 +363,22 @@
UChar(ch->chars[PUTC_i])));
}
break;
- }
- for (n = 0; n < PUTC_n; n++) {
- if (n)
- (void) _nc_trace_bufcat(bufnum, ", ");
- (void) _nc_trace_bufcat(bufnum,
- _nc_tracechar(CURRENT_SCREEN,
- UChar(PUTC_buf[n])));
+ } else if (ch->chars[PUTC_i] > assume_unicode) {
+ char temp[80];
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "{%d:\\u%04lx}",
+ _nc_wacs_width(ch->chars[PUTC_i]),
+ (unsigned long) ch->chars[PUTC_i]);
+ (void) _nc_trace_bufcat(bufnum, temp);
+ attr &= ~A_CHARTEXT; /* ignore WidecExt(ch) */
+ } else {
+ for (n = 0; n < PUTC_n; n++) {
+ if (n)
+ (void) _nc_trace_bufcat(bufnum, ", ");
+ (void) _nc_trace_bufcat(bufnum,
+ _nc_tracechar(CURRENT_SCREEN,
+ UChar(PUTC_buf[n])));
+ }
}
}
(void) _nc_trace_bufcat(bufnum, " }");
@@ -371,6 +387,18 @@
(void) _nc_trace_bufcat(bufnum, " | ");
(void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr));
}
+#if NCURSES_EXT_COLORS
+ /*
+ * Just in case the extended color is different from the chtype
+ * value, trace both.
+ */
+ if (ch->ext_color != PairNumber(attr)) {
+ char temp[80];
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ " X_COLOR{%d:%d}", ch->ext_color, PairNumber(attr));
+ (void) _nc_trace_bufcat(bufnum, temp);
+ }
+#endif
}
result = _nc_trace_bufcat(bufnum, r_brace);
diff --git a/ncurses/trace/lib_tracebits.c b/ncurses/trace/lib_tracebits.c
index f880b67..4bc50f3 100644
--- a/ncurses/trace/lib_tracebits.c
+++ b/ncurses/trace/lib_tracebits.c
@@ -1,5 +1,6 @@
/****************************************************************************
- * Copyright (c) 1998-2012,2015 Free Software Foundation, Inc. *
+ * Copyright 2019,2020 Thomas E. Dickey *
+ * Copyright 1998-2012,2015 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 +35,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_tracebits.c,v 1.26 2015/04/19 14:58:39 tom Exp $")
+MODULE_ID("$Id: lib_tracebits.c,v 1.31 2020/11/14 23:38:11 tom Exp $")
#if HAVE_SYS_TERMIO_H
#include <sys/termio.h> /* needed for ISC */
@@ -71,9 +72,15 @@
#ifdef TRACE
+#if defined(EXP_WIN32_DRIVER)
+#define BITNAMELEN 36
+#else
+#define BITNAMELEN 8
+#endif
+
typedef struct {
unsigned int val;
- const char name[8];
+ const char name[BITNAMELEN];
} BITNAMES;
#define TRACE_BUF_SIZE(num) (_nc_globals.tracebuf_ptr[num].size)
@@ -97,7 +104,7 @@
}
NCURSES_EXPORT(char *)
-_nc_trace_ttymode(TTY * tty)
+_nc_trace_ttymode(const TTY * tty)
/* describe the state of the terminal control bits exactly */
{
char *buf;
@@ -130,7 +137,7 @@
DATA(ONOCR),
DATA(ONLRET),
DATAX()
-#define ALLOUT (OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET)
+#define ALLOUT (OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET|OFLAGS_TABS)
}, cflags[] =
{
DATA(CLOCAL),
@@ -211,6 +218,36 @@
if (tty->c_lflag & ALLLOCAL)
lookup_bits(buf, lflags, "lflags", tty->c_lflag);
}
+#elif defined(EXP_WIN32_DRIVER)
+#define DATA(name) { name, { #name } }
+ static const BITNAMES dwFlagsOut[] =
+ {
+ DATA(ENABLE_PROCESSED_OUTPUT),
+ DATA(ENABLE_WRAP_AT_EOL_OUTPUT),
+ DATA(ENABLE_VIRTUAL_TERMINAL_PROCESSING),
+ DATA(DISABLE_NEWLINE_AUTO_RETURN),
+ DATA(ENABLE_LVB_GRID_WORLDWIDE)
+ };
+ static const BITNAMES dwFlagsIn[] =
+ {
+ DATA(ENABLE_PROCESSED_INPUT),
+ DATA(ENABLE_LINE_INPUT),
+ DATA(ENABLE_ECHO_INPUT),
+ DATA(ENABLE_MOUSE_INPUT),
+ DATA(ENABLE_INSERT_MODE),
+ DATA(ENABLE_QUICK_EDIT_MODE),
+ DATA(ENABLE_EXTENDED_FLAGS),
+ DATA(ENABLE_AUTO_POSITION),
+ DATA(ENABLE_VIRTUAL_TERMINAL_INPUT)
+ };
+
+ buf = _nc_trace_buf(0,
+ 8 + sizeof(dwFlagsOut) +
+ 8 + sizeof(dwFlagsIn));
+ if (buf != 0) {
+ lookup_bits(buf, dwFlagsIn, "dwIn", tty->dwFlagIn);
+ lookup_bits(buf, dwFlagsOut, "dwOut", tty->dwFlagOut);
+ }
#else
/* reference: ttcompat(4M) on SunOS 4.1 */
#ifndef EVENP
diff --git a/ncurses/trace/lib_tracechr.c b/ncurses/trace/lib_tracechr.c
index 8977f75..9c879dc 100644
--- a/ncurses/trace/lib_tracechr.c
+++ b/ncurses/trace/lib_tracechr.c
@@ -1,5 +1,6 @@
/****************************************************************************
- * Copyright (c) 1998-2009,2012 Free Software Foundation, Inc. *
+ * Copyright 2020,2024 Thomas E. Dickey *
+ * Copyright 1998-2009,2012 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 *
@@ -39,7 +40,7 @@
#include <ctype.h>
-MODULE_ID("$Id: lib_tracechr.c,v 1.22 2012/02/22 22:40:24 tom Exp $")
+MODULE_ID("$Id: lib_tracechr.c,v 1.24 2024/02/04 00:11:35 tom Exp $")
#ifdef TRACE
@@ -53,26 +54,28 @@
? sp->tracechr_buf
: _nc_globals.tracechr_buf);
- if (ch > KEY_MIN || ch < 0) {
+ if ((ch > KEY_MIN && !_nc_unicode_locale()) || ch < 0) {
name = safe_keyname(SP_PARM, ch);
if (name == 0 || *name == '\0')
name = "NULL";
_nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
- "'%.30s' = %#03o", name, ch);
- } else if (!is8bits(ch) || !isprint(UChar(ch))) {
+ "'%.30s' = \\x%02x", name, ch);
+ } else if (!is8bits(ch)
+ || (_nc_unicode_locale() && !is7bits(ch))
+ || !isprint(UChar(ch))) {
/*
* workaround for glibc bug:
* sprintf changes the result from unctrl() to an empty string if it
* does not correspond to a valid multibyte sequence.
*/
_nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
- "%#03o", ch);
+ "\\x%02x", ch);
} else {
name = safe_unctrl(SP_PARM, (chtype) ch);
if (name == 0 || *name == 0)
name = "null"; /* shouldn't happen */
_nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
- "'%.30s' = %#03o", name, ch);
+ "'%.30s' = \\x%02x", name, ch);
}
return (MyBuffer);
}
diff --git a/ncurses/trace/lib_tracedmp.c b/ncurses/trace/lib_tracedmp.c
index 0fda15b..529148b 100644
--- a/ncurses/trace/lib_tracedmp.c
+++ b/ncurses/trace/lib_tracedmp.c
@@ -1,5 +1,6 @@
/****************************************************************************
- * Copyright (c) 1998-2009,2012 Free Software Foundation, Inc. *
+ * Copyright 2020,2023 Thomas E. Dickey *
+ * Copyright 1998-2012,2016 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 *
@@ -39,7 +40,7 @@
#include <curses.priv.h>
#include <ctype.h>
-MODULE_ID("$Id: lib_tracedmp.c,v 1.34 2012/10/27 20:54:42 tom Exp $")
+MODULE_ID("$Id: lib_tracedmp.c,v 1.37 2023/06/24 15:49:45 tom Exp $")
#ifdef TRACE
@@ -70,13 +71,13 @@
if (++width + 1 > (int) my_length) {
my_length = (unsigned) (2 * (width + 1));
my_buffer = typeRealloc(char, my_length, my_buffer);
- if (my_buffer == 0)
- return;
}
+ if (my_buffer == 0)
+ return;
for (n = 0; n <= win->_maxy; ++n) {
char *ep = my_buffer;
- bool haveattrs, havecolors;
+ bool havecolors;
/*
* Dump A_CHARTEXT part. It is more important to make the grid line up
@@ -156,8 +157,8 @@
for (i = 0; i < 4; ++i) {
const char *hex = " 123456789ABCDEF";
attr_t mask = (attr_t) (0xf << ((i + 4) * 4));
+ bool haveattrs = FALSE;
- haveattrs = FALSE;
for (j = 0; j < width; ++j)
if (AttrOf(win->_line[n].text[j]) & mask) {
haveattrs = TRUE;
diff --git a/ncurses/trace/lib_tracemse.c b/ncurses/trace/lib_tracemse.c
index c62b71a..33d4d3d 100644
--- a/ncurses/trace/lib_tracemse.c
+++ b/ncurses/trace/lib_tracemse.c
@@ -1,5 +1,6 @@
/****************************************************************************
- * Copyright (c) 1998-2012,2014 Free Software Foundation, Inc. *
+ * Copyright 2020 Thomas E. Dickey *
+ * Copyright 1998-2012,2014 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 *
@@ -38,7 +39,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_tracemse.c,v 1.22 2014/10/10 09:06:26 tom Exp $")
+MODULE_ID("$Id: lib_tracemse.c,v 1.23 2020/02/02 23:34:34 tom Exp $")
#ifdef TRACE
diff --git a/ncurses/trace/trace_buf.c b/ncurses/trace/trace_buf.c
index 84a7a0c..91b12e4 100644
--- a/ncurses/trace/trace_buf.c
+++ b/ncurses/trace/trace_buf.c
@@ -1,5 +1,6 @@
/****************************************************************************
- * Copyright (c) 1998-2011,2012 Free Software Foundation, Inc. *
+ * Copyright 2020,2023 Thomas E. Dickey *
+ * Copyright 1998-2011,2012 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 *
@@ -35,7 +36,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: trace_buf.c,v 1.20 2012/02/22 22:34:31 tom Exp $")
+MODULE_ID("$Id: trace_buf.c,v 1.22 2023/06/24 13:37:25 tom Exp $")
#ifdef TRACE
@@ -103,7 +104,11 @@
NCURSES_EXPORT(char *)
_nc_trace_bufcat(int bufnum, const char *value)
{
- char *buffer = _nc_trace_alloc(bufnum, (size_t) 0);
+ char *buffer;
+
+ if (value == NULL)
+ value = "";
+ buffer = _nc_trace_alloc(bufnum, (size_t) 0);
if (buffer != 0) {
size_t have = strlen(buffer);
size_t need = strlen(value) + have;
diff --git a/ncurses/trace/trace_tries.c b/ncurses/trace/trace_tries.c
index 50ba016..14f704b 100644
--- a/ncurses/trace/trace_tries.c
+++ b/ncurses/trace/trace_tries.c
@@ -1,5 +1,6 @@
/****************************************************************************
- * Copyright (c) 1999-2011,2012 Free Software Foundation, Inc. *
+ * Copyright 2020 Thomas E. Dickey *
+ * Copyright 1999-2011,2012 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 *
@@ -35,7 +36,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: trace_tries.c,v 1.17 2012/10/27 20:50:50 tom Exp $")
+MODULE_ID("$Id: trace_tries.c,v 1.18 2020/02/02 23:34:34 tom Exp $")
#ifdef TRACE
#define my_buffer _nc_globals.tracetry_buf
diff --git a/ncurses/trace/trace_xnames.c b/ncurses/trace/trace_xnames.c
index 38a4873..2d74336 100644
--- a/ncurses/trace/trace_xnames.c
+++ b/ncurses/trace/trace_xnames.c
@@ -1,5 +1,6 @@
/****************************************************************************
- * Copyright (c) 1999-2000,2010 Free Software Foundation, Inc. *
+ * Copyright 2020 Thomas E. Dickey *
+ * Copyright 1999-2010,2016 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 *
@@ -35,7 +36,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: trace_xnames.c,v 1.6 2010/01/23 17:59:27 tom Exp $")
+MODULE_ID("$Id: trace_xnames.c,v 1.8 2020/02/02 23:34:34 tom Exp $")
NCURSES_EXPORT(void)
_nc_trace_xnames(TERMTYPE *tp GCC_UNUSED)
@@ -43,8 +44,9 @@
#ifdef TRACE
#if NCURSES_XNAMES
int limit = tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings;
- int n, m;
+
if (limit) {
+ int n;
int begin_num = tp->ext_Booleans;
int begin_str = tp->ext_Booleans + tp->ext_Numbers;
@@ -53,7 +55,10 @@
limit,
tp->ext_Booleans, tp->ext_Numbers, tp->ext_Strings,
tp->num_Booleans, tp->num_Numbers, tp->num_Strings);
+
for (n = 0; n < limit; n++) {
+ int m;
+
if ((m = n - begin_str) >= 0) {
_tracef("[%d] %s = %s", n,
tp->ext_Names[n],
diff --git a/ncurses/trace/varargs.c b/ncurses/trace/varargs.c
index 66252d8..7b9533b 100644
--- a/ncurses/trace/varargs.c
+++ b/ncurses/trace/varargs.c
@@ -1,5 +1,6 @@
/****************************************************************************
- * Copyright (c) 2001-2008,2012 Free Software Foundation, Inc. *
+ * Copyright 2020,2023 Thomas E. Dickey *
+ * Copyright 2001-2008,2012 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 +35,7 @@
#include <ctype.h>
-MODULE_ID("$Id: varargs.c,v 1.11 2012/10/27 21:03:28 tom Exp $")
+MODULE_ID("$Id: varargs.c,v 1.13 2023/06/24 13:41:46 tom Exp $")
#ifdef TRACE
@@ -58,18 +59,16 @@
NCURSES_EXPORT(char *)
_nc_varargs(const char *fmt, va_list ap)
{
- static char dummy[] = "";
-
char buffer[BUFSIZ];
const char *param;
int n;
if (fmt == 0 || *fmt == '\0')
- return dummy;
+ return NULL;
if (MyLength == 0)
MyBuffer = typeMalloc(char, MyLength = BUFSIZ);
if (MyBuffer == 0)
- return dummy;
+ return NULL;
*MyBuffer = '\0';
while (*fmt != '\0') {
@@ -184,7 +183,7 @@
}
}
- return (MyBuffer ? MyBuffer : dummy);
+ return (MyBuffer ? MyBuffer : NULL);
}
#else
EMPTY_MODULE(_nc_varargs)
diff --git a/ncurses/trace/visbuf.c b/ncurses/trace/visbuf.c
index fec0643..590e423 100644
--- a/ncurses/trace/visbuf.c
+++ b/ncurses/trace/visbuf.c
@@ -1,5 +1,6 @@
/****************************************************************************
- * Copyright (c) 2001-2012,2014 Free Software Foundation, Inc. *
+ * Copyright 2019-2021,2023 Thomas E. Dickey *
+ * Copyright 2001-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 *
@@ -42,7 +43,7 @@
#include <tic.h>
#include <ctype.h>
-MODULE_ID("$Id: visbuf.c,v 1.44 2014/09/25 08:51:13 tom Exp $")
+MODULE_ID("$Id: visbuf.c,v 1.54 2023/05/27 20:13:10 tom Exp $")
#define NUM_VISBUFS 4
@@ -66,7 +67,9 @@
static char *
_nc_vischar(char *tp, unsigned c LIMIT_ARG)
{
- if (c == '"' || c == '\\') {
+ if (tp == NULL) {
+ return NULL;
+ } else if (c == '"' || c == '\\') {
*tp++ = '\\';
*tp++ = (char) c;
} else if (is7bits((int) c) && (isgraph((int) c) || c == ' ')) {
@@ -80,6 +83,9 @@
} else if (c == '\b') {
*tp++ = '\\';
*tp++ = 'b';
+ } else if (c == '\t') {
+ *tp++ = '\\';
+ *tp++ = 't';
} else if (c == '\033') {
*tp++ = '\\';
*tp++ = 'e';
@@ -105,7 +111,6 @@
{
const char *vbuf = 0;
char *tp;
- int c;
int count;
if (buf == 0)
@@ -122,6 +127,8 @@
#else
{
static char *mybuf[NUM_VISBUFS];
+ int c;
+
if (bufnum < 0) {
for (c = 0; c < NUM_VISBUFS; ++c) {
FreeAndNull(mybuf[c]);
@@ -134,6 +141,8 @@
}
#endif
if (tp != 0) {
+ int c;
+
*tp++ = D_QUOTE;
while ((--count >= 0) && (c = *buf++) != '\0') {
tp = VisChar(tp, UChar(c), NormalLen(len));
@@ -185,7 +194,6 @@
{
const char *vbuf;
char *tp;
- wchar_t c;
int count;
if (buf == 0)
@@ -205,6 +213,8 @@
}
#endif
if (tp != 0) {
+ wchar_t c;
+
*tp++ = D_QUOTE;
while ((--count >= 0) && (c = *buf++) != '\0') {
char temp[CCHARW_MAX + 80];
@@ -275,13 +285,13 @@
/* use these functions for displaying parts of a line within a window */
NCURSES_EXPORT(const char *)
-_nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
+_nc_viscbuf2(int bufnum, const NCURSES_CH_T *buf, int len)
{
char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
- int first;
- const char *found;
if (result != 0) {
+ int first = 0;
+
#if USE_WIDEC_SUPPORT
if (len < 0)
len = _nc_wchstrlen(buf);
@@ -290,7 +300,6 @@
/*
* Display one or more strings followed by attributes.
*/
- first = 0;
while (first < len) {
attr_t attr = AttrOf(buf[first]);
int last = len - 1;
@@ -306,7 +315,8 @@
(void) _nc_trace_bufcat(bufnum, l_brace);
(void) _nc_trace_bufcat(bufnum, d_quote);
for (j = first; j <= last; ++j) {
- found = _nc_altcharset_name(attr, (chtype) CharOf(buf[j]));
+ const char *found = _nc_altcharset_name(attr, (chtype)
+ CharOf(buf[j]));
if (found != 0) {
(void) _nc_trace_bufcat(bufnum, found);
attr &= ~A_ALTCHARSET;
@@ -315,9 +325,9 @@
if (!isWidecExt(buf[j])) {
PUTC_DATA;
- PUTC_INIT;
for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
int k;
+ char temp[80];
PUTC_ch = buf[j].chars[PUTC_i];
if (PUTC_ch == L'\0') {
@@ -325,12 +335,18 @@
(void) _nc_trace_bufcat(bufnum, "\\000");
break;
}
+ PUTC_INIT;
PUTC_n = (int) wcrtomb(PUTC_buf,
buf[j].chars[PUTC_i], &PUT_st);
- if (PUTC_n <= 0)
+ if (PUTC_n <= 0 || buf[j].chars[PUTC_i] > 255) {
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "{%d:\\u%lx}",
+ _nc_wacs_width(buf[j].chars[PUTC_i]),
+ (unsigned long) buf[j].chars[PUTC_i]);
+ (void) _nc_trace_bufcat(bufnum, temp);
break;
+ }
for (k = 0; k < PUTC_n; k++) {
- char temp[80];
VisChar(temp, UChar(PUTC_buf[k]), sizeof(temp));
(void) _nc_trace_bufcat(bufnum, temp);
}
@@ -357,7 +373,7 @@
}
NCURSES_EXPORT(const char *)
-_nc_viscbuf(const NCURSES_CH_T * buf, int len)
+_nc_viscbuf(const NCURSES_CH_T *buf, int len)
{
return _nc_viscbuf2(0, buf, len);
}