GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: lib/libcurses/trace/lib_tracedmp.c Lines: 0 1 0.0 %
Date: 2017-11-13 Branches: 0 0 0.0 %

Line Branch Exec Source
1
/* $OpenBSD: lib_tracedmp.c,v 1.4 2010/01/12 23:22:07 nicm Exp $ */
2
3
/****************************************************************************
4
 * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc.              *
5
 *                                                                          *
6
 * Permission is hereby granted, free of charge, to any person obtaining a  *
7
 * copy of this software and associated documentation files (the            *
8
 * "Software"), to deal in the Software without restriction, including      *
9
 * without limitation the rights to use, copy, modify, merge, publish,      *
10
 * distribute, distribute with modifications, sublicense, and/or sell       *
11
 * copies of the Software, and to permit persons to whom the Software is    *
12
 * furnished to do so, subject to the following conditions:                 *
13
 *                                                                          *
14
 * The above copyright notice and this permission notice shall be included  *
15
 * in all copies or substantial portions of the Software.                   *
16
 *                                                                          *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20
 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21
 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22
 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23
 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24
 *                                                                          *
25
 * Except as contained in this notice, the name(s) of the above copyright   *
26
 * holders shall not be used in advertising or otherwise to promote the     *
27
 * sale, use or other dealings in this Software without prior written       *
28
 * authorization.                                                           *
29
 ****************************************************************************/
30
31
/****************************************************************************
32
 *  Author: Thomas E. Dickey 1996-on                                        *
33
 *     and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
34
 *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
35
 ****************************************************************************/
36
37
/*
38
 *	lib_tracedmp.c - Tracing/Debugging routines
39
 */
40
41
#include <curses.priv.h>
42
#include <ctype.h>
43
44
MODULE_ID("$Id: lib_tracedmp.c,v 1.4 2010/01/12 23:22:07 nicm Exp $")
45
46
#ifdef TRACE
47
48
#define my_buffer _nc_globals.tracedmp_buf
49
#define my_length _nc_globals.tracedmp_used
50
51
NCURSES_EXPORT(void)
52
_tracedump(const char *name, WINDOW *win)
53
{
54
    int i, j, n, width;
55
56
    /* compute narrowest possible display width */
57
    for (width = i = 0; i <= win->_maxy; ++i) {
58
	n = 0;
59
	for (j = 0; j <= win->_maxx; ++j) {
60
	    if (CharOf(win->_line[i].text[j]) != L(' ')
61
		|| AttrOf(win->_line[i].text[j]) != A_NORMAL
62
		|| GetPair(win->_line[i].text[j]) != 0) {
63
		n = j;
64
	    }
65
	}
66
67
	if (n > width)
68
	    width = n;
69
    }
70
    if (width < win->_maxx)
71
	++width;
72
    if (++width + 1 > (int) my_length) {
73
	my_length = 2 * (width + 1);
74
	my_buffer = typeRealloc(char, my_length, my_buffer);
75
    }
76
77
    for (n = 0; n <= win->_maxy; ++n) {
78
	char *ep = my_buffer;
79
	bool haveattrs, havecolors;
80
81
	/*
82
	 * Dump A_CHARTEXT part.  It is more important to make the grid line up
83
	 * in the trace file than to represent control- and wide-characters, so
84
	 * we map those to '.' and '?' respectively.
85
	 */
86
	for (j = 0; j < width; ++j) {
87
	    chtype test = CharOf(win->_line[n].text[j]);
88
	    ep[j] = (char) ((UChar(test) == test
89
#if USE_WIDEC_SUPPORT
90
			     && (win->_line[n].text[j].chars[1] == 0)
91
#endif
92
			    )
93
			    ? (iscntrl(UChar(test))
94
			       ? '.'
95
			       : UChar(test))
96
			    : '?');
97
	}
98
	ep[j] = '\0';
99
	_tracef("%s[%2d] %3ld%3ld ='%s'",
100
		name, n,
101
		(long) win->_line[n].firstchar,
102
		(long) win->_line[n].lastchar,
103
		ep);
104
105
	/* if there are multi-column characters on the line, print them now */
106
	if_WIDEC({
107
	    bool multicolumn = FALSE;
108
	    for (j = 0; j < width; ++j)
109
		if (WidecExt(win->_line[n].text[j]) != 0) {
110
		    multicolumn = TRUE;
111
		    break;
112
		}
113
	    if (multicolumn) {
114
		ep = my_buffer;
115
		for (j = 0; j < width; ++j) {
116
		    int test = WidecExt(win->_line[n].text[j]);
117
		    if (test) {
118
			ep[j] = (char) (test + '0');
119
		    } else {
120
			ep[j] = ' ';
121
		    }
122
		}
123
		ep[j] = '\0';
124
		_tracef("%*s[%2d]%*s='%s'", (int) strlen(name),
125
			"widec", n, 8, " ", my_buffer);
126
	    }
127
	});
128
129
	/* dump A_COLOR part, will screw up if there are more than 96 */
130
	havecolors = FALSE;
131
	for (j = 0; j < width; ++j)
132
	    if (GetPair(win->_line[n].text[j]) != 0) {
133
		havecolors = TRUE;
134
		break;
135
	    }
136
	if (havecolors) {
137
	    ep = my_buffer;
138
	    for (j = 0; j < width; ++j) {
139
		int pair = GetPair(win->_line[n].text[j]);
140
		if (pair >= 52)
141
		    ep[j] = '?';
142
		else if (pair >= 36)
143
		    ep[j] = (char) (pair + 'A');
144
		else if (pair >= 10)
145
		    ep[j] = (char) (pair + 'a');
146
		else if (pair >= 1)
147
		    ep[j] = (char) (pair + '0');
148
		else
149
		    ep[j] = ' ';
150
	    }
151
	    ep[j] = '\0';
152
	    _tracef("%*s[%2d]%*s='%s'", (int) strlen(name),
153
		    "colors", n, 8, " ", my_buffer);
154
	}
155
156
	for (i = 0; i < 4; ++i) {
157
	    const char *hex = " 123456789ABCDEF";
158
	    attr_t mask = (0xf << ((i + 4) * 4));
159
160
	    haveattrs = FALSE;
161
	    for (j = 0; j < width; ++j)
162
		if (AttrOf(win->_line[n].text[j]) & mask) {
163
		    haveattrs = TRUE;
164
		    break;
165
		}
166
	    if (haveattrs) {
167
		ep = my_buffer;
168
		for (j = 0; j < width; ++j)
169
		    ep[j] = hex[(AttrOf(win->_line[n].text[j]) & mask) >>
170
				((i + 4) * 4)];
171
		ep[j] = '\0';
172
		_tracef("%*s%d[%2d]%*s='%s'", (int) strlen(name) -
173
			1, "attrs", i, n, 8, " ", my_buffer);
174
	    }
175
	}
176
    }
177
#if NO_LEAKS
178
    free(my_buffer);
179
    my_buffer = 0;
180
    my_length = 0;
181
#endif
182
}
183
184
#else
185
EMPTY_MODULE(_nc_lib_tracedmp)
186
#endif /* TRACE */