]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/lib_tracedmp.c
ncurses 4.2
[ncurses.git] / ncurses / lib_tracedmp.c
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 #ifndef TRACE
39 #define TRACE                   /* turn on internal defs for this module */
40 #endif
41
42 #include <curses.priv.h>
43
44 MODULE_ID("$Id: lib_tracedmp.c,v 1.11 1998/02/11 12:14:00 tom Exp $")
45
46 void _tracedump(const char *name, WINDOW *win)
47 {
48     int i, j, n, width;
49
50     /* compute narrowest possible display width */
51     for (width = i = 0; i <= win->_maxy; i++)
52     {
53         n = 0;
54         for (j = 0; j <= win->_maxx; j++)
55           if (win->_line[i].text[j] != ' ')
56             n = j;
57
58         if (n > width)
59           width = n;
60     }
61     if (width < win->_maxx)
62       ++width;
63
64     for (n = 0; n <= win->_maxy; n++)
65     {
66         char    buf[BUFSIZ], *ep;
67         bool haveattrs, havecolors;
68
69         /* dump A_CHARTEXT part */
70         (void) sprintf(buf, "%s[%2d] %3d%3d ='",
71                 name, n,
72                 win->_line[n].firstchar,
73                 win->_line[n].lastchar);
74         ep = buf + strlen(buf);
75         for (j = 0; j <= width; j++) {
76             ep[j] = TextOf(win->_line[n].text[j]);
77             if (ep[j] == 0)
78                 ep[j] = '.';
79         }
80         ep[j] = '\'';
81         ep[j+1] = '\0';
82         _tracef("%s", buf);
83
84         /* dump A_COLOR part, will screw up if there are more than 96 */
85         havecolors = FALSE;
86         for (j = 0; j <= width; j++)
87             if (win->_line[n].text[j] & A_COLOR)
88             {
89                 havecolors = TRUE;
90                 break;
91             }
92         if (havecolors)
93         {
94             (void) sprintf(buf, "%*s[%2d]%*s='", (int)strlen(name), "colors", n, 8, " ");
95             ep = buf + strlen(buf);
96             for (j = 0; j <= width; j++)
97                 ep[j] = ((win->_line[n].text[j] >> 8) & 0xff) + ' ';
98             ep[j] = '\'';
99             ep[j+1] = '\0';
100             _tracef("%s", buf);
101         }
102
103         for (i = 0; i < 4; i++)
104         {
105             const char  *hex = " 123456789ABCDEF";
106             chtype      mask = (0xf << ((i + 4) * 4));
107
108             haveattrs = FALSE;
109             for (j = 0; j <= width; j++)
110                 if (win->_line[n].text[j] & mask)
111                 {
112                     haveattrs = TRUE;
113                     break;
114                 }
115             if (haveattrs)
116             {
117                 (void) sprintf(buf, "%*s%d[%2d]%*s='", (int)strlen(name)-1, "attrs", i, n, 8, " ");
118                 ep = buf + strlen(buf);
119                 for (j = 0; j <= width; j++)
120                     ep[j] = hex[(win->_line[n].text[j] & mask) >> ((i + 4) * 4)];
121                 ep[j] = '\'';
122                 ep[j+1] = '\0';
123                 _tracef("%s", buf);
124             }
125         }
126     }
127 }