1 /****************************************************************************
2 * Copyright 2020 Thomas E. Dickey *
3 * Copyright 1998-2012,2016 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Thomas E. Dickey 1996-on *
32 * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
33 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
34 ****************************************************************************/
37 * lib_tracedmp.c - Tracing/Debugging routines
40 #include <curses.priv.h>
43 MODULE_ID("$Id: lib_tracedmp.c,v 1.36 2020/02/02 23:34:34 tom Exp $")
47 #define my_buffer _nc_globals.tracedmp_buf
48 #define my_length _nc_globals.tracedmp_used
51 _tracedump(const char *name, WINDOW *win)
55 /* compute narrowest possible display width */
56 for (width = i = 0; i <= win->_maxy; ++i) {
58 for (j = 0; j <= win->_maxx; ++j) {
59 if (CharOf(win->_line[i].text[j]) != L(' ')
60 || AttrOf(win->_line[i].text[j]) != A_NORMAL
61 || GetPair(win->_line[i].text[j]) != 0) {
69 if (width < win->_maxx)
71 if (++width + 1 > (int) my_length) {
72 my_length = (unsigned) (2 * (width + 1));
73 my_buffer = typeRealloc(char, my_length, my_buffer);
78 for (n = 0; n <= win->_maxy; ++n) {
83 * Dump A_CHARTEXT part. It is more important to make the grid line up
84 * in the trace file than to represent control- and wide-characters, so
85 * we map those to '.' and '?' respectively.
87 for (j = 0; j < width; ++j) {
88 chtype test = (chtype) CharOf(win->_line[n].text[j]);
89 ep[j] = (char) ((UChar(test) == test
91 && (win->_line[n].text[j].chars[1] == 0)
94 ? (iscntrl(UChar(test))
100 _tracef("%s[%2d] %3ld%3ld ='%s'",
102 (long) win->_line[n].firstchar,
103 (long) win->_line[n].lastchar,
106 /* if there are multi-column characters on the line, print them now */
108 bool multicolumn = FALSE;
109 for (j = 0; j < width; ++j)
110 if (WidecExt(win->_line[n].text[j]) != 0) {
116 for (j = 0; j < width; ++j) {
117 int test = WidecExt(win->_line[n].text[j]);
119 ep[j] = (char) (test + '0');
125 _tracef("%*s[%2d]%*s='%s'", (int) strlen(name),
126 "widec", n, 8, " ", my_buffer);
130 /* dump A_COLOR part, will screw up if there are more than 96 */
132 for (j = 0; j < width; ++j)
133 if (GetPair(win->_line[n].text[j]) != 0) {
139 for (j = 0; j < width; ++j) {
140 int pair = GetPair(win->_line[n].text[j]);
144 ep[j] = (char) (pair + 'A');
146 ep[j] = (char) (pair + 'a');
148 ep[j] = (char) (pair + '0');
153 _tracef("%*s[%2d]%*s='%s'", (int) strlen(name),
154 "colors", n, 8, " ", my_buffer);
157 for (i = 0; i < 4; ++i) {
158 const char *hex = " 123456789ABCDEF";
159 attr_t mask = (attr_t) (0xf << ((i + 4) * 4));
160 bool haveattrs = FALSE;
162 for (j = 0; j < width; ++j)
163 if (AttrOf(win->_line[n].text[j]) & mask) {
169 for (j = 0; j < width; ++j)
170 ep[j] = hex[(AttrOf(win->_line[n].text[j]) & mask) >>
173 _tracef("%*s%d[%2d]%*s='%s'", (int) strlen(name) -
174 1, "attrs", i, n, 8, " ", my_buffer);
186 EMPTY_MODULE(_nc_lib_tracedmp)