Update to ncurses-6.0
Change-Id: I98ab2ea8a5e13cca9f8b7cf6277b9b14a4da4299
diff --git a/ncurses/trace/lib_trace.c b/ncurses/trace/lib_trace.c
index 743b1f6..cec01de 100644
--- a/ncurses/trace/lib_trace.c
+++ b/ncurses/trace/lib_trace.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2012,2013 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 *
@@ -30,6 +30,7 @@
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
* and: Thomas E. Dickey 1996-on *
+ * and: Juergen Pfeifer *
****************************************************************************/
/*
@@ -46,7 +47,7 @@
#include <ctype.h>
-MODULE_ID("$Id: lib_trace.c,v 1.71 2008/08/23 18:04:29 tom Exp $")
+MODULE_ID("$Id: lib_trace.c,v 1.82 2013/07/06 19:42:09 tom Exp $")
NCURSES_EXPORT_VAR(unsigned) _nc_tracing = 0; /* always define this */
@@ -56,26 +57,26 @@
NCURSES_EXPORT(const char *)
NCURSES_PUBLIC_VAR(_nc_tputs_trace) (void)
{
- return SP ? SP->_tputs_trace : _nc_prescreen._tputs_trace;
+ return CURRENT_SCREEN ? CURRENT_SCREEN->_tputs_trace : _nc_prescreen._tputs_trace;
}
NCURSES_EXPORT(long)
NCURSES_PUBLIC_VAR(_nc_outchars) (void)
{
- return SP ? SP->_outchars : _nc_prescreen._outchars;
+ return CURRENT_SCREEN ? CURRENT_SCREEN->_outchars : _nc_prescreen._outchars;
}
NCURSES_EXPORT(void)
_nc_set_tputs_trace(const char *s)
{
- if (SP)
- SP->_tputs_trace = s;
+ if (CURRENT_SCREEN)
+ CURRENT_SCREEN->_tputs_trace = s;
else
_nc_prescreen._tputs_trace = s;
}
NCURSES_EXPORT(void)
_nc_count_outchars(long increment)
{
- if (SP)
- SP->_outchars += increment;
+ if (CURRENT_SCREEN)
+ CURRENT_SCREEN->_outchars += increment;
else
_nc_prescreen._outchars += increment;
}
@@ -95,16 +96,16 @@
const char *mode = _nc_globals.init_trace ? "ab" : "wb";
if (TracePath[0] == '\0') {
- int size = sizeof(TracePath) - 12;
+ size_t size = sizeof(TracePath) - 12;
if (getcwd(TracePath, size) == 0) {
perror("curses: Can't get working directory");
exit(EXIT_FAILURE);
}
TracePath[size] = '\0';
assert(strlen(TracePath) <= size);
- strcat(TracePath, "/trace");
+ _nc_STRCAT(TracePath, "/trace", sizeof(TracePath));
if (_nc_is_dir_path(TracePath)) {
- strcat(TracePath, ".log");
+ _nc_STRCAT(TracePath, ".log", sizeof(TracePath));
}
}
@@ -120,8 +121,8 @@
* end of each line. This is useful in case the program dies.
*/
#if HAVE_SETVBUF /* ANSI */
- (void) setvbuf(TraceFP, (char *) 0, _IOLBF, 0);
-#elif HAVE_SETBUF /* POSIX */
+ (void) setvbuf(TraceFP, (char *) 0, _IOLBF, (size_t) 0);
+#elif HAVE_SETBUF /* POSIX */
(void) setbuffer(TraceFP, (char *) 0);
#endif
_tracef("TRACING NCURSES version %s.%d (tracelevel=%#x)",
@@ -183,7 +184,11 @@
# if USE_WEAK_SYMBOLS
if ((pthread_self))
# endif
- fprintf(TraceFP, "%#lx:", (long) (void *) pthread_self());
+#ifdef __MINGW32__
+ fprintf(TraceFP, "%#lx:", (long) (intptr_t) pthread_self().p);
+#else
+ fprintf(TraceFP, "%#lx:", (long) (intptr_t) pthread_self());
+#endif
#endif
if (before || after) {
int n;
@@ -213,12 +218,20 @@
/* Trace 'bool' return-values */
NCURSES_EXPORT(NCURSES_BOOL)
-_nc_retrace_bool(NCURSES_BOOL code)
+_nc_retrace_bool(int code)
{
T((T_RETURN("%s"), code ? "TRUE" : "FALSE"));
return code;
}
+/* Trace 'char' return-values */
+NCURSES_EXPORT(char)
+_nc_retrace_char(int code)
+{
+ T((T_RETURN("%c"), code));
+ return (char) code;
+}
+
/* Trace 'int' return-values */
NCURSES_EXPORT(int)
_nc_retrace_int(int code)
@@ -271,7 +284,7 @@
NCURSES_EXPORT(SCREEN *)
_nc_retrace_sp(SCREEN *code)
{
- T((T_RETURN("%p"), code));
+ T((T_RETURN("%p"), (void *) code));
return code;
}
@@ -279,7 +292,7 @@
NCURSES_EXPORT(WINDOW *)
_nc_retrace_win(WINDOW *code)
{
- T((T_RETURN("%p"), code));
+ T((T_RETURN("%p"), (void *) code));
return code;
}
@@ -326,8 +339,9 @@
_nc_va_tracef(fmt, ap);
va_end(ap);
- if (--(_nc_globals.nested_tracef) == 0)
+ if (--(_nc_globals.nested_tracef) == 0) {
_nc_unlock_global(tracef);
+ }
}
#endif /* USE_REENTRANT */
diff --git a/ncurses/trace/lib_traceatr.c b/ncurses/trace/lib_traceatr.c
index 45a03ce..24772d8 100644
--- a/ncurses/trace/lib_traceatr.c
+++ b/ncurses/trace/lib_traceatr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2013,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 *
@@ -30,6 +30,7 @@
* Author: Thomas Dickey 1996-on *
* and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Juergen Pfeifer *
****************************************************************************/
/*
@@ -37,12 +38,18 @@
*/
#include <curses.priv.h>
-#include <term.h> /* acs_chars */
-MODULE_ID("$Id: lib_traceatr.c,v 1.63 2008/08/03 16:24:53 tom Exp $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
+
+MODULE_ID("$Id: lib_traceatr.c,v 1.83 2015/04/04 13:41:37 tom Exp $")
#define COLOR_OF(c) ((c < 0) ? "default" : (c > 7 ? color_of(c) : colors[c].name))
+#define TRACE_BUF_SIZE(num) (_nc_globals.tracebuf_ptr[num].size)
+#define COLOR_BUF_SIZE(num) (sizeof(my_buffer[num]))
+
#ifdef TRACE
static const char l_brace[] = StringOf(L_BRACE);
@@ -61,9 +68,12 @@
my_cached = c;
my_select = !my_select;
if (c == COLOR_DEFAULT)
- strcpy(my_buffer[my_select], "default");
+ _nc_STRCPY(my_buffer[my_select], "default",
+ COLOR_BUF_SIZE(my_select));
else
- sprintf(my_buffer[my_select], "color%d", c);
+ _nc_SPRINTF(my_buffer[my_select],
+ _nc_SLIMIT(COLOR_BUF_SIZE(my_select))
+ "color%d", c);
}
return my_buffer[my_select];
}
@@ -75,78 +85,79 @@
NCURSES_EXPORT(char *)
_traceattr2(int bufnum, chtype newmode)
{
+#define DATA(name) { name, { #name } }
static const struct {
unsigned int val;
- const char *name;
+ const char name[14];
} names[] =
{
- /* *INDENT-OFF* */
- { A_STANDOUT, "A_STANDOUT" },
- { A_UNDERLINE, "A_UNDERLINE" },
- { A_REVERSE, "A_REVERSE" },
- { A_BLINK, "A_BLINK" },
- { A_DIM, "A_DIM" },
- { A_BOLD, "A_BOLD" },
- { A_ALTCHARSET, "A_ALTCHARSET" },
- { A_INVIS, "A_INVIS" },
- { A_PROTECT, "A_PROTECT" },
- { A_CHARTEXT, "A_CHARTEXT" },
- { A_NORMAL, "A_NORMAL" },
- { A_COLOR, "A_COLOR" },
- /* *INDENT-ON* */
-
+ DATA(A_STANDOUT),
+ DATA(A_UNDERLINE),
+ DATA(A_REVERSE),
+ DATA(A_BLINK),
+ DATA(A_DIM),
+ DATA(A_BOLD),
+ DATA(A_ALTCHARSET),
+ DATA(A_INVIS),
+ DATA(A_PROTECT),
+ DATA(A_CHARTEXT),
+ DATA(A_NORMAL),
+ DATA(A_COLOR),
+#if USE_ITALIC
+ DATA(A_ITALIC),
+#endif
}
#ifndef USE_TERMLIB
,
colors[] =
{
- /* *INDENT-OFF* */
- { COLOR_BLACK, "COLOR_BLACK" },
- { COLOR_RED, "COLOR_RED" },
- { COLOR_GREEN, "COLOR_GREEN" },
- { COLOR_YELLOW, "COLOR_YELLOW" },
- { COLOR_BLUE, "COLOR_BLUE" },
- { COLOR_MAGENTA, "COLOR_MAGENTA" },
- { COLOR_CYAN, "COLOR_CYAN" },
- { COLOR_WHITE, "COLOR_WHITE" },
- /* *INDENT-ON* */
-
+ DATA(COLOR_BLACK),
+ DATA(COLOR_RED),
+ DATA(COLOR_GREEN),
+ DATA(COLOR_YELLOW),
+ DATA(COLOR_BLUE),
+ DATA(COLOR_MAGENTA),
+ DATA(COLOR_CYAN),
+ DATA(COLOR_WHITE),
}
#endif /* !USE_TERMLIB */
;
+#undef DATA
size_t n;
char temp[80];
- char *result = _nc_trace_buf(bufnum, BUFSIZ);
+ char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
if (result != 0) {
unsigned save_nc_tracing = _nc_tracing;
_nc_tracing = 0;
- strcpy(result, l_brace);
+ _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')
- result = _nc_trace_bufcat(bufnum, "|");
+ (void) _nc_trace_bufcat(bufnum, "|");
result = _nc_trace_bufcat(bufnum, names[n].name);
if (names[n].val == A_COLOR) {
- short pairnum = PAIR_NUMBER(newmode);
+ short pairnum = (short) PairNumber(newmode);
#ifdef USE_TERMLIB
/* pair_content lives in libncurses */
- (void) sprintf(temp, "{%d}", pairnum);
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "{%d}", pairnum);
#else
- short fg, bg;
+ NCURSES_COLOR_T fg, bg;
if (pair_content(pairnum, &fg, &bg) == OK) {
- (void) sprintf(temp,
- "{%d = {%s, %s}}",
- pairnum,
- COLOR_OF(fg),
- COLOR_OF(bg));
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "{%d = {%s, %s}}",
+ pairnum,
+ COLOR_OF(fg),
+ COLOR_OF(bg));
} else {
- (void) sprintf(temp, "{%d}", pairnum);
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "{%d}", pairnum);
}
#endif
result = _nc_trace_bufcat(bufnum, temp);
@@ -172,6 +183,14 @@
}
/* Trace 'int' return-values */
+NCURSES_EXPORT(int)
+_nc_retrace_int_attr_t(attr_t code)
+{
+ T((T_RETURN("%s"), _traceattr(code)));
+ return (int) code;
+}
+
+/* Trace 'attr_t' return-values */
NCURSES_EXPORT(attr_t)
_nc_retrace_attr_t(attr_t code)
{
@@ -182,68 +201,76 @@
const char *
_nc_altcharset_name(attr_t attr, chtype ch)
{
+#define DATA(code, name) { code, { #name } }
typedef struct {
unsigned int val;
- const char *name;
+ const char name[13];
} ALT_NAMES;
+#if NCURSES_SP_FUNCS
+ SCREEN *sp = CURRENT_SCREEN;
+#endif
static const ALT_NAMES names[] =
{
- {'l', "ACS_ULCORNER"}, /* upper left corner */
- {'m', "ACS_LLCORNER"}, /* lower left corner */
- {'k', "ACS_URCORNER"}, /* upper right corner */
- {'j', "ACS_LRCORNER"}, /* lower right corner */
- {'t', "ACS_LTEE"}, /* tee pointing right */
- {'u', "ACS_RTEE"}, /* tee pointing left */
- {'v', "ACS_BTEE"}, /* tee pointing up */
- {'w', "ACS_TTEE"}, /* tee pointing down */
- {'q', "ACS_HLINE"}, /* horizontal line */
- {'x', "ACS_VLINE"}, /* vertical line */
- {'n', "ACS_PLUS"}, /* large plus or crossover */
- {'o', "ACS_S1"}, /* scan line 1 */
- {'s', "ACS_S9"}, /* scan line 9 */
- {'`', "ACS_DIAMOND"}, /* diamond */
- {'a', "ACS_CKBOARD"}, /* checker board (stipple) */
- {'f', "ACS_DEGREE"}, /* degree symbol */
- {'g', "ACS_PLMINUS"}, /* plus/minus */
- {'~', "ACS_BULLET"}, /* bullet */
- {',', "ACS_LARROW"}, /* arrow pointing left */
- {'+', "ACS_RARROW"}, /* arrow pointing right */
- {'.', "ACS_DARROW"}, /* arrow pointing down */
- {'-', "ACS_UARROW"}, /* arrow pointing up */
- {'h', "ACS_BOARD"}, /* board of squares */
- {'i', "ACS_LANTERN"}, /* lantern symbol */
- {'0', "ACS_BLOCK"}, /* solid square block */
- {'p', "ACS_S3"}, /* scan line 3 */
- {'r', "ACS_S7"}, /* scan line 7 */
- {'y', "ACS_LEQUAL"}, /* less/equal */
- {'z', "ACS_GEQUAL"}, /* greater/equal */
- {'{', "ACS_PI"}, /* Pi */
- {'|', "ACS_NEQUAL"}, /* not equal */
- {'}', "ACS_STERLING"}, /* UK pound sign */
- {'\0', (char *) 0}
+ DATA('l', ACS_ULCORNER), /* upper left corner */
+ DATA('m', ACS_LLCORNER), /* lower left corner */
+ DATA('k', ACS_URCORNER), /* upper right corner */
+ DATA('j', ACS_LRCORNER), /* lower right corner */
+ DATA('t', ACS_LTEE), /* tee pointing right */
+ DATA('u', ACS_RTEE), /* tee pointing left */
+ DATA('v', ACS_BTEE), /* tee pointing up */
+ DATA('w', ACS_TTEE), /* tee pointing down */
+ DATA('q', ACS_HLINE), /* horizontal line */
+ DATA('x', ACS_VLINE), /* vertical line */
+ DATA('n', ACS_PLUS), /* large plus or crossover */
+ DATA('o', ACS_S1), /* scan line 1 */
+ DATA('s', ACS_S9), /* scan line 9 */
+ DATA('`', ACS_DIAMOND), /* diamond */
+ DATA('a', ACS_CKBOARD), /* checker board (stipple) */
+ DATA('f', ACS_DEGREE), /* degree symbol */
+ DATA('g', ACS_PLMINUS), /* plus/minus */
+ DATA('~', ACS_BULLET), /* bullet */
+ DATA(',', ACS_LARROW), /* arrow pointing left */
+ DATA('+', ACS_RARROW), /* arrow pointing right */
+ DATA('.', ACS_DARROW), /* arrow pointing down */
+ DATA('-', ACS_UARROW), /* arrow pointing up */
+ DATA('h', ACS_BOARD), /* board of squares */
+ DATA('i', ACS_LANTERN), /* lantern symbol */
+ DATA('0', ACS_BLOCK), /* solid square block */
+ DATA('p', ACS_S3), /* scan line 3 */
+ DATA('r', ACS_S7), /* scan line 7 */
+ DATA('y', ACS_LEQUAL), /* less/equal */
+ DATA('z', ACS_GEQUAL), /* greater/equal */
+ DATA('{', ACS_PI), /* Pi */
+ DATA('|', ACS_NEQUAL), /* not equal */
+ DATA('}', ACS_STERLING), /* UK pound sign */
};
+#undef DATA
const char *result = 0;
- if ((attr & A_ALTCHARSET) && (acs_chars != 0)) {
+#if NCURSES_SP_FUNCS
+ (void) sp;
+#endif
+ if (SP_PARM != 0 && (attr & A_ALTCHARSET) && (acs_chars != 0)) {
char *cp;
char *found = 0;
- const ALT_NAMES *sp;
+ size_t n;
for (cp = acs_chars; cp[0] && cp[1]; cp += 2) {
- if (ChCharOf(cp[1]) == ChCharOf(ch)) {
+ if (ChCharOf(UChar(cp[1])) == ChCharOf(ch)) {
found = cp;
/* don't exit from loop - there may be redefinitions */
}
}
if (found != 0) {
- ch = ChCharOf(*found);
- for (sp = names; sp->val; sp++)
- if (sp->val == ch) {
- result = sp->name;
+ ch = ChCharOf(UChar(*found));
+ for (n = 0; n < SIZEOF(names); ++n) {
+ if (names[n].val == ch) {
+ result = names[n].name;
break;
}
+ }
}
}
return result;
@@ -253,14 +280,16 @@
_tracechtype2(int bufnum, chtype ch)
{
const char *found;
- char *result = _nc_trace_buf(bufnum, BUFSIZ);
+ char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
if (result != 0) {
- strcpy(result, l_brace);
+ _nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum));
if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) {
(void) _nc_trace_bufcat(bufnum, found);
} else
- (void) _nc_trace_bufcat(bufnum, _nc_tracechar(SP, (int) ChCharOf(ch)));
+ (void) _nc_trace_bufcat(bufnum,
+ _nc_tracechar(CURRENT_SCREEN,
+ (int) ChCharOf(ch)));
if (ChAttrOf(ch) != A_NORMAL) {
(void) _nc_trace_bufcat(bufnum, " | ");
@@ -291,12 +320,12 @@
NCURSES_EXPORT(char *)
_tracecchar_t2(int bufnum, const cchar_t *ch)
{
- char *result = _nc_trace_buf(bufnum, BUFSIZ);
+ char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
attr_t attr;
const char *found;
if (result != 0) {
- strcpy(result, l_brace);
+ _nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum));
if (ch != 0) {
attr = AttrOfD(ch);
if ((found = _nc_altcharset_name(attr, (chtype) CharOfD(ch))) != 0) {
@@ -313,14 +342,17 @@
(void) _nc_trace_bufcat(bufnum, "{ ");
for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
PUTC_ch = ch->chars[PUTC_i];
- if (PUTC_ch == L'\0')
+ if (PUTC_ch == L'\0') {
+ if (PUTC_i == 0)
+ (void) _nc_trace_bufcat(bufnum, "\\000");
break;
- PUTC_n = wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st);
+ }
+ PUTC_n = (int) wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st);
if (PUTC_n <= 0) {
if (PUTC_ch != L'\0') {
/* it could not be a multibyte sequence */
(void) _nc_trace_bufcat(bufnum,
- _nc_tracechar(SP,
+ _nc_tracechar(CURRENT_SCREEN,
UChar(ch->chars[PUTC_i])));
}
break;
@@ -329,7 +361,7 @@
if (n)
(void) _nc_trace_bufcat(bufnum, ", ");
(void) _nc_trace_bufcat(bufnum,
- _nc_tracechar(SP,
+ _nc_tracechar(CURRENT_SCREEN,
UChar(PUTC_buf[n])));
}
}
diff --git a/ncurses/trace/lib_tracebits.c b/ncurses/trace/lib_tracebits.c
index cc441b3..f880b67 100644
--- a/ncurses/trace/lib_tracebits.c
+++ b/ncurses/trace/lib_tracebits.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 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 *
@@ -33,13 +33,8 @@
****************************************************************************/
#include <curses.priv.h>
-#include <term.h> /* cur_term */
-MODULE_ID("$Id: lib_tracebits.c,v 1.17 2008/08/03 16:09:26 tom Exp $")
-
-#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
-#define _POSIX_SOURCE
-#endif
+MODULE_ID("$Id: lib_tracebits.c,v 1.26 2015/04/19 14:58:39 tom Exp $")
#if HAVE_SYS_TERMIO_H
#include <sys/termio.h> /* needed for ISC */
@@ -78,25 +73,27 @@
typedef struct {
unsigned int val;
- const char *name;
+ const char name[8];
} BITNAMES;
+#define TRACE_BUF_SIZE(num) (_nc_globals.tracebuf_ptr[num].size)
+
static void
lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int val)
{
const BITNAMES *sp;
- (void) strcat(buf, label);
- (void) strcat(buf, ": {");
- for (sp = table; sp->name; sp++)
+ _nc_STRCAT(buf, label, TRACE_BUF_SIZE(0));
+ _nc_STRCAT(buf, ": {", TRACE_BUF_SIZE(0));
+ for (sp = table; sp->name[0]; sp++)
if (sp->val != 0
&& (val & sp->val) == sp->val) {
- (void) strcat(buf, sp->name);
- (void) strcat(buf, ", ");
+ _nc_STRCAT(buf, sp->name, TRACE_BUF_SIZE(0));
+ _nc_STRCAT(buf, ", ", TRACE_BUF_SIZE(0));
}
if (buf[strlen(buf) - 2] == ',')
buf[strlen(buf) - 2] = '\0';
- (void) strcat(buf, "} ");
+ _nc_STRCAT(buf, "} ", TRACE_BUF_SIZE(0));
}
NCURSES_EXPORT(char *)
@@ -106,56 +103,59 @@
char *buf;
#ifdef TERMIOS
+#define DATA(name) { name, { #name } }
+#define DATA2(name,name2) { name, { #name2 } }
+#define DATAX() { 0, { "" } }
static const BITNAMES iflags[] =
{
- {BRKINT, "BRKINT"},
- {IGNBRK, "IGNBRK"},
- {IGNPAR, "IGNPAR"},
- {PARMRK, "PARMRK"},
- {INPCK, "INPCK"},
- {ISTRIP, "ISTRIP"},
- {INLCR, "INLCR"},
- {IGNCR, "IGNC"},
- {ICRNL, "ICRNL"},
- {IXON, "IXON"},
- {IXOFF, "IXOFF"},
- {0, NULL}
+ DATA(BRKINT),
+ DATA(IGNBRK),
+ DATA(IGNPAR),
+ DATA(PARMRK),
+ DATA(INPCK),
+ DATA(ISTRIP),
+ DATA(INLCR),
+ DATA(IGNCR),
+ DATA(ICRNL),
+ DATA(IXON),
+ DATA(IXOFF),
+ DATAX()
#define ALLIN (BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF)
}, oflags[] =
{
- {OPOST, "OPOST"},
- {OFLAGS_TABS, "XTABS"},
- {ONLCR, "ONLCR"},
- {OCRNL, "OCRNL"},
- {ONOCR, "ONOCR"},
- {ONLRET, "ONLRET"},
- {0, NULL}
+ DATA(OPOST),
+ DATA2(OFLAGS_TABS, XTABS),
+ DATA(ONLCR),
+ DATA(OCRNL),
+ DATA(ONOCR),
+ DATA(ONLRET),
+ DATAX()
#define ALLOUT (OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET)
}, cflags[] =
{
- {CLOCAL, "CLOCAL"},
- {CREAD, "CREAD"},
- {CSTOPB, "CSTOPB"},
+ DATA(CLOCAL),
+ DATA(CREAD),
+ DATA(CSTOPB),
#if !defined(CS5) || !defined(CS8)
- {CSIZE, "CSIZE"},
+ DATA(CSIZE),
#endif
- {HUPCL, "HUPCL"},
- {PARENB, "PARENB"},
- {PARODD | PARENB, "PARODD"}, /* concession to readability */
- {0, NULL}
+ DATA(HUPCL),
+ DATA(PARENB),
+ DATA2(PARODD | PARENB, PARODD),
+ DATAX()
#define ALLCTRL (CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD)
}, lflags[] =
{
- {ECHO, "ECHO"},
- {ECHOE | ECHO, "ECHOE"}, /* concession to readability */
- {ECHOK | ECHO, "ECHOK"}, /* concession to readability */
- {ECHONL, "ECHONL"},
- {ICANON, "ICANON"},
- {ISIG, "ISIG"},
- {NOFLSH, "NOFLSH"},
- {TOSTOP, "TOSTOP"},
- {IEXTEN, "IEXTEN"},
- {0, NULL}
+ DATA(ECHO),
+ DATA2(ECHOE | ECHO, ECHOE),
+ DATA2(ECHOK | ECHO, ECHOK),
+ DATA(ECHONL),
+ DATA(ICANON),
+ DATA(ISIG),
+ DATA(NOFLSH),
+ DATA(TOSTOP),
+ DATA(IEXTEN),
+ DATAX()
#define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
};
@@ -178,11 +178,11 @@
#if defined(CS5) && defined(CS8)
{
- static struct {
+ static const struct {
int value;
- const char *name;
+ const char name[5];
} csizes[] = {
-#define CS_DATA(name) { name, #name " " }
+#define CS_DATA(name) { name, { #name " " } }
CS_DATA(CS5),
#ifdef CS6
CS_DATA(CS6),
@@ -193,7 +193,7 @@
CS_DATA(CS8),
};
const char *result = "CSIZE? ";
- int value = (tty->c_cflag & CSIZE);
+ int value = (int) (tty->c_cflag & CSIZE);
unsigned n;
if (value != 0) {
@@ -204,7 +204,7 @@
}
}
}
- strcat(buf, result);
+ _nc_STRCAT(buf, result, TRACE_BUF_SIZE(0));
}
#endif
@@ -231,17 +231,17 @@
static const BITNAMES cflags[] =
{
- {CBREAK, "CBREAK"},
- {CRMOD, "CRMOD"},
- {ECHO, "ECHO"},
- {EVENP, "EVENP"},
- {LCASE, "LCASE"},
- {LLITOUT, "LLITOUT"},
- {ODDP, "ODDP"},
- {RAW, "RAW"},
- {TANDEM, "TANDEM"},
- {XTABS, "XTABS"},
- {0, NULL}
+ DATA(CBREAK),
+ DATA(CRMOD),
+ DATA(ECHO),
+ DATA(EVENP),
+ DATA(LCASE),
+ DATA(LLITOUT),
+ DATA(ODDP),
+ DATA(RAW),
+ DATA(TANDEM),
+ DATA(XTABS),
+ DATAX()
#define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
};
@@ -262,5 +262,5 @@
return _nc_trace_ttymode(&(cur_term->Nttyb));
}
#else
-EMPTY_MODULE(_nc_tracebits)
+EMPTY_MODULE(_nc_empty_lib_tracebits)
#endif /* TRACE */
diff --git a/ncurses/trace/lib_tracechr.c b/ncurses/trace/lib_tracechr.c
index 79cf03b..8977f75 100644
--- a/ncurses/trace/lib_tracechr.c
+++ b/ncurses/trace/lib_tracechr.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 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,10 +39,12 @@
#include <ctype.h>
-MODULE_ID("$Id: lib_tracechr.c,v 1.19 2008/08/03 15:39:29 tom Exp $")
+MODULE_ID("$Id: lib_tracechr.c,v 1.22 2012/02/22 22:40:24 tom Exp $")
#ifdef TRACE
+#define MyBufSize sizeof(_nc_globals.tracechr_buf)
+
NCURSES_EXPORT(char *)
_nc_tracechar(SCREEN *sp, int ch)
{
@@ -52,22 +54,25 @@
: _nc_globals.tracechr_buf);
if (ch > KEY_MIN || ch < 0) {
- name = _nc_keyname(sp, ch);
+ name = safe_keyname(SP_PARM, ch);
if (name == 0 || *name == '\0')
name = "NULL";
- (void) sprintf(MyBuffer, "'%.30s' = %#03o", name, ch);
+ _nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
+ "'%.30s' = %#03o", name, ch);
} else if (!is8bits(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.
*/
- (void) sprintf(MyBuffer, "%#03o", ch);
+ _nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
+ "%#03o", ch);
} else {
- name = _nc_unctrl(sp, (chtype) ch);
+ name = safe_unctrl(SP_PARM, (chtype) ch);
if (name == 0 || *name == 0)
name = "null"; /* shouldn't happen */
- (void) sprintf(MyBuffer, "'%.30s' = %#03o", name, ch);
+ _nc_SPRINTF(MyBuffer, _nc_SLIMIT(MyBufSize)
+ "'%.30s' = %#03o", name, ch);
}
return (MyBuffer);
}
@@ -75,7 +80,7 @@
NCURSES_EXPORT(char *)
_tracechar(int ch)
{
- return _nc_tracechar(SP, ch);
+ return _nc_tracechar(CURRENT_SCREEN, ch);
}
#else
EMPTY_MODULE(_nc_lib_tracechr)
diff --git a/ncurses/trace/lib_tracedmp.c b/ncurses/trace/lib_tracedmp.c
index 58732a0..0fda15b 100644
--- a/ncurses/trace/lib_tracedmp.c
+++ b/ncurses/trace/lib_tracedmp.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 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 +39,7 @@
#include <curses.priv.h>
#include <ctype.h>
-MODULE_ID("$Id: lib_tracedmp.c,v 1.31 2008/08/16 19:30:56 tom Exp $")
+MODULE_ID("$Id: lib_tracedmp.c,v 1.34 2012/10/27 20:54:42 tom Exp $")
#ifdef TRACE
@@ -68,8 +68,10 @@
if (width < win->_maxx)
++width;
if (++width + 1 > (int) my_length) {
- my_length = 2 * (width + 1);
+ my_length = (unsigned) (2 * (width + 1));
my_buffer = typeRealloc(char, my_length, my_buffer);
+ if (my_buffer == 0)
+ return;
}
for (n = 0; n <= win->_maxy; ++n) {
@@ -82,7 +84,7 @@
* we map those to '.' and '?' respectively.
*/
for (j = 0; j < width; ++j) {
- chtype test = CharOf(win->_line[n].text[j]);
+ chtype test = (chtype) CharOf(win->_line[n].text[j]);
ep[j] = (char) ((UChar(test) == test
#if USE_WIDEC_SUPPORT
&& (win->_line[n].text[j].chars[1] == 0)
@@ -153,7 +155,7 @@
for (i = 0; i < 4; ++i) {
const char *hex = " 123456789ABCDEF";
- attr_t mask = (0xf << ((i + 4) * 4));
+ attr_t mask = (attr_t) (0xf << ((i + 4) * 4));
haveattrs = FALSE;
for (j = 0; j < width; ++j)
diff --git a/ncurses/trace/lib_tracemse.c b/ncurses/trace/lib_tracemse.c
index 74cc177..c62b71a 100644
--- a/ncurses/trace/lib_tracemse.c
+++ b/ncurses/trace/lib_tracemse.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 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,23 +38,22 @@
#include <curses.priv.h>
-MODULE_ID("$Id: lib_tracemse.c,v 1.15 2008/08/03 15:39:29 tom Exp $")
+MODULE_ID("$Id: lib_tracemse.c,v 1.22 2014/10/10 09:06:26 tom Exp $")
#ifdef TRACE
#define my_buffer sp->tracemse_buf
NCURSES_EXPORT(char *)
-_nc_tracemouse(SCREEN *sp, MEVENT const *ep)
+_nc_trace_mmask_t(SCREEN *sp, mmask_t code)
{
- (void) sprintf(my_buffer, TRACEMSE_FMT,
- ep->id,
- ep->x,
- ep->y,
- ep->z,
- (unsigned long) ep->bstate);
-
-#define SHOW(m, s) if ((ep->bstate & m) == m) strcat(strcat(my_buffer, s), ", ")
+#define SHOW(m, s) \
+ if ((code & m) == m) { \
+ size_t n = strlen(my_buffer); \
+ if (n && (my_buffer[n-1] != '{')) \
+ _nc_STRCAT(my_buffer, ", ", sizeof(my_buffer)); \
+ _nc_STRCAT(my_buffer, s, sizeof(my_buffer)); \
+ }
SHOW(BUTTON1_RELEASED, "release-1");
SHOW(BUTTON1_PRESSED, "press-1");
@@ -110,14 +109,47 @@
if (my_buffer[strlen(my_buffer) - 1] == ' ')
my_buffer[strlen(my_buffer) - 2] = '\0';
- (void) strcat(my_buffer, "}");
+
return (my_buffer);
}
NCURSES_EXPORT(char *)
+_nc_tracemouse(SCREEN *sp, MEVENT const *ep)
+{
+ char *result = 0;
+
+ if (sp != 0) {
+ _nc_SPRINTF(my_buffer, _nc_SLIMIT(sizeof(my_buffer))
+ TRACEMSE_FMT,
+ ep->id,
+ ep->x,
+ ep->y,
+ ep->z,
+ (unsigned long) ep->bstate);
+
+ (void) _nc_trace_mmask_t(sp, ep->bstate);
+ _nc_STRCAT(my_buffer, "}", sizeof(my_buffer));
+ result = (my_buffer);
+ }
+ return result;
+}
+
+NCURSES_EXPORT(mmask_t)
+_nc_retrace_mmask_t(SCREEN *sp, mmask_t code)
+{
+ if (sp != 0) {
+ *my_buffer = '\0';
+ T((T_RETURN("{%s}"), _nc_trace_mmask_t(sp, code)));
+ } else {
+ T((T_RETURN("{?}")));
+ }
+ return code;
+}
+
+NCURSES_EXPORT(char *)
_tracemouse(MEVENT const *ep)
{
- return _nc_tracemouse(SP, ep);
+ return _nc_tracemouse(CURRENT_SCREEN, ep);
}
#else /* !TRACE */
diff --git a/ncurses/trace/trace_buf.c b/ncurses/trace/trace_buf.c
index 6345acc..84a7a0c 100644
--- a/ncurses/trace/trace_buf.c
+++ b/ncurses/trace/trace_buf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 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 +35,9 @@
#include <curses.priv.h>
-MODULE_ID("$Id: trace_buf.c,v 1.14 2008/08/03 15:13:56 tom Exp $")
+MODULE_ID("$Id: trace_buf.c,v 1.20 2012/02/22 22:34:31 tom Exp $")
+
+#ifdef TRACE
#define MyList _nc_globals.tracebuf_ptr
#define MySize _nc_globals.tracebuf_used
@@ -47,7 +49,7 @@
if (bufnum >= 0) {
if ((size_t) (bufnum + 1) > MySize) {
- size_t need = (bufnum + 1) * 2;
+ size_t need = (size_t) (bufnum + 1) * 2;
if ((MyList = typeRealloc(TRACEBUF, need, MyList)) != 0) {
while (need > MySize)
MyList[MySize++].text = 0;
@@ -101,14 +103,18 @@
NCURSES_EXPORT(char *)
_nc_trace_bufcat(int bufnum, const char *value)
{
- char *buffer = _nc_trace_alloc(bufnum, 0);
+ char *buffer = _nc_trace_alloc(bufnum, (size_t) 0);
if (buffer != 0) {
size_t have = strlen(buffer);
+ size_t need = strlen(value) + have;
- buffer = _nc_trace_alloc(bufnum, 1 + have + strlen(value));
+ buffer = _nc_trace_alloc(bufnum, 1 + need);
if (buffer != 0)
- (void) strcpy(buffer + have, value);
+ _nc_STRCPY(buffer + have, value, need);
}
return buffer;
}
+#else
+EMPTY_MODULE(_nc_empty_trace_buf)
+#endif /* TRACE */
diff --git a/ncurses/trace/trace_tries.c b/ncurses/trace/trace_tries.c
index f813aba..50ba016 100644
--- a/ncurses/trace/trace_tries.c
+++ b/ncurses/trace/trace_tries.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1999-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 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 *
@@ -27,7 +27,7 @@
****************************************************************************/
/****************************************************************************
- * Author: Thomas E. Dickey <dickey@clark.net> 1999 *
+ * Author: Thomas E. Dickey 1999 *
****************************************************************************/
/*
* trace_tries.c - Tracing/Debugging buffers (keycode tries-trees)
@@ -35,7 +35,7 @@
#include <curses.priv.h>
-MODULE_ID("$Id: trace_tries.c,v 1.13 2008/08/03 15:43:30 tom Exp $")
+MODULE_ID("$Id: trace_tries.c,v 1.17 2012/10/27 20:50:50 tom Exp $")
#ifdef TRACE
#define my_buffer _nc_globals.tracetry_buf
@@ -46,33 +46,36 @@
{
if (level > my_length) {
my_length = (level + 1) * 4;
- my_buffer = (unsigned char *) realloc(my_buffer, my_length);
+ my_buffer = (unsigned char *) _nc_doalloc(my_buffer, my_length);
}
- while (tree != 0) {
- if ((my_buffer[level] = tree->ch) == 0)
- my_buffer[level] = 128;
- my_buffer[level + 1] = 0;
- if (tree->value != 0) {
- _tracef("%5d: %s (%s)", tree->value,
- _nc_visbuf((char *) my_buffer), keyname(tree->value));
+ if (my_buffer != 0) {
+ while (tree != 0) {
+ if ((my_buffer[level] = tree->ch) == 0)
+ my_buffer[level] = 128;
+ my_buffer[level + 1] = 0;
+ if (tree->value != 0) {
+ _tracef("%5d: %s (%s)", tree->value,
+ _nc_visbuf((char *) my_buffer), keyname(tree->value));
+ }
+ if (tree->child)
+ recur_tries(tree->child, level + 1);
+ tree = tree->sibling;
}
- if (tree->child)
- recur_tries(tree->child, level + 1);
- tree = tree->sibling;
}
}
NCURSES_EXPORT(void)
_nc_trace_tries(TRIES * tree)
{
- my_buffer = typeMalloc(unsigned char, my_length = 80);
- _tracef("BEGIN tries %p", tree);
- recur_tries(tree, 0);
- _tracef(". . . tries %p", tree);
- free(my_buffer);
+ if ((my_buffer = typeMalloc(unsigned char, my_length = 80)) != 0) {
+ _tracef("BEGIN tries %p", (void *) tree);
+ recur_tries(tree, 0);
+ _tracef(". . . tries %p", (void *) tree);
+ free(my_buffer);
+ }
}
#else
-EMPTY_MODULE(_nc_trace_tries)
+EMPTY_MODULE(_nc_empty_trace_tries)
#endif
diff --git a/ncurses/trace/trace_xnames.c b/ncurses/trace/trace_xnames.c
index 9b0b592..38a4873 100644
--- a/ncurses/trace/trace_xnames.c
+++ b/ncurses/trace/trace_xnames.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1999,2000 Free Software Foundation, Inc. *
+ * Copyright (c) 1999-2000,2010 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,12 +34,11 @@
*/
#include <curses.priv.h>
-#include <term_entry.h>
-MODULE_ID("$Id: trace_xnames.c,v 1.5 2000/12/10 03:02:45 tom Exp $")
+MODULE_ID("$Id: trace_xnames.c,v 1.6 2010/01/23 17:59:27 tom Exp $")
NCURSES_EXPORT(void)
-_nc_trace_xnames(TERMTYPE * tp GCC_UNUSED)
+_nc_trace_xnames(TERMTYPE *tp GCC_UNUSED)
{
#ifdef TRACE
#if NCURSES_XNAMES
diff --git a/ncurses/trace/varargs.c b/ncurses/trace/varargs.c
index f4ee467..66252d8 100644
--- a/ncurses/trace/varargs.c
+++ b/ncurses/trace/varargs.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 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 +34,7 @@
#include <ctype.h>
-MODULE_ID("$Id: varargs.c,v 1.7 2008/08/03 15:42:49 tom Exp $")
+MODULE_ID("$Id: varargs.c,v 1.11 2012/10/27 21:03:28 tom Exp $")
#ifdef TRACE
@@ -44,7 +44,7 @@
atUnknown = 0, atInteger, atFloat, atPoint, atString
} ARGTYPE;
-#define VA_INT(type) ival = va_arg(ap, type)
+#define VA_INT(type) ival = (int) va_arg(ap, type)
#define VA_FLT(type) fval = va_arg(ap, type)
#define VA_PTR(type) pval = (char *)va_arg(ap, type)
#define VA_STR(type) sval = va_arg(ap, type)
@@ -149,25 +149,32 @@
param = buffer;
switch (used) {
case atInteger:
- sprintf(buffer, "%d", ival);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+ "%d", ival);
break;
case atFloat:
- sprintf(buffer, "%f", fval);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+ "%f", fval);
break;
case atPoint:
- sprintf(buffer, "%p", pval);
+ _nc_SPRINTF(buffer, _nc_SLIMIT(sizeof(buffer))
+ "%p", pval);
break;
case atString:
param = _nc_visbuf2(1, sval);
break;
case atUnknown:
default:
- strcpy(buffer, "?");
+ _nc_STRCPY(buffer, "?", sizeof(buffer));
break;
}
MyLength += strlen(param) + 2;
MyBuffer = typeRealloc(char, MyLength, MyBuffer);
- sprintf(MyBuffer + strlen(MyBuffer), ", %s", param);
+ if (MyBuffer != 0) {
+ _nc_SPRINTF(MyBuffer + strlen(MyBuffer),
+ _nc_SLIMIT(MyLength - strlen(MyBuffer))
+ ", %s", param);
+ }
}
}
used = atUnknown;
@@ -177,7 +184,7 @@
}
}
- return (MyBuffer);
+ return (MyBuffer ? MyBuffer : dummy);
}
#else
EMPTY_MODULE(_nc_varargs)
diff --git a/ncurses/trace/visbuf.c b/ncurses/trace/visbuf.c
index bf9fb14..fec0643 100644
--- a/ncurses/trace/visbuf.c
+++ b/ncurses/trace/visbuf.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 2001-2007,2008 Free Software Foundation, Inc. *
+ * Copyright (c) 2001-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 *
@@ -42,10 +42,12 @@
#include <tic.h>
#include <ctype.h>
-MODULE_ID("$Id: visbuf.c,v 1.32 2008/08/04 23:07:39 tom Exp $")
+MODULE_ID("$Id: visbuf.c,v 1.44 2014/09/25 08:51:13 tom Exp $")
+
+#define NUM_VISBUFS 4
#define NormalLen(len) (size_t) (((size_t)(len) + 1) * 4)
-#define WideLen(len) (size_t) (((size_t)(len) + 1) * 4 * MB_CUR_MAX)
+#define WideLen(len) (size_t) (((size_t)(len) + 1) * 4 * (size_t) MB_CUR_MAX)
#ifdef TRACE
static const char d_quote[] = StringOf(D_QUOTE);
@@ -53,13 +55,21 @@
static const char r_brace[] = StringOf(R_BRACE);
#endif
+#if USE_STRING_HACKS && HAVE_SNPRINTF
+#define VisChar(tp, chr, limit) _nc_vischar(tp, chr, limit)
+#define LIMIT_ARG ,size_t limit
+#else
+#define VisChar(tp, chr, limit) _nc_vischar(tp, chr)
+#define LIMIT_ARG /* nothing */
+#endif
+
static char *
-_nc_vischar(char *tp, unsigned c)
+_nc_vischar(char *tp, unsigned c LIMIT_ARG)
{
if (c == '"' || c == '\\') {
*tp++ = '\\';
*tp++ = (char) c;
- } else if (is7bits(c) && (isgraph(c) || c == ' ')) {
+ } else if (is7bits((int) c) && (isgraph((int) c) || c == ' ')) {
*tp++ = (char) c;
} else if (c == '\n') {
*tp++ = '\\';
@@ -82,7 +92,8 @@
*tp++ = '^';
*tp++ = (char) ('@' + c);
} else {
- sprintf(tp, "\\%03lo", (unsigned long) ChCharOf(c));
+ _nc_SPRINTF(tp, _nc_SLIMIT(limit)
+ "\\%03lo", (unsigned long) ChCharOf(c));
tp += strlen(tp);
}
*tp = 0;
@@ -92,9 +103,10 @@
static const char *
_nc_visbuf2n(int bufnum, const char *buf, int len)
{
- const char *vbuf;
+ const char *vbuf = 0;
char *tp;
int c;
+ int count;
if (buf == 0)
return ("(null)");
@@ -104,22 +116,30 @@
if (len < 0)
len = (int) strlen(buf);
+ count = len;
#ifdef TRACE
vbuf = tp = _nc_trace_buf(bufnum, NormalLen(len));
#else
{
- static char *mybuf[4];
- mybuf[bufnum] = typeRealloc(char, NormalLen(len), mybuf[bufnum]);
- vbuf = tp = mybuf[bufnum];
+ static char *mybuf[NUM_VISBUFS];
+ if (bufnum < 0) {
+ for (c = 0; c < NUM_VISBUFS; ++c) {
+ FreeAndNull(mybuf[c]);
+ }
+ tp = 0;
+ } else {
+ mybuf[bufnum] = typeRealloc(char, NormalLen(len), mybuf[bufnum]);
+ vbuf = tp = mybuf[bufnum];
+ }
}
#endif
if (tp != 0) {
*tp++ = D_QUOTE;
- while ((--len >= 0) && (c = *buf++) != '\0') {
- tp = _nc_vischar(tp, UChar(c));
+ while ((--count >= 0) && (c = *buf++) != '\0') {
+ tp = VisChar(tp, UChar(c), NormalLen(len));
}
*tp++ = D_QUOTE;
- *tp++ = '\0';
+ *tp = '\0';
} else {
vbuf = ("(_nc_visbuf2n failed)");
}
@@ -166,6 +186,7 @@
const char *vbuf;
char *tp;
wchar_t c;
+ int count;
if (buf == 0)
return ("(null)");
@@ -173,30 +194,32 @@
if (len < 0)
len = (int) wcslen(buf);
+ count = len;
#ifdef TRACE
vbuf = tp = _nc_trace_buf(bufnum, WideLen(len));
#else
{
- static char *mybuf[2];
+ static char *mybuf[NUM_VISBUFS];
mybuf[bufnum] = typeRealloc(char, WideLen(len), mybuf[bufnum]);
vbuf = tp = mybuf[bufnum];
}
#endif
if (tp != 0) {
*tp++ = D_QUOTE;
- while ((--len >= 0) && (c = *buf++) != '\0') {
+ while ((--count >= 0) && (c = *buf++) != '\0') {
char temp[CCHARW_MAX + 80];
int j = wctomb(temp, c), k;
if (j <= 0) {
- sprintf(temp, "\\u%08X", (unsigned) c);
+ _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
+ "\\u%08X", (unsigned) c);
j = (int) strlen(temp);
}
for (k = 0; k < j; ++k) {
- tp = _nc_vischar(tp, UChar(temp[k]));
+ tp = VisChar(tp, UChar(temp[k]), WideLen(len));
}
}
*tp++ = D_QUOTE;
- *tp++ = '\0';
+ *tp = '\0';
} else {
vbuf = ("(_nc_viswbuf2n failed)");
}
@@ -229,7 +252,9 @@
static unsigned mylen;
unsigned n;
- for (n = 0; buf[n] != 0; ++n) ;
+ for (n = 0; buf[n] != 0; ++n) {
+ ; /* empty */
+ }
if (mylen < ++n) {
mylen = n + 80;
if (mybuf != 0)
@@ -237,8 +262,12 @@
else
mybuf = typeMalloc(wchar_t, mylen);
}
- for (n = 0; buf[n] != 0; ++n)
- mybuf[n] = (wchar_t) buf[n];
+ if (mybuf != 0) {
+ for (n = 0; buf[n] != 0; ++n) {
+ mybuf[n] = (wchar_t) buf[n];
+ }
+ mybuf[n] = L'\0';
+ }
return _nc_viswbuf2(0, mybuf);
}
@@ -248,7 +277,7 @@
NCURSES_EXPORT(const char *)
_nc_viscbuf2(int bufnum, const NCURSES_CH_T * buf, int len)
{
- char *result = _nc_trace_buf(bufnum, BUFSIZ);
+ char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ);
int first;
const char *found;
@@ -274,12 +303,12 @@
}
}
- result = _nc_trace_bufcat(bufnum, l_brace);
- result = _nc_trace_bufcat(bufnum, d_quote);
+ (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]));
if (found != 0) {
- result = _nc_trace_bufcat(bufnum, found);
+ (void) _nc_trace_bufcat(bufnum, found);
attr &= ~A_ALTCHARSET;
} else
#if USE_WIDEC_SUPPORT
@@ -291,30 +320,34 @@
int k;
PUTC_ch = buf[j].chars[PUTC_i];
- if (PUTC_ch == L'\0')
+ if (PUTC_ch == L'\0') {
+ if (PUTC_i == 0)
+ (void) _nc_trace_bufcat(bufnum, "\\000");
break;
- PUTC_n = (int) wcrtomb(PUTC_buf, buf[j].chars[PUTC_i], &PUT_st);
+ }
+ PUTC_n = (int) wcrtomb(PUTC_buf,
+ buf[j].chars[PUTC_i], &PUT_st);
if (PUTC_n <= 0)
break;
for (k = 0; k < PUTC_n; k++) {
char temp[80];
- _nc_vischar(temp, UChar(PUTC_buf[k]));
- result = _nc_trace_bufcat(bufnum, temp);
+ VisChar(temp, UChar(PUTC_buf[k]), sizeof(temp));
+ (void) _nc_trace_bufcat(bufnum, temp);
}
}
}
#else
{
char temp[80];
- _nc_vischar(temp, UChar(buf[j]));
- result = _nc_trace_bufcat(bufnum, temp);
+ VisChar(temp, UChar(buf[j]), sizeof(temp));
+ (void) _nc_trace_bufcat(bufnum, temp);
}
#endif /* USE_WIDEC_SUPPORT */
}
- result = _nc_trace_bufcat(bufnum, d_quote);
+ (void) _nc_trace_bufcat(bufnum, d_quote);
if (attr != A_NORMAL) {
- result = _nc_trace_bufcat(bufnum, " | ");
- result = _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr));
+ (void) _nc_trace_bufcat(bufnum, " | ");
+ (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr));
}
result = _nc_trace_bufcat(bufnum, r_brace);
first = last + 1;