summaryrefslogtreecommitdiff
path: root/lib/libcurses/trace/lib_tracedmp.c
diff options
context:
space:
mode:
authorNicholas Marriott <nicm@cvs.openbsd.org>2010-01-12 23:22:15 +0000
committerNicholas Marriott <nicm@cvs.openbsd.org>2010-01-12 23:22:15 +0000
commit6ee254699bf787d78835419be2b3241fb037d444 (patch)
tree07fe67dab517e4990f344fe2c00e65cef4d25b81 /lib/libcurses/trace/lib_tracedmp.c
parent0b62f5dc36fc7203a74cdc812c4234ae188fdfd2 (diff)
Update to ncurses 5.7, with local changes reapplied.
This is around eight years worth of changes (previously we were around ncurses 5.2), too many to list - many bug fixes and also a few new functions. A major bump for libcurses, libpanel, libform and libmenu. ok deraadt
Diffstat (limited to 'lib/libcurses/trace/lib_tracedmp.c')
-rw-r--r--lib/libcurses/trace/lib_tracedmp.c157
1 files changed, 106 insertions, 51 deletions
diff --git a/lib/libcurses/trace/lib_tracedmp.c b/lib/libcurses/trace/lib_tracedmp.c
index 4e557d65974..71759dc21db 100644
--- a/lib/libcurses/trace/lib_tracedmp.c
+++ b/lib/libcurses/trace/lib_tracedmp.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: lib_tracedmp.c,v 1.3 2003/03/17 19:16:59 millert Exp $ */
+/* $OpenBSD: lib_tracedmp.c,v 1.4 2010/01/12 23:22:07 nicm Exp $ */
/****************************************************************************
- * Copyright (c) 1998,2000 Free Software Foundation, Inc. *
+ * 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 *
@@ -29,7 +29,8 @@
****************************************************************************/
/****************************************************************************
- * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
+ * Author: Thomas E. Dickey 1996-on *
+ * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
****************************************************************************/
@@ -38,94 +39,148 @@
*/
#include <curses.priv.h>
+#include <ctype.h>
-MODULE_ID("$From: lib_tracedmp.c,v 1.16 2000/12/10 03:02:45 tom Exp $")
+MODULE_ID("$Id: lib_tracedmp.c,v 1.4 2010/01/12 23:22:07 nicm 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++) {
+ for (width = i = 0; i <= win->_maxy; ++i) {
n = 0;
- for (j = 0; j <= win->_maxx; j++)
- if (win->_line[i].text[j] != ' ')
+ 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 buf[BUFSIZ], *ep;
+ for (n = 0; n <= win->_maxy; ++n) {
+ char *ep = my_buffer;
bool haveattrs, havecolors;
- /* dump A_CHARTEXT part */
- (void) snprintf(buf, sizeof(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] = '.';
+ /*
+ * 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] = (char) ((UChar(test) == test
+#if USE_WIDEC_SUPPORT
+ && (win->_line[n].text[j].chars[1] == 0)
+#endif
+ )
+ ? (iscntrl(UChar(test))
+ ? '.'
+ : UChar(test))
+ : '?');
}
- ep[j] = '\'';
- ep[j + 1] = '\0';
- _tracef("%s", buf);
+ 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] = (char) (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 (win->_line[n].text[j] & A_COLOR) {
+ for (j = 0; j < width; ++j)
+ if (GetPair(win->_line[n].text[j]) != 0) {
havecolors = TRUE;
break;
}
if (havecolors) {
- (void) snprintf(buf, sizeof(buf), "%*s[%2d]%*s='",
- (int) strlen(name), "colors", n, 8, " ");
- ep = buf + strlen(buf);
- for (j = 0; j <= width; j++)
- ep[j] = CharOf(win->_line[n].text[j] >> 8) + ' ';
- ep[j] = '\'';
- ep[j + 1] = '\0';
- _tracef("%s", buf);
+ 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] = (char) (pair + 'A');
+ else if (pair >= 10)
+ ep[j] = (char) (pair + 'a');
+ else if (pair >= 1)
+ ep[j] = (char) (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++) {
+ for (i = 0; i < 4; ++i) {
const char *hex = " 123456789ABCDEF";
- chtype mask = (0xf << ((i + 4) * 4));
+ attr_t mask = (0xf << ((i + 4) * 4));
haveattrs = FALSE;
- for (j = 0; j <= width; j++)
- if (win->_line[n].text[j] & mask) {
+ for (j = 0; j < width; ++j)
+ if (AttrOf(win->_line[n].text[j]) & mask) {
haveattrs = TRUE;
break;
}
if (haveattrs) {
- (void) snprintf(buf, sizeof(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);
+ 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
-extern
-NCURSES_EXPORT(void)
-_nc_lib_tracedmp(void);
-NCURSES_EXPORT(void)
-_nc_lib_tracedmp(void)
-{
-}
+EMPTY_MODULE(_nc_lib_tracedmp)
#endif /* TRACE */