1 /****************************************************************************
2 * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Thomas E. Dickey 1996-2001 *
31 * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
32 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
33 ****************************************************************************/
36 * lib_tracedmp.c - Tracing/Debugging routines
39 #include <curses.priv.h>
42 MODULE_ID("$Id: lib_tracedmp.c,v 1.25 2002/09/22 22:21:38 tom Exp $")
46 _tracedump(const char *name, WINDOW *win)
49 static size_t used = 0;
53 /* compute narrowest possible display width */
54 for (width = i = 0; i <= win->_maxy; ++i) {
56 for (j = 0; j <= win->_maxx; ++j)
57 if (CharOf(win->_line[i].text[j]) != L(' ')
58 || AttrOf(win->_line[i].text[j]) != A_NORMAL)
64 if (width < win->_maxx)
66 if (++width + 1 > (int) used) {
67 used = 2 * (width + 1);
68 buf = typeRealloc(char, used, buf);
71 for (n = 0; n <= win->_maxy; ++n) {
73 bool haveattrs, havecolors;
76 * Dump A_CHARTEXT part. It is more important to make the grid line up
77 * in the trace file than to represent control- and wide-characters, so
78 * we map those to '.' and '?' respectively.
80 for (j = 0; j < width; ++j) {
81 chtype test = CharOf(win->_line[n].text[j]);
82 ep[j] = (UChar(test) == test
84 && (win->_line[n].text[j].chars[1] == 0)
87 ? (iscntrl(UChar(test))
93 _tracef("%s[%2d] %3d%3d ='%s'",
95 win->_line[n].firstchar,
96 win->_line[n].lastchar,
99 /* dump A_COLOR part, will screw up if there are more than 96 */
101 for (j = 0; j < width; ++j)
102 if (AttrOf(win->_line[n].text[j]) & A_COLOR) {
108 for (j = 0; j < width; ++j)
109 ep[j] = UChar(AttrOf(win->_line[n].text[j]) >>
110 NCURSES_ATTR_SHIFT) + ' ';
112 _tracef("%*s[%2d]%*s='%s'", (int) strlen(name),
113 "colors", n, 8, " ", buf);
116 for (i = 0; i < 4; ++i) {
117 const char *hex = " 123456789ABCDEF";
118 attr_t mask = (0xf << ((i + 4) * 4));
121 for (j = 0; j < width; ++j)
122 if (AttrOf(win->_line[n].text[j]) & mask) {
128 for (j = 0; j < width; ++j)
129 ep[j] = hex[(AttrOf(win->_line[n].text[j]) & mask) >>
132 _tracef("%*s%d[%2d]%*s='%s'", (int) strlen(name) -
133 1, "attrs", i, n, 8, " ", buf);
145 empty_module(_nc_lib_tracedmp)