summaryrefslogtreecommitdiff
path: root/lib/libcurses/trace
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1999-01-18 19:10:28 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1999-01-18 19:10:28 +0000
commit2ab6a45cb794e8f5ff7b3d8c9fe25b0ef0f5b669 (patch)
tree68bbd31bb6b70c640ee51637367f12996de516f7 /lib/libcurses/trace
parent369038865daffb176f8616ac082675a6e8116a0f (diff)
ncurses-4.2-990116
Diffstat (limited to 'lib/libcurses/trace')
-rw-r--r--lib/libcurses/trace/lib_trace.c202
-rw-r--r--lib/libcurses/trace/lib_traceatr.c220
-rw-r--r--lib/libcurses/trace/lib_tracebits.c219
-rw-r--r--lib/libcurses/trace/lib_tracechr.c69
-rw-r--r--lib/libcurses/trace/lib_tracedmp.c130
-rw-r--r--lib/libcurses/trace/lib_tracemse.c97
-rw-r--r--lib/libcurses/trace/trace_buf.c83
7 files changed, 1020 insertions, 0 deletions
diff --git a/lib/libcurses/trace/lib_trace.c b/lib/libcurses/trace/lib_trace.c
new file mode 100644
index 00000000000..11124a0167c
--- /dev/null
+++ b/lib/libcurses/trace/lib_trace.c
@@ -0,0 +1,202 @@
+/* $OpenBSD: lib_trace.c,v 1.1 1999/01/18 19:10:23 millert Exp $ */
+
+/****************************************************************************
+ * Copyright (c) 1998 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> *
+ ****************************************************************************/
+
+/*
+ * lib_trace.c - Tracing/Debugging routines
+ */
+
+#include <curses.priv.h>
+#include <tic.h>
+
+MODULE_ID("$From: lib_trace.c,v 1.30 1998/10/03 23:41:42 tom Exp $")
+
+#include <ctype.h>
+#if HAVE_FCNTL_H
+#include <fcntl.h>
+#endif
+
+unsigned _nc_tracing = 0; /* always define this */
+
+#ifdef TRACE
+const char *_nc_tputs_trace = "";
+long _nc_outchars;
+
+static FILE * tracefp; /* default to writing to stderr */
+#endif
+
+void trace(const unsigned int tracelevel GCC_UNUSED)
+{
+#ifdef TRACE
+static bool been_here = FALSE;
+static char my_name[] = "trace";
+
+ _nc_tracing = tracelevel;
+ if (! been_here && tracelevel) {
+ been_here = TRUE;
+
+ if (_nc_access(my_name, W_OK) < 0
+ || (tracefp = fopen(my_name, "w")) == 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)",
+ NCURSES_VERSION, NCURSES_VERSION_PATCH);
+ }
+#endif
+}
+
+const char *_nc_visbuf2(int bufnum, const char *buf)
+/* visibilize a given string */
+{
+char *vbuf;
+char *tp;
+int c;
+
+ if (buf == 0)
+ return("(null)");
+ if (buf == CANCELLED_STRING)
+ return("(cancelled)");
+
+ tp = vbuf = _nc_trace_buf(bufnum, (strlen(buf) * 4) + 5);
+ *tp++ = '"';
+ while ((c = *buf++) != '\0') {
+ if (c == '"') {
+ *tp++ = '\\'; *tp++ = '"';
+ } 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 (is7bits(c) && iscntrl(c)) {
+ *tp++ = '\\'; *tp++ = '^'; *tp++ = '@' + c;
+ } else {
+ sprintf(tp, "\\%03o", c & 0xff);
+ tp += strlen(tp);
+ }
+ }
+ *tp++ = '"';
+ *tp++ = '\0';
+ return(vbuf);
+}
+
+const char *_nc_visbuf(const char *buf)
+{
+ return _nc_visbuf2(0, buf);
+}
+
+#ifdef TRACE
+void
+_tracef(const char *fmt, ...)
+{
+static const char Called[] = T_CALLED("");
+static const char Return[] = T_RETURN("");
+static int level;
+va_list ap;
+bool before = FALSE;
+bool after = FALSE;
+int doit = _nc_tracing;
+int save_err = errno;
+
+ if (strlen(fmt) >= sizeof(Called) - 1) {
+ if (!strncmp(fmt, Called, sizeof(Called)-1)) {
+ before = TRUE;
+ level++;
+ } else if (!strncmp(fmt, Return, sizeof(Return)-1)) {
+ after = TRUE;
+ }
+ if (before || after) {
+ if ((level <= 1)
+ || (doit & TRACE_ICALLS) != 0)
+ doit &= (TRACE_CALLS|TRACE_CCALLS);
+ else
+ doit = 0;
+ }
+ }
+
+ if (doit != 0) {
+ if (tracefp == 0)
+ tracefp = stderr;
+ if (before || after) {
+ int n;
+ for (n = 1; n < level; n++)
+ fputs("+ ", tracefp);
+ }
+ va_start(ap, fmt);
+ vfprintf(tracefp, fmt, ap);
+ fputc('\n', tracefp);
+ va_end(ap);
+ fflush(tracefp);
+ }
+
+ if (after && level)
+ level--;
+ errno = save_err;
+}
+
+/* Trace 'int' return-values */
+int _nc_retrace_int(int code)
+{
+ T((T_RETURN("%d"), code));
+ return code;
+}
+
+/* Trace 'char*' return-values */
+char * _nc_retrace_ptr(char * code)
+{
+ T((T_RETURN("%s"), _nc_visbuf(code)));
+ return code;
+}
+
+/* Trace 'WINDOW *' return-values */
+WINDOW *_nc_retrace_win(WINDOW *code)
+{
+ T((T_RETURN("%p"), code));
+ return code;
+}
+#endif /* TRACE */
diff --git a/lib/libcurses/trace/lib_traceatr.c b/lib/libcurses/trace/lib_traceatr.c
new file mode 100644
index 00000000000..58c86c8081a
--- /dev/null
+++ b/lib/libcurses/trace/lib_traceatr.c
@@ -0,0 +1,220 @@
+/* $OpenBSD: lib_traceatr.c,v 1.1 1999/01/18 19:10:23 millert Exp $ */
+
+/****************************************************************************
+ * Copyright (c) 1998 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> *
+ ****************************************************************************/
+
+
+
+/*
+ * lib_traceatr.c - Tracing/Debugging routines (attributes)
+ */
+
+#include <curses.priv.h>
+#include <term.h> /* acs_chars */
+
+MODULE_ID("$From: lib_traceatr.c,v 1.28 1998/03/21 18:39:36 tom Exp $")
+
+#define COLOR_OF(c) (c < 0 || c > 7 ? "default" : colors[c].name)
+
+#ifdef TRACE
+char *_traceattr2(int bufnum, attr_t newmode)
+{
+char *buf = _nc_trace_buf(bufnum, BUFSIZ);
+char *tmp = buf;
+static const struct {unsigned int val; const char *name;}
+names[] =
+ {
+ { 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" },
+ },
+colors[] =
+ {
+ { 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" },
+ };
+size_t n;
+unsigned save_nc_tracing = _nc_tracing;
+ _nc_tracing = 0;
+
+ strcpy(tmp++, "{");
+
+ for (n = 0; n < SIZEOF(names); n++) {
+ if ((newmode & names[n].val) != 0) {
+ if (buf[1] != '\0')
+ strcat(tmp, "|");
+ strcat(tmp, names[n].name);
+ tmp += strlen(tmp);
+
+ if (names[n].val == A_COLOR)
+ {
+ short pairnum = PAIR_NUMBER(newmode);
+ short fg, bg;
+
+ if (pair_content(pairnum, &fg, &bg) == OK)
+ (void) sprintf(tmp,
+ "{%d = {%s, %s}}",
+ pairnum,
+ COLOR_OF(fg),
+ COLOR_OF(bg)
+ );
+ else
+ (void) sprintf(tmp, "{%d}", pairnum);
+ }
+ }
+ }
+ if (AttrOf(newmode) == A_NORMAL) {
+ if (buf[1] != '\0')
+ strcat(tmp, "|");
+ strcat(tmp, "A_NORMAL");
+ }
+
+ _nc_tracing = save_nc_tracing;
+ return (strcat(buf,"}"));
+}
+
+char *_traceattr(attr_t newmode)
+{
+ return _traceattr2(0, newmode);
+}
+
+/* Trace 'int' return-values */
+attr_t _nc_retrace_attr_t(attr_t code)
+{
+ T((T_RETURN("%s"), _traceattr(code)));
+ return code;
+}
+
+char *_tracechtype2(int bufnum, chtype ch)
+{
+char *buf = _nc_trace_buf(bufnum, BUFSIZ);
+char *found = 0;
+
+ strcpy(buf, "{");
+ if (ch & A_ALTCHARSET)
+ {
+ char *cp;
+ static const struct {unsigned int val; const char *name;}
+ 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}
+ },
+ *sp;
+
+ for (cp = acs_chars; cp[0] && cp[1]; cp += 2)
+ {
+ if (TextOf(cp[1]) == TextOf(ch))
+ {
+ found = cp;
+ /* don't exit from loop - there may be redefinitions */
+ }
+ }
+
+ if (found != 0)
+ {
+ ch = TextOf(*found);
+ for (sp = names; sp->val; sp++)
+ if (sp->val == ch)
+ {
+ (void) strcat(buf, sp->name);
+ ch &= ~A_ALTCHARSET;
+ break;
+ }
+ }
+ }
+
+ if (found == 0)
+ (void) strcat(buf, _tracechar(TextOf(ch)));
+
+ if (AttrOf(ch) != A_NORMAL)
+ (void) sprintf(buf + strlen(buf), " | %s", _traceattr2(bufnum+20,AttrOf(ch)));
+
+ strcat(buf, "}");
+ return(buf);
+}
+
+char *_tracechtype(chtype ch)
+{
+ return _tracechtype2(0, ch);
+}
+#else
+extern void _nc_lib_traceatr(void);
+ void _nc_lib_traceatr(void) { }
+#endif /* TRACE */
diff --git a/lib/libcurses/trace/lib_tracebits.c b/lib/libcurses/trace/lib_tracebits.c
new file mode 100644
index 00000000000..b7038c6793b
--- /dev/null
+++ b/lib/libcurses/trace/lib_tracebits.c
@@ -0,0 +1,219 @@
+/* $OpenBSD: lib_tracebits.c,v 1.1 1999/01/18 19:10:24 millert Exp $ */
+
+/****************************************************************************
+ * Copyright (c) 1998 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> *
+ ****************************************************************************/
+
+#include <curses.priv.h>
+#include <term.h> /* cur_term */
+
+MODULE_ID("$From: lib_tracebits.c,v 1.1 1998/11/08 00:20:32 tom Exp $")
+
+#if defined(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>
+#include <fcntl.h>
+#endif
+
+/* may be undefined if we're using termio.h */
+#ifndef TOSTOP
+#define TOSTOP 0
+#endif
+#ifndef IEXTEN
+#define IEXTEN 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,"} ");
+}
+
+char *_nc_tracebits(void)
+/* describe the state of the terminal control bits exactly */
+{
+char *buf;
+static const BITNAMES
+
+#ifdef TERMIOS
+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"},
+ {0, NULL}
+#define ALLOUT (OPOST)
+ },
+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 (cur_term->Nttyb.c_iflag & ALLIN)
+ lookup_bits(buf, iflags, "iflags", cur_term->Nttyb.c_iflag);
+
+ if (cur_term->Nttyb.c_oflag & ALLOUT)
+ lookup_bits(buf, oflags, "oflags", cur_term->Nttyb.c_oflag);
+
+ if (cur_term->Nttyb.c_cflag & ALLCTRL)
+ lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.c_cflag);
+
+#if defined(CS5) && defined(CS8)
+ switch (cur_term->Nttyb.c_cflag & CSIZE) {
+ case CS5: strcat(buf, "CS5 "); break;
+ case CS6: strcat(buf, "CS6 "); break;
+ case CS7: strcat(buf, "CS7 "); break;
+ case CS8: strcat(buf, "CS8 "); break;
+ default: strcat(buf, "CSIZE? "); break;
+ }
+#endif
+
+ if (cur_term->Nttyb.c_lflag & ALLLOCAL)
+ lookup_bits(buf, lflags, "lflags", cur_term->Nttyb.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
+
+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 (cur_term->Nttyb.sg_flags & ALLCTRL)
+ {
+ lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.sg_flags);
+ }
+
+#endif
+ return(buf);
+}
+#else
+char *_nc_tracebits(void) { return ""; }
+#endif /* TRACE */
diff --git a/lib/libcurses/trace/lib_tracechr.c b/lib/libcurses/trace/lib_tracechr.c
new file mode 100644
index 00000000000..e97e6793146
--- /dev/null
+++ b/lib/libcurses/trace/lib_tracechr.c
@@ -0,0 +1,69 @@
+/****************************************************************************
+ * Copyright (c) 1998 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> *
+ ****************************************************************************/
+
+
+
+/*
+ * lib_tracechr.c - Tracing/Debugging routines
+ */
+
+#ifndef TRACE
+#define TRACE /* turn on internal defs for this module */
+#endif
+
+#include <curses.priv.h>
+
+#include <ctype.h>
+
+#ifdef TRACE
+char *_tracechar(const unsigned char ch)
+{
+ static char crep[20];
+ /*
+ * We can show the actual character if it's either an ordinary printable
+ * or one of the high-half characters.
+ */
+ if (isprint(ch) || (ch & 0x80))
+ {
+ crep[0] = '\'';
+ crep[1] = ch; /* necessary; printf tries too hard on metachars */
+ (void) sprintf(crep + 2, "' = 0x%02x", (unsigned)ch);
+ }
+ else
+ (void) sprintf(crep, "0x%02x", (unsigned)ch);
+ return(crep);
+}
+#else
+extern void _nc_lib_tracechr(void);
+ void _nc_lib_tracechr(void) { }
+#endif
diff --git a/lib/libcurses/trace/lib_tracedmp.c b/lib/libcurses/trace/lib_tracedmp.c
new file mode 100644
index 00000000000..50859050044
--- /dev/null
+++ b/lib/libcurses/trace/lib_tracedmp.c
@@ -0,0 +1,130 @@
+/* $OpenBSD: lib_tracedmp.c,v 1.1 1999/01/18 19:10:24 millert Exp $ */
+
+/****************************************************************************
+ * Copyright (c) 1998 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> *
+ ****************************************************************************/
+
+/*
+ * lib_tracedmp.c - Tracing/Debugging routines
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$From: lib_tracedmp.c,v 1.13 1998/03/21 18:39:44 tom Exp $")
+
+#ifdef TRACE
+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 (win->_line[i].text[j] != ' ')
+ n = j;
+
+ if (n > width)
+ width = n;
+ }
+ if (width < win->_maxx)
+ ++width;
+
+ for (n = 0; n <= win->_maxy; n++)
+ {
+ char buf[BUFSIZ], *ep;
+ bool haveattrs, havecolors;
+
+ /* dump A_CHARTEXT part */
+ (void) sprintf(buf, "%s[%2d] %3d%3d ='",
+ name, n,
+ win->_line[n].firstchar,
+ win->_line[n].lastchar);
+ ep = buf + strlen(buf);
+ for (j = 0; j <= width; j++) {
+ ep[j] = TextOf(win->_line[n].text[j]);
+ if (ep[j] == 0)
+ ep[j] = '.';
+ }
+ ep[j] = '\'';
+ ep[j+1] = '\0';
+ _tracef("%s", buf);
+
+ /* dump A_COLOR part, will screw up if there are more than 96 */
+ havecolors = FALSE;
+ for (j = 0; j <= width; j++)
+ if (win->_line[n].text[j] & A_COLOR)
+ {
+ havecolors = TRUE;
+ break;
+ }
+ if (havecolors)
+ {
+ (void) sprintf(buf, "%*s[%2d]%*s='", (int)strlen(name), "colors", n, 8, " ");
+ ep = buf + strlen(buf);
+ for (j = 0; j <= width; j++)
+ ep[j] = ((win->_line[n].text[j] >> 8) & 0xff) + ' ';
+ ep[j] = '\'';
+ ep[j+1] = '\0';
+ _tracef("%s", buf);
+ }
+
+ for (i = 0; i < 4; i++)
+ {
+ const char *hex = " 123456789ABCDEF";
+ chtype mask = (0xf << ((i + 4) * 4));
+
+ haveattrs = FALSE;
+ for (j = 0; j <= width; j++)
+ if (win->_line[n].text[j] & mask)
+ {
+ haveattrs = TRUE;
+ break;
+ }
+ if (haveattrs)
+ {
+ (void) sprintf(buf, "%*s%d[%2d]%*s='", (int)strlen(name)-1, "attrs", i, n, 8, " ");
+ ep = buf + strlen(buf);
+ for (j = 0; j <= width; j++)
+ ep[j] = hex[(win->_line[n].text[j] & mask) >> ((i + 4) * 4)];
+ ep[j] = '\'';
+ ep[j+1] = '\0';
+ _tracef("%s", buf);
+ }
+ }
+ }
+}
+#else
+extern void _nc_lib_tracedmp(void);
+ void _nc_lib_tracedmp(void) { }
+#endif /* TRACE */
diff --git a/lib/libcurses/trace/lib_tracemse.c b/lib/libcurses/trace/lib_tracemse.c
new file mode 100644
index 00000000000..a1b649f5c88
--- /dev/null
+++ b/lib/libcurses/trace/lib_tracemse.c
@@ -0,0 +1,97 @@
+/* $OpenBSD: lib_tracemse.c,v 1.1 1999/01/18 19:10:24 millert Exp $ */
+
+/****************************************************************************
+ * Copyright (c) 1998 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> *
+ ****************************************************************************/
+
+
+
+/*
+ * lib_tracemse.c - Tracing/Debugging routines (mouse events)
+ */
+
+#include <curses.priv.h>
+
+MODULE_ID("$From: lib_tracemse.c,v 1.6 1998/11/16 14:28:17 Alexander.V.Lukyanov Exp $")
+
+#ifdef TRACE
+
+char *_tracemouse(MEVENT const *ep)
+{
+ static char buf[80];
+
+ (void) sprintf(buf, "id %2d at (%2d, %2d, %2d) state %4lx = {",
+ ep->id, ep->x, ep->y, ep->z, ep->bstate);
+
+#define SHOW(m, s) if ((ep->bstate & m)==m) {strcat(buf,s); strcat(buf, ", ");}
+ 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")
+ SHOW(BUTTON1_RESERVED_EVENT, "reserved-1")
+ 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")
+ SHOW(BUTTON2_RESERVED_EVENT, "reserved-2")
+ 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")
+ SHOW(BUTTON3_RESERVED_EVENT, "reserved-3")
+ 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")
+ SHOW(BUTTON4_RESERVED_EVENT, "reserved-4")
+ 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 (buf[strlen(buf)-1] == ' ')
+ buf[strlen(buf)-2] = '\0';
+ (void) strcat(buf, "}");
+ return(buf);
+}
+
+#else /* !TRACE */
+/* don't make empty module */
+void _nc_lib_tracemouse(void);
+void _nc_lib_tracemouse(void) {}
+#endif
diff --git a/lib/libcurses/trace/trace_buf.c b/lib/libcurses/trace/trace_buf.c
new file mode 100644
index 00000000000..11117c5326b
--- /dev/null
+++ b/lib/libcurses/trace/trace_buf.c
@@ -0,0 +1,83 @@
+/* $OpenBSD: trace_buf.c,v 1.1 1999/01/18 19:10:25 millert Exp $ */
+
+/****************************************************************************
+ * Copyright (c) 1998 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("$From: trace_buf.c,v 1.6 1998/08/15 23:37:25 tom Exp $")
+
+typedef struct {
+ char *text;
+ size_t size;
+} LIST;
+
+char * _nc_trace_buf(int bufnum, size_t want)
+{
+ static LIST *list;
+ static size_t have;
+
+#if NO_LEAKS
+ if (bufnum < 0) {
+ if (have) {
+ while (have--) {
+ free(list[have].text);
+ }
+ free(list);
+ }
+ return 0;
+ }
+#endif
+
+ if ((size_t)(bufnum+1) > have) {
+ size_t need = (bufnum + 1) * 2;
+ size_t used = sizeof(*list) * need;
+ if ((list = (LIST *)_nc_doalloc(list, used)) == 0)
+ return(0);
+ while (need > have)
+ list[have++].text = 0;
+ }
+
+ if (list[bufnum].text == 0
+ || want > list[bufnum].size)
+ {
+ if ((list[bufnum].text = (char *)_nc_doalloc(list[bufnum].text, want)) != 0)
+ list[bufnum].size = want;
+ }
+
+ if (list[bufnum].text != 0)
+ *(list[bufnum].text) = '\0';
+ return list[bufnum].text;
+}