lib_tracedmp.c revision 50276
1/****************************************************************************
2 * Copyright (c) 1998 Free Software Foundation, Inc.                        *
3 *                                                                          *
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:                 *
11 *                                                                          *
12 * The above copyright notice and this permission notice shall be included  *
13 * in all copies or substantial portions of the Software.                   *
14 *                                                                          *
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.                               *
22 *                                                                          *
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       *
26 * authorization.                                                           *
27 ****************************************************************************/
28
29/****************************************************************************
30 *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31 *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32 ****************************************************************************/
33
34/*
35 *	lib_tracedmp.c - Tracing/Debugging routines
36 */
37
38#include <curses.priv.h>
39
40MODULE_ID("$Id: lib_tracedmp.c,v 1.13 1998/03/21 18:39:44 tom Exp $")
41
42#ifdef TRACE
43void _tracedump(const char *name, WINDOW *win)
44{
45    int	i, j, n, width;
46
47    /* compute narrowest possible display width */
48    for (width = i = 0; i <= win->_maxy; i++)
49    {
50	n = 0;
51	for (j = 0; j <= win->_maxx; j++)
52	  if (win->_line[i].text[j] != ' ')
53	    n = j;
54
55	if (n > width)
56	  width = n;
57    }
58    if (width < win->_maxx)
59      ++width;
60
61    for (n = 0; n <= win->_maxy; n++)
62    {
63	char	buf[BUFSIZ], *ep;
64	bool haveattrs, havecolors;
65
66	/* dump A_CHARTEXT part */
67	(void) sprintf(buf, "%s[%2d] %3d%3d ='",
68		name, n,
69		win->_line[n].firstchar,
70		win->_line[n].lastchar);
71	ep = buf + strlen(buf);
72	for (j = 0; j <= width; j++) {
73	    ep[j] = TextOf(win->_line[n].text[j]);
74	    if (ep[j] == 0)
75	    	ep[j] = '.';
76	}
77	ep[j] = '\'';
78	ep[j+1] = '\0';
79	_tracef("%s", buf);
80
81	/* dump A_COLOR part, will screw up if there are more than 96 */
82	havecolors = FALSE;
83	for (j = 0; j <= width; j++)
84	    if (win->_line[n].text[j] & A_COLOR)
85	    {
86		havecolors = TRUE;
87		break;
88	    }
89	if (havecolors)
90	{
91	    (void) sprintf(buf, "%*s[%2d]%*s='", (int)strlen(name), "colors", n, 8, " ");
92	    ep = buf + strlen(buf);
93	    for (j = 0; j <= width; j++)
94		ep[j] = ((win->_line[n].text[j] >> 8) & 0xff) + ' ';
95	    ep[j] = '\'';
96	    ep[j+1] = '\0';
97	    _tracef("%s", buf);
98	}
99
100	for (i = 0; i < 4; i++)
101	{
102	    const char	*hex = " 123456789ABCDEF";
103	    chtype	mask = (0xf << ((i + 4) * 4));
104
105	    haveattrs = FALSE;
106	    for (j = 0; j <= width; j++)
107		if (win->_line[n].text[j] & mask)
108		{
109		    haveattrs = TRUE;
110		    break;
111		}
112	    if (haveattrs)
113	    {
114		(void) sprintf(buf, "%*s%d[%2d]%*s='", (int)strlen(name)-1, "attrs", i, n, 8, " ");
115		ep = buf + strlen(buf);
116		for (j = 0; j <= width; j++)
117		    ep[j] = hex[(win->_line[n].text[j] & mask) >> ((i + 4) * 4)];
118		ep[j] = '\'';
119		ep[j+1] = '\0';
120		_tracef("%s", buf);
121	    }
122	}
123    }
124}
125#else
126extern	void _nc_lib_tracedmp(void);
127	void _nc_lib_tracedmp(void) { }
128#endif /* TRACE */
129