aboutsummaryrefslogtreecommitdiff
path: root/ncurses/trace
diff options
context:
space:
mode:
Diffstat (limited to 'ncurses/trace')
-rw-r--r--ncurses/trace/README33
-rw-r--r--ncurses/trace/lib_trace.c328
-rw-r--r--ncurses/trace/lib_traceatr.c344
-rw-r--r--ncurses/trace/lib_tracebits.c271
-rw-r--r--ncurses/trace/lib_tracechr.c74
-rw-r--r--ncurses/trace/lib_tracedmp.c184
-rw-r--r--ncurses/trace/lib_tracemse.c119
-rw-r--r--ncurses/trace/trace_buf.c105
-rw-r--r--ncurses/trace/trace_tries.c78
-rw-r--r--ncurses/trace/trace_xnames.c75
-rw-r--r--ncurses/trace/varargs.c184
-rw-r--r--ncurses/trace/visbuf.c321
12 files changed, 2116 insertions, 0 deletions
diff --git a/ncurses/trace/README b/ncurses/trace/README
new file mode 100644
index 000000000000..e658feccb873
--- /dev/null
+++ b/ncurses/trace/README
@@ -0,0 +1,33 @@
+-------------------------------------------------------------------------------
+-- Copyright (c) 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 --
+-- "Software"), to deal in the Software without restriction, including --
+-- without limitation the rights to use, copy, modify, merge, publish, --
+-- distribute, distribute with modifications, sublicense, and/or sell copies --
+-- of the Software, and to permit persons to whom the Software is furnished --
+-- to do so, subject to the following conditions: --
+-- --
+-- The above copyright notice and this permission notice shall be included --
+-- in all copies or substantial portions of the Software. --
+-- --
+-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS --
+-- OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF --
+-- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN --
+-- NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, --
+-- DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR --
+-- OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE --
+-- USE OR OTHER DEALINGS IN THE SOFTWARE. --
+-- --
+-- Except as contained in this notice, the name(s) of the above copyright --
+-- holders shall not be used in advertising or otherwise to promote the --
+-- 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 $
+-------------------------------------------------------------------------------
+
+The files in this directory (trace) support both the terminfo and ncurses
+libraries. Most of the functions are linked in only when the libraries
+are compiled with TRACE defined.
diff --git a/ncurses/trace/lib_trace.c b/ncurses/trace/lib_trace.c
new file mode 100644
index 000000000000..03acb16cba91
--- /dev/null
+++ b/ncurses/trace/lib_trace.c
@@ -0,0 +1,328 @@
+/****************************************************************************
+ * Copyright (c) 1998-2007,2008 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 *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+ * lib_trace.c - Tracing/Debugging routines
+ *
+ * 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.
+ */
+
+#include <curses.priv.h>
+#include <tic.h>
+
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_trace.c,v 1.66 2008/03/22 16:56:48 tom Exp $")
+
+NCURSES_EXPORT_VAR(unsigned) _nc_tracing = 0; /* always define this */
+
+#ifdef TRACE
+
+#if USE_REENTRANT
+NCURSES_EXPORT(const char *)
+NCURSES_PUBLIC_VAR(_nc_tputs_trace) (void)
+{
+ return SP ? SP->_tputs_trace : _nc_prescreen._tputs_trace;
+}
+NCURSES_EXPORT(long)
+NCURSES_PUBLIC_VAR(_nc_outchars) (void)
+{
+ return SP ? SP->_outchars : _nc_prescreen._outchars;
+}
+NCURSES_EXPORT(void)
+_nc_set_tputs_trace(const char *s)
+{
+ if (SP)
+ SP->_tputs_trace = s;
+ else
+ _nc_prescreen._tputs_trace = s;
+}
+NCURSES_EXPORT(void)
+_nc_count_outchars(long increment)
+{
+ if (SP)
+ SP->_outchars += increment;
+ else
+ _nc_prescreen._outchars += increment;
+}
+#else
+NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace = "";
+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
+
+NCURSES_EXPORT(void)
+trace(const unsigned int tracelevel)
+{
+ if ((TraceFP == 0) && tracelevel) {
+ const char *mode = _nc_globals.init_trace ? "ab" : "wb";
+
+ if (TracePath[0] == '\0') {
+ if (getcwd(TracePath, sizeof(TracePath) - 12) == 0) {
+ perror("curses: Can't get working directory");
+ exit(EXIT_FAILURE);
+ }
+ strcat(TracePath, "/trace");
+ if (_nc_is_dir_path(TracePath)) {
+ strcat(TracePath, ".log");
+ }
+ }
+
+ _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);
+ }
+ /* 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.
+ */
+#if HAVE_SETVBUF /* ANSI */
+ (void) setvbuf(TraceFP, (char *) 0, _IOLBF, 0);
+#elif HAVE_SETBUF /* POSIX */
+ (void) setbuffer(TraceFP, (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;
+ }
+ _nc_tracing = tracelevel;
+ } else if (_nc_tracing != tracelevel) {
+ _nc_tracing = tracelevel;
+ _tracef("tracelevel=%#x", tracelevel);
+ }
+}
+
+static void
+_nc_va_tracef(const char *fmt, va_list ap)
+{
+ static const char Called[] = T_CALLED("");
+ static const char Return[] = T_RETURN("");
+
+ bool before = FALSE;
+ bool after = FALSE;
+ unsigned doit = _nc_tracing;
+ int save_err = errno;
+
+ if (strlen(fmt) >= sizeof(Called) - 1) {
+ if (!strncmp(fmt, Called, sizeof(Called) - 1)) {
+ before = TRUE;
+ TraceLevel++;
+ } else if (!strncmp(fmt, Return, sizeof(Return) - 1)) {
+ after = TRUE;
+ }
+ if (before || after) {
+ if ((TraceLevel <= 1)
+ || (doit & TRACE_ICALLS) != 0)
+ doit &= (TRACE_CALLS | TRACE_CCALLS);
+ else
+ doit = 0;
+ }
+ }
+
+ if (doit != 0) {
+ if (TraceFP == 0)
+ TraceFP = stderr;
+#ifdef USE_PTHREADS
+ /*
+ * TRACE_ICALLS is "really" needed to show normal use with threaded
+ * applications, since anything can be running during a napms(),
+ * making it appear in the hierarchical trace as it other functions
+ * are being called.
+ *
+ * Rather than add the complication of a per-thread stack, just
+ * show the thread-id in each line of the trace.
+ */
+ fprintf(TraceFP, "%#lx:", (long) pthread_self());
+#endif
+ if (before || after) {
+ int n;
+ for (n = 1; n < TraceLevel; n++)
+ fputs("+ ", TraceFP);
+ }
+ vfprintf(TraceFP, fmt, ap);
+ fputc('\n', TraceFP);
+ fflush(TraceFP);
+ }
+
+ if (after && TraceLevel)
+ TraceLevel--;
+
+ errno = save_err;
+}
+
+NCURSES_EXPORT(void)
+_tracef(const char *fmt,...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ _nc_va_tracef(fmt, ap);
+ va_end(ap);
+}
+
+/* Trace 'bool' return-values */
+NCURSES_EXPORT(NCURSES_BOOL)
+_nc_retrace_bool(NCURSES_BOOL code)
+{
+ T((T_RETURN("%s"), code ? "TRUE" : "FALSE"));
+ return code;
+}
+
+/* Trace 'int' return-values */
+NCURSES_EXPORT(int)
+_nc_retrace_int(int code)
+{
+ T((T_RETURN("%d"), code));
+ return code;
+}
+
+/* Trace 'unsigned' return-values */
+NCURSES_EXPORT(unsigned)
+_nc_retrace_unsigned(unsigned code)
+{
+ T((T_RETURN("%#x"), code));
+ return code;
+}
+
+/* Trace 'char*' return-values */
+NCURSES_EXPORT(char *)
+_nc_retrace_ptr(char *code)
+{
+ T((T_RETURN("%s"), _nc_visbuf(code)));
+ return code;
+}
+
+/* Trace 'const char*' return-values */
+NCURSES_EXPORT(const char *)
+_nc_retrace_cptr(const char *code)
+{
+ T((T_RETURN("%s"), _nc_visbuf(code)));
+ return code;
+}
+
+/* Trace 'NCURSES_CONST void*' return-values */
+NCURSES_EXPORT(NCURSES_CONST void *)
+_nc_retrace_cvoid_ptr(NCURSES_CONST void *code)
+{
+ T((T_RETURN("%p"), code));
+ return code;
+}
+
+/* Trace 'void*' return-values */
+NCURSES_EXPORT(void *)
+_nc_retrace_void_ptr(void *code)
+{
+ T((T_RETURN("%p"), code));
+ return code;
+}
+
+/* Trace 'SCREEN *' return-values */
+NCURSES_EXPORT(SCREEN *)
+_nc_retrace_sp(SCREEN *code)
+{
+ T((T_RETURN("%p"), code));
+ return code;
+}
+
+/* Trace 'WINDOW *' return-values */
+NCURSES_EXPORT(WINDOW *)
+_nc_retrace_win(WINDOW *code)
+{
+ T((T_RETURN("%p"), code));
+ return code;
+}
+
+#if USE_REENTRANT
+/*
+ * Check if the given trace-mask is enabled.
+ *
+ * This function may be called from within one of the functions that fills
+ * in parameters for _tracef(), but in that case we do not want to lock the
+ * mutex, since it is already locked.
+ */
+NCURSES_EXPORT(int)
+_nc_use_tracef(unsigned mask)
+{
+ bool result = FALSE;
+
+ _nc_lock_global(tst_tracef);
+ if (!_nc_globals.nested_tracef++) {
+ if ((result = (_nc_tracing & (mask))) != 0) {
+ /* we will call _nc_locked_tracef(), no nesting so far */
+ _nc_lock_global(tracef);
+ } else {
+ /* we will not call _nc_locked_tracef() */
+ _nc_globals.nested_tracef = 0;
+ }
+ } else {
+ /* we may call _nc_locked_tracef(), but with nested_tracef > 0 */
+ result = (_nc_tracing & (mask));
+ }
+ _nc_unlock_global(tst_tracef);
+ return result;
+}
+
+/*
+ * We call this if _nc_use_tracef() returns true, which means we must unlock
+ * the tracef mutex.
+ */
+NCURSES_EXPORT(void)
+_nc_locked_tracef(const char *fmt,...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ _nc_va_tracef(fmt, ap);
+ va_end(ap);
+
+ if (--(_nc_globals.nested_tracef) == 0)
+ _nc_unlock_global(tracef);
+}
+#endif /* USE_REENTRANT */
+
+#endif /* TRACE */
diff --git a/ncurses/trace/lib_traceatr.c b/ncurses/trace/lib_traceatr.c
new file mode 100644
index 000000000000..108eb8b4d335
--- /dev/null
+++ b/ncurses/trace/lib_traceatr.c
@@ -0,0 +1,344 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 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 *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas Dickey 1996-on *
+ * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+ * lib_traceatr.c - Tracing/Debugging routines (attributes)
+ */
+
+#include <curses.priv.h>
+#include <term.h> /* acs_chars */
+
+MODULE_ID("$Id: lib_traceatr.c,v 1.59 2007/06/09 17:22:10 tom Exp $")
+
+#define COLOR_OF(c) ((c < 0) ? "default" : (c > 7 ? color_of(c) : colors[c].name))
+
+#ifdef TRACE
+
+static const char l_brace[] = StringOf(L_BRACE);
+static const char r_brace[] = StringOf(R_BRACE);
+
+#ifndef USE_TERMLIB
+
+#define my_buffer _nc_globals.traceatr_color_buf
+#define my_select _nc_globals.traceatr_color_sel
+#define my_cached _nc_globals.traceatr_color_last
+
+static char *
+color_of(int c)
+{
+ if (c != my_cached) {
+ my_cached = c;
+ my_select = !my_select;
+ if (c == COLOR_DEFAULT)
+ strcpy(my_buffer[my_select], "default");
+ else
+ sprintf(my_buffer[my_select], "color%d", c);
+ }
+ return my_buffer[my_select];
+}
+
+#undef my_buffer
+#undef my_select
+#endif /* !USE_TERMLIB */
+
+NCURSES_EXPORT(char *)
+_traceattr2(int bufnum, chtype newmode)
+{
+ char *buf = _nc_trace_buf(bufnum, BUFSIZ);
+ char temp[80];
+ static const struct {
+ unsigned int val;
+ const char *name;
+ } 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* */
+
+ }
+#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* */
+
+ }
+#endif /* !USE_TERMLIB */
+ ;
+ size_t n;
+ unsigned save_nc_tracing = _nc_tracing;
+ _nc_tracing = 0;
+
+ strcpy(buf, l_brace);
+
+ for (n = 0; n < SIZEOF(names); n++) {
+ if ((newmode & names[n].val) != 0) {
+ if (buf[1] != '\0')
+ buf = _nc_trace_bufcat(bufnum, "|");
+ buf = _nc_trace_bufcat(bufnum, names[n].name);
+
+ if (names[n].val == A_COLOR) {
+ short pairnum = PAIR_NUMBER(newmode);
+#ifdef USE_TERMLIB
+ /* pair_content lives in libncurses */
+ (void) sprintf(temp, "{%d}", pairnum);
+#else
+ short fg, bg;
+
+ if (pair_content(pairnum, &fg, &bg) == OK) {
+ (void) sprintf(temp,
+ "{%d = {%s, %s}}",
+ pairnum,
+ COLOR_OF(fg),
+ COLOR_OF(bg));
+ } else {
+ (void) sprintf(temp, "{%d}", pairnum);
+ }
+#endif
+ buf = _nc_trace_bufcat(bufnum, temp);
+ }
+ }
+ }
+ if (ChAttrOf(newmode) == A_NORMAL) {
+ if (buf[1] != '\0')
+ (void) _nc_trace_bufcat(bufnum, "|");
+ (void) _nc_trace_bufcat(bufnum, "A_NORMAL");
+ }
+
+ _nc_tracing = save_nc_tracing;
+ return (_nc_trace_bufcat(bufnum, r_brace));
+}
+
+NCURSES_EXPORT(char *)
+_traceattr(attr_t newmode)
+{
+ return _traceattr2(0, newmode);
+}
+
+/* Trace 'int' return-values */
+NCURSES_EXPORT(attr_t)
+_nc_retrace_attr_t(attr_t code)
+{
+ T((T_RETURN("%s"), _traceattr(code)));
+ return code;
+}
+
+const char *
+_nc_altcharset_name(attr_t attr, chtype ch)
+{
+ typedef struct {
+ unsigned int val;
+ const char *name;
+ } ALT_NAMES;
+
+ const char *result = 0;
+
+ if ((attr & A_ALTCHARSET) && (acs_chars != 0)) {
+ char *cp;
+ char *found = 0;
+ /* *INDENT-OFF* */
+ 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 }
+ };
+ /* *INDENT-OFF* */
+ const ALT_NAMES *sp;
+
+ for (cp = acs_chars; cp[0] && cp[1]; cp += 2) {
+ if (ChCharOf(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;
+ break;
+ }
+ }
+ }
+ return result;
+}
+
+NCURSES_EXPORT(char *)
+_tracechtype2(int bufnum, chtype ch)
+{
+ const char *found;
+
+ strcpy(_nc_trace_buf(bufnum, BUFSIZ), l_brace);
+ if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) {
+ (void) _nc_trace_bufcat(bufnum, found);
+ } else
+ (void) _nc_trace_bufcat(bufnum, _tracechar((int)ChCharOf(ch)));
+
+ if (ChAttrOf(ch) != A_NORMAL) {
+ (void) _nc_trace_bufcat(bufnum, " | ");
+ (void) _nc_trace_bufcat(bufnum,
+ _traceattr2(bufnum + 20, ChAttrOf(ch)));
+ }
+
+ return (_nc_trace_bufcat(bufnum, r_brace));
+}
+
+NCURSES_EXPORT(char *)
+_tracechtype (chtype ch)
+{
+ return _tracechtype2(0, ch);
+}
+
+/* Trace 'chtype' return-values */
+NCURSES_EXPORT(chtype)
+_nc_retrace_chtype (chtype code)
+{
+ T((T_RETURN("%s"), _tracechtype(code)));
+ return code;
+}
+
+#if USE_WIDEC_SUPPORT
+NCURSES_EXPORT(char *)
+_tracecchar_t2 (int bufnum, const cchar_t *ch)
+{
+ char *buf = _nc_trace_buf(bufnum, BUFSIZ);
+ attr_t attr;
+ const char *found;
+
+ strcpy(buf, l_brace);
+ if (ch != 0) {
+ attr = AttrOfD(ch);
+ if ((found = _nc_altcharset_name(attr, (chtype) CharOfD(ch))) != 0) {
+ (void) _nc_trace_bufcat(bufnum, found);
+ attr &= ~A_ALTCHARSET;
+ } else if (isWidecExt(CHDEREF(ch))) {
+ (void) _nc_trace_bufcat(bufnum, "{NAC}");
+ attr &= ~A_CHARTEXT;
+ } else {
+ PUTC_DATA;
+ int n;
+
+ PUTC_INIT;
+ (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')
+ break;
+ PUTC_n = 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, _tracechar(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, _tracechar(UChar(PUTC_buf[n])));
+ }
+ }
+ (void) _nc_trace_bufcat(bufnum, " }");
+ }
+ if (attr != A_NORMAL) {
+ (void) _nc_trace_bufcat(bufnum, " | ");
+ (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr));
+ }
+ }
+
+ return (_nc_trace_bufcat(bufnum, r_brace));
+}
+
+NCURSES_EXPORT(char *)
+_tracecchar_t (const cchar_t *ch)
+{
+ return _tracecchar_t2(0, ch);
+}
+#endif
+
+#else
+empty_module(_nc_lib_traceatr)
+#endif /* TRACE */
diff --git a/ncurses/trace/lib_tracebits.c b/ncurses/trace/lib_tracebits.c
new file mode 100644
index 000000000000..de2394c39225
--- /dev/null
+++ b/ncurses/trace/lib_tracebits.c
@@ -0,0 +1,271 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 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 *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <term.h> /* cur_term */
+
+MODULE_ID("$Id: lib_tracebits.c,v 1.15 2007/06/30 16:14:20 tom Exp $")
+
+#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
+#define _POSIX_SOURCE
+#endif
+
+#if HAVE_SYS_TERMIO_H
+#include <sys/termio.h> /* needed for ISC */
+#endif
+
+#ifdef __EMX__
+#include <io.h>
+#endif
+
+/* may be undefined if we're using termio.h */
+#ifndef TOSTOP
+#define TOSTOP 0
+#endif
+
+#ifndef IEXTEN
+#define IEXTEN 0
+#endif
+
+#ifndef ONLCR
+#define ONLCR 0
+#endif
+
+#ifndef OCRNL
+#define OCRNL 0
+#endif
+
+#ifndef ONOCR
+#define ONOCR 0
+#endif
+
+#ifndef ONLRET
+#define ONLRET 0
+#endif
+
+#ifdef TRACE
+
+typedef struct {
+ unsigned int val;
+ const char *name;
+} BITNAMES;
+
+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++)
+ if (sp->val != 0
+ && (val & sp->val) == sp->val) {
+ (void) strcat(buf, sp->name);
+ (void) strcat(buf, ", ");
+ }
+ if (buf[strlen(buf) - 2] == ',')
+ buf[strlen(buf) - 2] = '\0';
+ (void) strcat(buf, "} ");
+}
+
+NCURSES_EXPORT(char *)
+_nc_trace_ttymode(TTY * tty)
+/* describe the state of the terminal control bits exactly */
+{
+ char *buf;
+
+#ifdef TERMIOS
+ 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}
+#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}
+#define ALLOUT (OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET)
+ }, cflags[] =
+ {
+ {CLOCAL, "CLOCAL"},
+ {CREAD, "CREAD"},
+ {CSTOPB, "CSTOPB"},
+#if !defined(CS5) || !defined(CS8)
+ {CSIZE, "CSIZE"},
+#endif
+ {HUPCL, "HUPCL"},
+ {PARENB, "PARENB"},
+ {PARODD | PARENB, "PARODD"}, /* concession to readability */
+ {0, NULL}
+#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}
+#define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
+ };
+
+ buf = _nc_trace_buf(0,
+ 8 + sizeof(iflags) +
+ 8 + sizeof(oflags) +
+ 8 + sizeof(cflags) +
+ 8 + sizeof(lflags) +
+ 8);
+
+ if (tty->c_iflag & ALLIN)
+ lookup_bits(buf, iflags, "iflags", tty->c_iflag);
+
+ if (tty->c_oflag & ALLOUT)
+ lookup_bits(buf, oflags, "oflags", tty->c_oflag);
+
+ if (tty->c_cflag & ALLCTRL)
+ lookup_bits(buf, cflags, "cflags", tty->c_cflag);
+
+#if defined(CS5) && defined(CS8)
+ {
+ static struct {
+ const char *name;
+ int value;
+ } csizes[] = {
+ {
+ "CS5 ", CS5
+ },
+#ifdef CS6
+ {
+ "CS6 ", CS6
+ },
+#endif
+#ifdef CS7
+ {
+ "CS7 ", CS7
+ },
+#endif
+ {
+ "CS8 ", CS8
+ },
+ };
+ const char *result = "CSIZE? ";
+ int value = (tty->c_cflag & CSIZE);
+ unsigned n;
+
+ if (value != 0) {
+ for (n = 0; n < SIZEOF(csizes); n++) {
+ if (csizes[n].value == value) {
+ result = csizes[n].name;
+ break;
+ }
+ }
+ }
+ strcat(buf, result);
+ }
+#endif
+
+ if (tty->c_lflag & ALLLOCAL)
+ lookup_bits(buf, lflags, "lflags", tty->c_lflag);
+
+#else
+ /* reference: ttcompat(4M) on SunOS 4.1 */
+#ifndef EVENP
+#define EVENP 0
+#endif
+#ifndef LCASE
+#define LCASE 0
+#endif
+#ifndef LLITOUT
+#define LLITOUT 0
+#endif
+#ifndef ODDP
+#define ODDP 0
+#endif
+#ifndef TANDEM
+#define TANDEM 0
+#endif
+
+ 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}
+#define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
+ };
+
+ buf = _nc_trace_buf(0,
+ 8 + sizeof(cflags));
+
+ if (tty->sg_flags & ALLCTRL) {
+ lookup_bits(buf, cflags, "cflags", tty->sg_flags);
+ }
+#endif
+ return (buf);
+}
+
+NCURSES_EXPORT(char *)
+_nc_tracebits(void)
+{
+ return _nc_trace_ttymode(&(cur_term->Nttyb));
+}
+#else
+empty_module(_nc_tracebits)
+#endif /* TRACE */
diff --git a/ncurses/trace/lib_tracechr.c b/ncurses/trace/lib_tracechr.c
new file mode 100644
index 000000000000..479756ac59be
--- /dev/null
+++ b/ncurses/trace/lib_tracechr.c
@@ -0,0 +1,74 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2007 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 *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+ * lib_tracechr.c - Tracing/Debugging routines
+ */
+#include <curses.priv.h>
+
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_tracechr.c,v 1.13 2007/04/21 23:16:37 tom Exp $")
+
+#ifdef TRACE
+#define MyBuffer _nc_globals.tracechr_buf
+
+NCURSES_EXPORT(char *)
+_tracechar(int ch)
+{
+ NCURSES_CONST char *name;
+
+ if (ch > KEY_MIN || ch < 0) {
+ name = keyname(ch);
+ if (name == 0 || *name == '\0')
+ name = "NULL";
+ (void) sprintf(MyBuffer, "'%.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);
+ } else {
+ name = unctrl((chtype) ch);
+ if (name == 0 || *name == 0)
+ name = "null"; /* shouldn't happen */
+ (void) sprintf(MyBuffer, "'%.30s' = %#03o", name, ch);
+ }
+ return (MyBuffer);
+}
+#else
+empty_module(_nc_lib_tracechr)
+#endif
diff --git a/ncurses/trace/lib_tracedmp.c b/ncurses/trace/lib_tracedmp.c
new file mode 100644
index 000000000000..d56d1a5d48b0
--- /dev/null
+++ b/ncurses/trace/lib_tracedmp.c
@@ -0,0 +1,184 @@
+/****************************************************************************
+ * Copyright (c) 1998-2006,2007 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 *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey 1996-on *
+ * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+ * lib_tracedmp.c - Tracing/Debugging routines
+ */
+
+#include <curses.priv.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: lib_tracedmp.c,v 1.29 2007/06/30 23:01:19 tom Exp $")
+
+#ifdef TRACE
+
+#define my_buffer _nc_globals.tracedmp_buf
+#define my_length _nc_globals.tracedmp_used
+
+NCURSES_EXPORT(void)
+_tracedump(const char *name, WINDOW *win)
+{
+ int i, j, n, width;
+
+ /* compute narrowest possible display width */
+ for (width = i = 0; i <= win->_maxy; ++i) {
+ n = 0;
+ for (j = 0; j <= win->_maxx; ++j) {
+ if (CharOf(win->_line[i].text[j]) != L(' ')
+ || AttrOf(win->_line[i].text[j]) != A_NORMAL
+ || GetPair(win->_line[i].text[j]) != 0) {
+ n = j;
+ }
+ }
+
+ if (n > width)
+ width = n;
+ }
+ if (width < win->_maxx)
+ ++width;
+ if (++width + 1 > (int) my_length) {
+ my_length = 2 * (width + 1);
+ my_buffer = typeRealloc(char, my_length, my_buffer);
+ }
+
+ for (n = 0; n <= win->_maxy; ++n) {
+ char *ep = my_buffer;
+ bool haveattrs, havecolors;
+
+ /*
+ * Dump A_CHARTEXT part. It is more important to make the grid line up
+ * in the trace file than to represent control- and wide-characters, so
+ * we map those to '.' and '?' respectively.
+ */
+ for (j = 0; j < width; ++j) {
+ chtype test = CharOf(win->_line[n].text[j]);
+ ep[j] = (UChar(test) == test
+#if USE_WIDEC_SUPPORT
+ && (win->_line[n].text[j].chars[1] == 0)
+#endif
+ )
+ ? (iscntrl(UChar(test))
+ ? '.'
+ : UChar(test))
+ : '?';
+ }
+ ep[j] = '\0';
+ _tracef("%s[%2d] %3ld%3ld ='%s'",
+ name, n,
+ (long) win->_line[n].firstchar,
+ (long) win->_line[n].lastchar,
+ ep);
+
+ /* if there are multi-column characters on the line, print them now */
+ if_WIDEC({
+ bool multicolumn = FALSE;
+ for (j = 0; j < width; ++j)
+ if (WidecExt(win->_line[n].text[j]) != 0) {
+ multicolumn = TRUE;
+ break;
+ }
+ if (multicolumn) {
+ ep = my_buffer;
+ for (j = 0; j < width; ++j) {
+ int test = WidecExt(win->_line[n].text[j]);
+ if (test) {
+ ep[j] = test + '0';
+ } else {
+ ep[j] = ' ';
+ }
+ }
+ ep[j] = '\0';
+ _tracef("%*s[%2d]%*s='%s'", (int) strlen(name),
+ "widec", n, 8, " ", my_buffer);
+ }
+ });
+
+ /* dump A_COLOR part, will screw up if there are more than 96 */
+ havecolors = FALSE;
+ for (j = 0; j < width; ++j)
+ if (GetPair(win->_line[n].text[j]) != 0) {
+ havecolors = TRUE;
+ break;
+ }
+ if (havecolors) {
+ ep = my_buffer;
+ for (j = 0; j < width; ++j) {
+ int pair = GetPair(win->_line[n].text[j]);
+ if (pair >= 52)
+ ep[j] = '?';
+ else if (pair >= 36)
+ ep[j] = pair + 'A';
+ else if (pair >= 10)
+ ep[j] = pair + 'a';
+ else if (pair >= 1)
+ ep[j] = pair + '0';
+ else
+ ep[j] = ' ';
+ }
+ ep[j] = '\0';
+ _tracef("%*s[%2d]%*s='%s'", (int) strlen(name),
+ "colors", n, 8, " ", my_buffer);
+ }
+
+ for (i = 0; i < 4; ++i) {
+ const char *hex = " 123456789ABCDEF";
+ attr_t mask = (0xf << ((i + 4) * 4));
+
+ haveattrs = FALSE;
+ for (j = 0; j < width; ++j)
+ if (AttrOf(win->_line[n].text[j]) & mask) {
+ haveattrs = TRUE;
+ break;
+ }
+ if (haveattrs) {
+ ep = my_buffer;
+ for (j = 0; j < width; ++j)
+ ep[j] = hex[(AttrOf(win->_line[n].text[j]) & mask) >>
+ ((i + 4) * 4)];
+ ep[j] = '\0';
+ _tracef("%*s%d[%2d]%*s='%s'", (int) strlen(name) -
+ 1, "attrs", i, n, 8, " ", my_buffer);
+ }
+ }
+ }
+#if NO_LEAKS
+ free(my_buffer);
+ my_buffer = 0;
+ my_length = 0;
+#endif
+}
+
+#else
+empty_module(_nc_lib_tracedmp)
+#endif /* TRACE */
diff --git a/ncurses/trace/lib_tracemse.c b/ncurses/trace/lib_tracemse.c
new file mode 100644
index 000000000000..5edcc13a6ffa
--- /dev/null
+++ b/ncurses/trace/lib_tracemse.c
@@ -0,0 +1,119 @@
+/****************************************************************************
+ * Copyright (c) 1998-2005,2007 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 *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ * and: Thomas E. Dickey 1996-on *
+ ****************************************************************************/
+
+/*
+ * lib_tracemse.c - Tracing/Debugging routines (mouse events)
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: lib_tracemse.c,v 1.13 2007/04/21 21:23:00 tom Exp $")
+
+#ifdef TRACE
+
+#define my_buffer _nc_globals.tracemse_buf
+
+NCURSES_EXPORT(char *)
+_tracemouse(MEVENT const *ep)
+{
+ (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), ", ")
+
+ SHOW(BUTTON1_RELEASED, "release-1");
+ SHOW(BUTTON1_PRESSED, "press-1");
+ SHOW(BUTTON1_CLICKED, "click-1");
+ SHOW(BUTTON1_DOUBLE_CLICKED, "doubleclick-1");
+ SHOW(BUTTON1_TRIPLE_CLICKED, "tripleclick-1");
+#if NCURSES_MOUSE_VERSION == 1
+ SHOW(BUTTON1_RESERVED_EVENT, "reserved-1");
+#endif
+
+ SHOW(BUTTON2_RELEASED, "release-2");
+ SHOW(BUTTON2_PRESSED, "press-2");
+ SHOW(BUTTON2_CLICKED, "click-2");
+ SHOW(BUTTON2_DOUBLE_CLICKED, "doubleclick-2");
+ SHOW(BUTTON2_TRIPLE_CLICKED, "tripleclick-2");
+#if NCURSES_MOUSE_VERSION == 1
+ SHOW(BUTTON2_RESERVED_EVENT, "reserved-2");
+#endif
+
+ SHOW(BUTTON3_RELEASED, "release-3");
+ SHOW(BUTTON3_PRESSED, "press-3");
+ SHOW(BUTTON3_CLICKED, "click-3");
+ SHOW(BUTTON3_DOUBLE_CLICKED, "doubleclick-3");
+ SHOW(BUTTON3_TRIPLE_CLICKED, "tripleclick-3");
+#if NCURSES_MOUSE_VERSION == 1
+ SHOW(BUTTON3_RESERVED_EVENT, "reserved-3");
+#endif
+
+ SHOW(BUTTON4_RELEASED, "release-4");
+ SHOW(BUTTON4_PRESSED, "press-4");
+ SHOW(BUTTON4_CLICKED, "click-4");
+ SHOW(BUTTON4_DOUBLE_CLICKED, "doubleclick-4");
+ SHOW(BUTTON4_TRIPLE_CLICKED, "tripleclick-4");
+#if NCURSES_MOUSE_VERSION == 1
+ SHOW(BUTTON4_RESERVED_EVENT, "reserved-4");
+#endif
+
+#if NCURSES_MOUSE_VERSION == 2
+ SHOW(BUTTON5_RELEASED, "release-5");
+ SHOW(BUTTON5_PRESSED, "press-5");
+ SHOW(BUTTON5_CLICKED, "click-5");
+ SHOW(BUTTON5_DOUBLE_CLICKED, "doubleclick-5");
+ SHOW(BUTTON5_TRIPLE_CLICKED, "tripleclick-5");
+#endif
+
+ SHOW(BUTTON_CTRL, "ctrl");
+ SHOW(BUTTON_SHIFT, "shift");
+ SHOW(BUTTON_ALT, "alt");
+ SHOW(ALL_MOUSE_EVENTS, "all-events");
+ SHOW(REPORT_MOUSE_POSITION, "position");
+
+#undef SHOW
+
+ if (my_buffer[strlen(my_buffer) - 1] == ' ')
+ my_buffer[strlen(my_buffer) - 2] = '\0';
+ (void) strcat(my_buffer, "}");
+ return (my_buffer);
+}
+
+#else /* !TRACE */
+empty_module(_nc_lib_tracemouse)
+#endif
diff --git a/ncurses/trace/trace_buf.c b/ncurses/trace/trace_buf.c
new file mode 100644
index 000000000000..7bf91c674df3
--- /dev/null
+++ b/ncurses/trace/trace_buf.c
@@ -0,0 +1,105 @@
+/****************************************************************************
+ * Copyright (c) 1998-2003,2007 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 *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey <dickey@clark.net> 1997 *
+ ****************************************************************************/
+/*
+ * trace_buf.c - Tracing/Debugging buffers (attributes)
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: trace_buf.c,v 1.13 2007/04/21 22:50:08 tom Exp $")
+
+#define MyList _nc_globals.tracebuf_ptr
+#define MySize _nc_globals.tracebuf_used
+
+static char *
+_nc_trace_alloc(int bufnum, size_t want)
+{
+ char *result = 0;
+
+ if (bufnum >= 0) {
+ if ((size_t) (bufnum + 1) > MySize) {
+ size_t need = (bufnum + 1) * 2;
+ if ((MyList = typeRealloc(TRACEBUF, need, MyList)) == 0)
+ return (0);
+ while (need > MySize)
+ MyList[MySize++].text = 0;
+ }
+
+ if (MyList[bufnum].text == 0
+ || want > MyList[bufnum].size) {
+ MyList[bufnum].text = typeRealloc(char, want, MyList[bufnum].text);
+ if (MyList[bufnum].text != 0)
+ MyList[bufnum].size = want;
+ }
+
+ result = MyList[bufnum].text;
+ }
+#if NO_LEAKS
+ else {
+ if (MySize) {
+ while (MySize--) {
+ if (MyList[MySize].text != 0)
+ free(MyList[MySize].text);
+ }
+ free(MyList);
+ }
+ }
+#endif
+ return result;
+}
+
+/*
+ * (re)Allocate a buffer big enough for the caller's wants.
+ */
+NCURSES_EXPORT(char *)
+_nc_trace_buf(int bufnum, size_t want)
+{
+ char *result = _nc_trace_alloc(bufnum, want);
+ if (result != 0)
+ *result = '\0';
+ return result;
+}
+
+/*
+ * Append a new string to an existing buffer.
+ */
+NCURSES_EXPORT(char *)
+_nc_trace_bufcat(int bufnum, const char *value)
+{
+ char *buffer = _nc_trace_alloc(bufnum, 0);
+ size_t have = strlen(buffer);
+
+ buffer = _nc_trace_alloc(bufnum, 1 + have + strlen(value));
+ (void) strcpy(buffer + have, value);
+
+ return buffer;
+}
diff --git a/ncurses/trace/trace_tries.c b/ncurses/trace/trace_tries.c
new file mode 100644
index 000000000000..0aa0b227d7d0
--- /dev/null
+++ b/ncurses/trace/trace_tries.c
@@ -0,0 +1,78 @@
+/****************************************************************************
+ * Copyright (c) 1999-2006,2007 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 *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey <dickey@clark.net> 1999 *
+ ****************************************************************************/
+/*
+ * trace_tries.c - Tracing/Debugging buffers (keycode tries-trees)
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$Id: trace_tries.c,v 1.12 2007/04/21 21:55:41 tom Exp $")
+
+#ifdef TRACE
+#define my_buffer _nc_globals.tracetry_buf
+#define my_length _nc_globals.tracetry_used
+
+static void
+recur_tries(TRIES * tree, unsigned level)
+{
+ if (level > my_length) {
+ my_length = (level + 1) * 4;
+ my_buffer = (unsigned char *) realloc(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 (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);
+}
+
+#else
+empty_module(_nc_trace_tries)
+#endif
diff --git a/ncurses/trace/trace_xnames.c b/ncurses/trace/trace_xnames.c
new file mode 100644
index 000000000000..9b0b5920d814
--- /dev/null
+++ b/ncurses/trace/trace_xnames.c
@@ -0,0 +1,75 @@
+/****************************************************************************
+ * Copyright (c) 1999,2000 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 *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey <dickey@clark.net> 1999 *
+ ****************************************************************************/
+/*
+ * trace_xnames.c - Tracing/Debugging buffers (TERMTYPE extended names)
+ */
+
+#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 $")
+
+NCURSES_EXPORT(void)
+_nc_trace_xnames(TERMTYPE * tp GCC_UNUSED)
+{
+#ifdef TRACE
+#if NCURSES_XNAMES
+ int limit = tp->ext_Booleans + tp->ext_Numbers + tp->ext_Strings;
+ int n, m;
+ if (limit) {
+ int begin_num = tp->ext_Booleans;
+ int begin_str = tp->ext_Booleans + tp->ext_Numbers;
+
+ _tracef("extended names (%s) %d = %d+%d+%d of %d+%d+%d",
+ tp->term_names,
+ 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++) {
+ if ((m = n - begin_str) >= 0) {
+ _tracef("[%d] %s = %s", n,
+ tp->ext_Names[n],
+ _nc_visbuf(tp->Strings[tp->num_Strings + m - tp->ext_Strings]));
+ } else if ((m = n - begin_num) >= 0) {
+ _tracef("[%d] %s = %d (num)", n,
+ tp->ext_Names[n],
+ tp->Numbers[tp->num_Numbers + m - tp->ext_Numbers]);
+ } else {
+ _tracef("[%d] %s = %d (bool)", n,
+ tp->ext_Names[n],
+ tp->Booleans[tp->num_Booleans + n - tp->ext_Booleans]);
+ }
+ }
+ }
+#endif
+#endif
+}
diff --git a/ncurses/trace/varargs.c b/ncurses/trace/varargs.c
new file mode 100644
index 000000000000..5e63d21a2cc5
--- /dev/null
+++ b/ncurses/trace/varargs.c
@@ -0,0 +1,184 @@
+/****************************************************************************
+ * Copyright (c) 2001-2003,2007 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 *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey 2001 *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+
+MODULE_ID("$Id: varargs.c,v 1.6 2007/07/14 15:51:27 tom Exp $")
+
+#ifdef TRACE
+
+#define MAX_PARMS 10
+
+typedef enum {
+ atUnknown = 0, atInteger, atFloat, atPoint, atString
+} ARGTYPE;
+
+#define VA_INT(type) ival = 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)
+
+#define MyBuffer _nc_globals.tracearg_buf
+#define MyLength _nc_globals.tracearg_used
+
+/*
+ * Returns a string that represents the parameter list of a printf-style call.
+ */
+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;
+ if (MyLength == 0)
+ MyBuffer = typeMalloc(char, MyLength = BUFSIZ);
+ if (MyBuffer == 0)
+ return dummy;
+ *MyBuffer = '\0';
+
+ while (*fmt != '\0') {
+ if (*fmt == '%') {
+ char *pval = 0; /* avoid const-cast */
+ const char *sval = "";
+ double fval = 0.0;
+ int done = FALSE;
+ int ival = 0;
+ int type = 0;
+ ARGTYPE parm[MAX_PARMS];
+ int parms = 0;
+ ARGTYPE used = atUnknown;
+
+ while (*++fmt != '\0' && !done) {
+
+ if (*fmt == '*') {
+ VA_INT(int);
+ if (parms < MAX_PARMS)
+ parm[parms++] = atInteger;
+ } else if (isalpha(UChar(*fmt))) {
+ done = TRUE;
+ switch (*fmt) {
+ case 'Z': /* FALLTHRU */
+ case 'h': /* FALLTHRU */
+ case 'l': /* FALLTHRU */
+ done = FALSE;
+ type = *fmt;
+ break;
+ case 'i': /* FALLTHRU */
+ case 'd': /* FALLTHRU */
+ case 'u': /* FALLTHRU */
+ case 'x': /* FALLTHRU */
+ case 'X': /* FALLTHRU */
+ if (type == 'l')
+ VA_INT(long);
+ else if (type == 'Z')
+ VA_INT(size_t);
+ else
+ VA_INT(int);
+ used = atInteger;
+ break;
+ case 'f': /* FALLTHRU */
+ case 'e': /* FALLTHRU */
+ case 'E': /* FALLTHRU */
+ case 'g': /* FALLTHRU */
+ case 'G': /* FALLTHRU */
+ VA_FLT(double);
+ used = atFloat;
+ break;
+ case 'c':
+ VA_INT(int);
+ used = atInteger;
+ break;
+ case 's':
+ VA_STR(const char *);
+ used = atString;
+ break;
+ case 'p':
+ VA_PTR(void *);
+ used = atPoint;
+ break;
+ case 'n':
+ VA_PTR(int *);
+ used = atPoint;
+ break;
+ default:
+ break;
+ }
+ } else if (*fmt == '%') {
+ done = TRUE;
+ }
+ if (used != atUnknown && parms < MAX_PARMS) {
+ parm[parms++] = used;
+ for (n = 0; n < parms; ++n) {
+ used = parm[n];
+ param = buffer;
+ switch (used) {
+ case atInteger:
+ sprintf(buffer, "%d", ival);
+ break;
+ case atFloat:
+ sprintf(buffer, "%f", fval);
+ break;
+ case atPoint:
+ sprintf(buffer, "%p", pval);
+ break;
+ case atString:
+ param = _nc_visbuf2(1, sval);
+ break;
+ case atUnknown:
+ default:
+ strcpy(buffer, "?");
+ break;
+ }
+ MyLength += strlen(param) + 2;
+ MyBuffer = typeRealloc(char, MyLength, MyBuffer);
+ sprintf(MyBuffer + strlen(MyBuffer), ", %s", param);
+ }
+ }
+ used = atUnknown;
+ }
+ } else {
+ fmt++;
+ }
+ }
+
+ return (MyBuffer);
+}
+#else
+empty_module(_nc_varargs)
+#endif
diff --git a/ncurses/trace/visbuf.c b/ncurses/trace/visbuf.c
new file mode 100644
index 000000000000..74081efe6442
--- /dev/null
+++ b/ncurses/trace/visbuf.c
@@ -0,0 +1,321 @@
+/****************************************************************************
+ * Copyright (c) 2001-2006,2007 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 *
+ * "Software"), to deal in the Software without restriction, including *
+ * without limitation the rights to use, copy, modify, merge, publish, *
+ * distribute, distribute with modifications, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included *
+ * in all copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
+ * *
+ * Except as contained in this notice, the name(s) of the above copyright *
+ * holders shall not be used in advertising or otherwise to promote the *
+ * sale, use or other dealings in this Software without prior written *
+ * authorization. *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Author: Thomas E. Dickey 1996-on *
+ * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * and: Eric S. Raymond <esr@snark.thyrsus.com> *
+ ****************************************************************************/
+
+/*
+ * visbuf.c - Tracing/Debugging support routines
+ */
+
+#define NEED_NCURSES_CH_T
+#include <curses.priv.h>
+
+#include <tic.h>
+#include <ctype.h>
+
+MODULE_ID("$Id: visbuf.c,v 1.26 2007/06/09 17:21:53 tom Exp $")
+
+#define NormalLen(len) (unsigned) ((len + 1) * 4)
+#define WideLen(len) (unsigned) ((len + 1) * 4 * MB_CUR_MAX)
+
+#ifdef TRACE
+static const char d_quote[] = StringOf(D_QUOTE);
+static const char l_brace[] = StringOf(L_BRACE);
+static const char r_brace[] = StringOf(R_BRACE);
+#endif
+
+static char *
+_nc_vischar(char *tp, unsigned c)
+{
+ if (c == '"' || c == '\\') {
+ *tp++ = '\\';
+ *tp++ = c;
+ } else if (is7bits(c) && (isgraph(c) || c == ' ')) {
+ *tp++ = c;
+ } else if (c == '\n') {
+ *tp++ = '\\';
+ *tp++ = 'n';
+ } else if (c == '\r') {
+ *tp++ = '\\';
+ *tp++ = 'r';
+ } else if (c == '\b') {
+ *tp++ = '\\';
+ *tp++ = 'b';
+ } else if (c == '\033') {
+ *tp++ = '\\';
+ *tp++ = 'e';
+ } else if (UChar(c) == 0x7f) {
+ *tp++ = '\\';
+ *tp++ = '^';
+ *tp++ = '?';
+ } else if (is7bits(c) && iscntrl(UChar(c))) {
+ *tp++ = '\\';
+ *tp++ = '^';
+ *tp++ = '@' + c;
+ } else {
+ sprintf(tp, "\\%03lo", (unsigned long) ChCharOf(c));
+ tp += strlen(tp);
+ }
+ *tp = 0;
+ return tp;
+}
+
+static const char *
+_nc_visbuf2n(int bufnum, const char *buf, int len)
+{
+ char *vbuf;
+ char *tp;
+ int c;
+
+ if (buf == 0)
+ return ("(null)");
+ if (buf == CANCELLED_STRING)
+ return ("(cancelled)");
+
+ if (len < 0)
+ len = strlen(buf);
+
+#ifdef TRACE
+ tp = vbuf = _nc_trace_buf(bufnum, NormalLen(len));
+#else
+ {
+ static char *mybuf[4];
+ mybuf[bufnum] = typeRealloc(char, NormalLen(len), mybuf[bufnum]);
+ tp = vbuf = mybuf[bufnum];
+ }
+#endif
+ *tp++ = D_QUOTE;
+ while ((--len >= 0) && (c = *buf++) != '\0') {
+ tp = _nc_vischar(tp, UChar(c));
+ }
+ *tp++ = D_QUOTE;
+ *tp++ = '\0';
+ return (vbuf);
+}
+
+NCURSES_EXPORT(const char *)
+_nc_visbuf2(int bufnum, const char *buf)
+{
+ return _nc_visbuf2n(bufnum, buf, -1);
+}
+
+NCURSES_EXPORT(const char *)
+_nc_visbuf(const char *buf)
+{
+ return _nc_visbuf2(0, buf);
+}
+
+NCURSES_EXPORT(const char *)
+_nc_visbufn(const char *buf, int len)
+{
+ return _nc_visbuf2n(0, buf, len);
+}
+
+#ifdef TRACE
+#if USE_WIDEC_SUPPORT
+
+#if defined(USE_TERMLIB)
+#define _nc_wchstrlen _my_wchstrlen
+static int
+_nc_wchstrlen(const cchar_t *s)
+{
+ int result = 0;
+ while (CharOf(s[result]) != L'\0') {
+ result++;
+ }
+ return result;
+}
+#endif
+
+static const char *
+_nc_viswbuf2n(int bufnum, const wchar_t *buf, int len)
+{
+ char *vbuf;
+ char *tp;
+ wchar_t c;
+
+ if (buf == 0)
+ return ("(null)");
+
+ if (len < 0)
+ len = wcslen(buf);
+
+#ifdef TRACE
+ tp = vbuf = _nc_trace_buf(bufnum, WideLen(len));
+#else
+ {
+ static char *mybuf[2];
+ mybuf[bufnum] = typeRealloc(char, WideLen(len), mybuf[bufnum]);
+ tp = vbuf = mybuf[bufnum];
+ }
+#endif
+ *tp++ = D_QUOTE;
+ while ((--len >= 0) && (c = *buf++) != '\0') {
+ char temp[CCHARW_MAX + 80];
+ int j = wctomb(temp, c), k;
+ if (j <= 0) {
+ sprintf(temp, "\\u%08X", (wint_t) c);
+ j = strlen(temp);
+ }
+ for (k = 0; k < j; ++k) {
+ tp = _nc_vischar(tp, UChar(temp[k]));
+ }
+ }
+ *tp++ = D_QUOTE;
+ *tp++ = '\0';
+ return (vbuf);
+}
+
+NCURSES_EXPORT(const char *)
+_nc_viswbuf2(int bufnum, const wchar_t *buf)
+{
+ return _nc_viswbuf2n(bufnum, buf, -1);
+}
+
+NCURSES_EXPORT(const char *)
+_nc_viswbuf(const wchar_t *buf)
+{
+ return _nc_viswbuf2(0, buf);
+}
+
+NCURSES_EXPORT(const char *)
+_nc_viswbufn(const wchar_t *buf, int len)
+{
+ return _nc_viswbuf2n(0, buf, len);
+}
+
+/* this special case is used for wget_wstr() */
+NCURSES_EXPORT(const char *)
+_nc_viswibuf(const wint_t *buf)
+{
+ static wchar_t *mybuf;
+ static unsigned mylen;
+ unsigned n;
+
+ for (n = 0; buf[n] != 0; ++n) ;
+ if (mylen < ++n) {
+ mylen = n + 80;
+ if (mybuf != 0)
+ mybuf = typeRealloc(wchar_t, mylen, mybuf);
+ else
+ mybuf = typeMalloc(wchar_t, mylen);
+ }
+ for (n = 0; buf[n] != 0; ++n)
+ mybuf[n] = (wchar_t) buf[n];
+
+ return _nc_viswbuf2(0, mybuf);
+}
+#endif /* USE_WIDEC_SUPPORT */
+
+/* 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)
+{
+ char *result = _nc_trace_buf(bufnum, BUFSIZ);
+ int first;
+ const char *found;
+
+#if USE_WIDEC_SUPPORT
+ if (len < 0)
+ len = _nc_wchstrlen(buf);
+#endif /* USE_WIDEC_SUPPORT */
+
+ /*
+ * Display one or more strings followed by attributes.
+ */
+ first = 0;
+ while (first < len) {
+ attr_t attr = AttrOf(buf[first]);
+ int last = len - 1;
+ int j;
+
+ for (j = first + 1; j < len; ++j) {
+ if (!SameAttrOf(buf[j], buf[first])) {
+ last = j - 1;
+ break;
+ }
+ }
+
+ result = _nc_trace_bufcat(bufnum, l_brace);
+ result = _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);
+ attr &= ~A_ALTCHARSET;
+ } else
+#if USE_WIDEC_SUPPORT
+ if (!isWidecExt(buf[j])) {
+ PUTC_DATA;
+
+ PUTC_INIT;
+ for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
+ int k;
+
+ PUTC_ch = buf[j].chars[PUTC_i];
+ if (PUTC_ch == L'\0')
+ break;
+ PUTC_n = 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);
+ }
+ }
+ }
+#else
+ {
+ char temp[80];
+ _nc_vischar(temp, UChar(buf[j]));
+ result = _nc_trace_bufcat(bufnum, temp);
+ }
+#endif /* USE_WIDEC_SUPPORT */
+ }
+ result = _nc_trace_bufcat(bufnum, d_quote);
+ if (attr != A_NORMAL) {
+ result = _nc_trace_bufcat(bufnum, " | ");
+ result = _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr));
+ }
+ result = _nc_trace_bufcat(bufnum, r_brace);
+ first = last + 1;
+ }
+ return result;
+}
+
+NCURSES_EXPORT(const char *)
+_nc_viscbuf(const NCURSES_CH_T * buf, int len)
+{
+ return _nc_viscbuf2(0, buf, len);
+}
+#endif /* TRACE */