]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/lib_tracedmp.c
ncurses 4.1
[ncurses.git] / ncurses / lib_tracedmp.c
1
2 /***************************************************************************
3 *                            COPYRIGHT NOTICE                              *
4 ****************************************************************************
5 *                ncurses is copyright (C) 1992-1995                        *
6 *                          Zeyd M. Ben-Halim                               *
7 *                          zmbenhal@netcom.com                             *
8 *                          Eric S. Raymond                                 *
9 *                          esr@snark.thyrsus.com                           *
10 *                                                                          *
11 *        Permission is hereby granted to reproduce and distribute ncurses  *
12 *        by any means and for any fee, whether alone or as part of a       *
13 *        larger distribution, in source or in binary form, PROVIDED        *
14 *        this notice is included with any such distribution, and is not    *
15 *        removed from any of its header files. Mention of ncurses in any   *
16 *        applications linked with it is highly appreciated.                *
17 *                                                                          *
18 *        ncurses comes AS IS with no warranty, implied or expressed.       *
19 *                                                                          *
20 ***************************************************************************/
21
22 /*
23  *      lib_tracedmp.c - Tracing/Debugging routines
24  */
25
26 #ifndef TRACE
27 #define TRACE                   /* turn on internal defs for this module */
28 #endif
29
30 #include <curses.priv.h>
31
32 MODULE_ID("$Id: lib_tracedmp.c,v 1.9 1997/01/15 00:39:27 tom Exp $")
33
34 void _tracedump(const char *name, WINDOW *win)
35 {
36     int i, j, n, width;
37
38     /* compute narrowest possible display width */
39     for (width = i = 0; i <= win->_maxy; i++)
40     {
41         n = 0;
42         for (j = 0; j <= win->_maxx; j++)
43           if (win->_line[i].text[j] != ' ')
44             n = j;
45
46         if (n > width)
47           width = n;
48     }
49     if (width < win->_maxx)
50       ++width;
51
52     for (n = 0; n <= win->_maxy; n++)
53     {
54         char    buf[BUFSIZ], *ep;
55         bool haveattrs, havecolors;
56
57         /* dump A_CHARTEXT part */
58         (void) sprintf(buf, "%s[%2d] %3d%3d ='",
59                 name, n,
60                 win->_line[n].firstchar,
61                 win->_line[n].lastchar);
62         ep = buf + strlen(buf);
63         for (j = 0; j <= width; j++) {
64             ep[j] = TextOf(win->_line[n].text[j]);
65             if (ep[j] == 0)
66                 ep[j] = '.';
67         }
68         ep[j] = '\'';
69         ep[j+1] = '\0';
70         _tracef(buf);
71
72         /* dump A_COLOR part, will screw up if there are more than 96 */
73         havecolors = FALSE;
74         for (j = 0; j <= width; j++)
75             if (win->_line[n].text[j] & A_COLOR)
76             {
77                 havecolors = TRUE;
78                 break;
79             }
80         if (havecolors)
81         {
82             (void) sprintf(buf, "%*s[%2d]%*s='", (int)strlen(name), "colors", n, 8, " ");
83             ep = buf + strlen(buf);
84             for (j = 0; j <= width; j++)
85                 ep[j] = ((win->_line[n].text[j] >> 8) & 0xff) + ' ';
86             ep[j] = '\'';
87             ep[j+1] = '\0';
88             _tracef(buf);
89         }
90
91         for (i = 0; i < 4; i++)
92         {
93             const char  *hex = " 123456789ABCDEF";
94             chtype      mask = (0xf << ((i + 4) * 4));
95
96             haveattrs = FALSE;
97             for (j = 0; j <= width; j++)
98                 if (win->_line[n].text[j] & mask)
99                 {
100                     haveattrs = TRUE;
101                     break;
102                 }
103             if (haveattrs)
104             {
105                 (void) sprintf(buf, "%*s%d[%2d]%*s='", (int)strlen(name)-1, "attrs", i, n, 8, " ");
106                 ep = buf + strlen(buf);
107                 for (j = 0; j <= width; j++)
108                     ep[j] = hex[(win->_line[n].text[j] & mask) >> ((i + 4) * 4)];
109                 ep[j] = '\'';
110                 ep[j+1] = '\0';
111                 _tracef(buf);
112             }
113         }
114     }
115 }