lib_tracedmp.c revision 76726
1178172Simp/****************************************************************************
2178172Simp * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
3178172Simp *                                                                          *
4178172Simp * Permission is hereby granted, free of charge, to any person obtaining a  *
5178172Simp * copy of this software and associated documentation files (the            *
6178172Simp * "Software"), to deal in the Software without restriction, including      *
7178172Simp * without limitation the rights to use, copy, modify, merge, publish,      *
8178172Simp * distribute, distribute with modifications, sublicense, and/or sell       *
9178172Simp * copies of the Software, and to permit persons to whom the Software is    *
10178172Simp * furnished to do so, subject to the following conditions:                 *
11178172Simp *                                                                          *
12178172Simp * The above copyright notice and this permission notice shall be included  *
13178172Simp * in all copies or substantial portions of the Software.                   *
14178172Simp *                                                                          *
15178172Simp * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16178172Simp * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17178172Simp * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18178172Simp * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19178172Simp * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20178172Simp * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21178172Simp * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22178172Simp *                                                                          *
23178172Simp * Except as contained in this notice, the name(s) of the above copyright   *
24178172Simp * holders shall not be used in advertising or otherwise to promote the     *
25178172Simp * sale, use or other dealings in this Software without prior written       *
26178172Simp * authorization.                                                           *
27178172Simp ****************************************************************************/
28178172Simp
29178172Simp/****************************************************************************
30178172Simp *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31178172Simp *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32178172Simp ****************************************************************************/
33178172Simp
34178172Simp/*
35178172Simp *	lib_tracedmp.c - Tracing/Debugging routines
36178172Simp */
37178172Simp
38178172Simp#include <curses.priv.h>
39178172Simp
40178172SimpMODULE_ID("$Id: lib_tracedmp.c,v 1.16 2000/12/10 03:02:45 tom Exp $")
41178172Simp
42196994Sphk#ifdef TRACE
43196994SphkNCURSES_EXPORT(void)
44178172Simp_tracedump(const char *name, WINDOW *win)
45196994Sphk{
46196994Sphk    int i, j, n, width;
47178172Simp
48178172Simp    /* compute narrowest possible display width */
49206717Sjmallett    for (width = i = 0; i <= win->_maxy; i++) {
50178172Simp	n = 0;
51178172Simp	for (j = 0; j <= win->_maxx; j++)
52178172Simp	    if (win->_line[i].text[j] != ' ')
53178172Simp		n = j;
54178172Simp
55178172Simp	if (n > width)
56178172Simp	    width = n;
57178172Simp    }
58178172Simp    if (width < win->_maxx)
59178172Simp	++width;
60178172Simp
61178172Simp    for (n = 0; n <= win->_maxy; n++) {
62178172Simp	char buf[BUFSIZ], *ep;
63178172Simp	bool haveattrs, havecolors;
64178172Simp
65178172Simp	/* dump A_CHARTEXT part */
66178172Simp	(void) sprintf(buf, "%s[%2d] %3d%3d ='",
67178172Simp		       name, n,
68178172Simp		       win->_line[n].firstchar,
69178172Simp		       win->_line[n].lastchar);
70178172Simp	ep = buf + strlen(buf);
71178172Simp	for (j = 0; j <= width; j++) {
72178172Simp	    ep[j] = TextOf(win->_line[n].text[j]);
73208165Srrs	    if (ep[j] == 0)
74178172Simp		ep[j] = '.';
75178172Simp	}
76178172Simp	ep[j] = '\'';
77178172Simp	ep[j + 1] = '\0';
78178172Simp	_tracef("%s", buf);
79178172Simp
80178172Simp	/* dump A_COLOR part, will screw up if there are more than 96 */
81178172Simp	havecolors = FALSE;
82178172Simp	for (j = 0; j <= width; j++)
83178172Simp	    if (win->_line[n].text[j] & A_COLOR) {
84178172Simp		havecolors = TRUE;
85178172Simp		break;
86178172Simp	    }
87178172Simp	if (havecolors) {
88195376Ssam	    (void) sprintf(buf, "%*s[%2d]%*s='", (int) strlen(name),
89195376Ssam			   "colors", n, 8, " ");
90195376Ssam	    ep = buf + strlen(buf);
91195376Ssam	    for (j = 0; j <= width; j++)
92195376Ssam		ep[j] = CharOf(win->_line[n].text[j] >> 8) + ' ';
93195376Ssam	    ep[j] = '\'';
94202031Simp	    ep[j + 1] = '\0';
95178172Simp	    _tracef("%s", buf);
96191278Srwatson	}
97191278Srwatson
98191278Srwatson	for (i = 0; i < 4; i++) {
99191278Srwatson	    const char *hex = " 123456789ABCDEF";
100191276Srwatson	    chtype mask = (0xf << ((i + 4) * 4));
101191276Srwatson
102191276Srwatson	    haveattrs = FALSE;
103178172Simp	    for (j = 0; j <= width; j++)
104178172Simp		if (win->_line[n].text[j] & mask) {
105178172Simp		    haveattrs = TRUE;
106210627Sjchandra		    break;
107178172Simp		}
108206746Sjmallett	    if (haveattrs) {
109178172Simp		(void) sprintf(buf, "%*s%d[%2d]%*s='", (int) strlen(name) -
110210846Sjchandra			       1, "attrs", i, n, 8, " ");
111210846Sjchandra		ep = buf + strlen(buf);
112210846Sjchandra		for (j = 0; j <= width; j++)
113210846Sjchandra		    ep[j] = hex[(win->_line[n].text[j] & mask) >> ((i + 4) * 4)];
114210846Sjchandra		ep[j] = '\'';
115210846Sjchandra		ep[j + 1] = '\0';
116210627Sjchandra		_tracef("%s", buf);
117210627Sjchandra	    }
118210846Sjchandra	}
119210846Sjchandra    }
120210846Sjchandra}
121210846Sjchandra#else
122210627Sjchandraextern
123210627SjchandraNCURSES_EXPORT(void)
124197316Salc_nc_lib_tracedmp(void);
125197316SalcNCURSES_EXPORT(void)
126183441Simp_nc_lib_tracedmp(void)
127183441Simp{
128178172Simp}
129178172Simp#endif /* TRACE */
130205072Sneel