1 /****************************************************************************
2 * Copyright (c) 1998-2008,2009 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-on *
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.32 2009/04/18 21:01:38 tom Exp $")
46 #define my_buffer _nc_globals.tracedmp_buf
47 #define my_length _nc_globals.tracedmp_used
50 _tracedump(const char *name, WINDOW *win)
54 /* compute narrowest possible display width */
55 for (width = i = 0; i <= win->_maxy; ++i) {
57 for (j = 0; j <= win->_maxx; ++j) {
58 if (CharOf(win->_line[i].text[j]) != L(' ')
59 || AttrOf(win->_line[i].text[j]) != A_NORMAL
60 || GetPair(win->_line[i].text[j]) != 0) {
68 if (width < win->_maxx)
70 if (++width + 1 > (int) my_length) {
71 my_length = (unsigned) (2 * (width + 1));
72 my_buffer = typeRealloc(char, my_length, my_buffer);
75 for (n = 0; n <= win->_maxy; ++n) {
77 bool haveattrs, havecolors;
80 * Dump A_CHARTEXT part. It is more important to make the grid line up
81 * in the trace file than to represent control- and wide-characters, so
82 * we map those to '.' and '?' respectively.
84 for (j = 0; j < width; ++j) {
85 chtype test = (chtype) CharOf(win->_line[n].text[j]);
86 ep[j] = (char) ((UChar(test) == test
88 && (win->_line[n].text[j].chars[1] == 0)
91 ? (iscntrl(UChar(test))
97 _tracef("%s[%2d] %3ld%3ld ='%s'",
99 (long) win->_line[n].firstchar,
100 (long) win->_line[n].lastchar,
103 /* if there are multi-column characters on the line, print them now */
105 bool multicolumn = FALSE;
106 for (j = 0; j < width; ++j)
107 if (WidecExt(win->_line[n].text[j]) != 0) {
113 for (j = 0; j < width; ++j) {
114 chtype test = WidecExt(win->_line[n].text[j]);
116 ep[j] = (char) (test + '0');
122 _tracef("%*s[%2d]%*s='%s'", (int) strlen(name),
123 "widec", n, 8, " ", my_buffer);
127 /* dump A_COLOR part, will screw up if there are more than 96 */
129 for (j = 0; j < width; ++j)
130 if (GetPair(win->_line[n].text[j]) != 0) {
136 for (j = 0; j < width; ++j) {
137 int pair = GetPair(win->_line[n].text[j]);
141 ep[j] = (char) (pair + 'A');
143 ep[j] = (char) (pair + 'a');
145 ep[j] = (char) (pair + '0');
150 _tracef("%*s[%2d]%*s='%s'", (int) strlen(name),
151 "colors", n, 8, " ", my_buffer);
154 for (i = 0; i < 4; ++i) {
155 const char *hex = " 123456789ABCDEF";
156 attr_t mask = (attr_t) (0xf << ((i + 4) * 4));
159 for (j = 0; j < width; ++j)
160 if (AttrOf(win->_line[n].text[j]) & mask) {
166 for (j = 0; j < width; ++j)
167 ep[j] = hex[(AttrOf(win->_line[n].text[j]) & mask) >>
170 _tracef("%*s%d[%2d]%*s='%s'", (int) strlen(name) -
171 1, "attrs", i, n, 8, " ", my_buffer);
183 EMPTY_MODULE(_nc_lib_tracedmp)