Back to index

tetex-bin  3.0
lib_tracedmp.c
Go to the documentation of this file.
00001 /****************************************************************************
00002  * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc.              *
00003  *                                                                          *
00004  * Permission is hereby granted, free of charge, to any person obtaining a  *
00005  * copy of this software and associated documentation files (the            *
00006  * "Software"), to deal in the Software without restriction, including      *
00007  * without limitation the rights to use, copy, modify, merge, publish,      *
00008  * distribute, distribute with modifications, sublicense, and/or sell       *
00009  * copies of the Software, and to permit persons to whom the Software is    *
00010  * furnished to do so, subject to the following conditions:                 *
00011  *                                                                          *
00012  * The above copyright notice and this permission notice shall be included  *
00013  * in all copies or substantial portions of the Software.                   *
00014  *                                                                          *
00015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
00016  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
00017  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
00018  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
00019  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
00020  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
00021  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
00022  *                                                                          *
00023  * Except as contained in this notice, the name(s) of the above copyright   *
00024  * holders shall not be used in advertising or otherwise to promote the     *
00025  * sale, use or other dealings in this Software without prior written       *
00026  * authorization.                                                           *
00027  ****************************************************************************/
00028 
00029 /****************************************************************************
00030  *  Author: Thomas E. Dickey 1996-2001                                      *
00031  *     and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
00032  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
00033  ****************************************************************************/
00034 
00035 /*
00036  *     lib_tracedmp.c - Tracing/Debugging routines
00037  */
00038 
00039 #include <curses.priv.h>
00040 #include <ctype.h>
00041 
00042 MODULE_ID("$Id: lib_tracedmp.c,v 1.25 2002/09/22 22:21:38 tom Exp $")
00043 
00044 #ifdef TRACE
00045 NCURSES_EXPORT(void)
00046 _tracedump(const char *name, WINDOW *win)
00047 {
00048     static char *buf = 0;
00049     static size_t used = 0;
00050 
00051     int i, j, n, width;
00052 
00053     /* compute narrowest possible display width */
00054     for (width = i = 0; i <= win->_maxy; ++i) {
00055        n = 0;
00056        for (j = 0; j <= win->_maxx; ++j)
00057            if (CharOf(win->_line[i].text[j]) != L(' ')
00058               || AttrOf(win->_line[i].text[j]) != A_NORMAL)
00059               n = j;
00060 
00061        if (n > width)
00062            width = n;
00063     }
00064     if (width < win->_maxx)
00065        ++width;
00066     if (++width + 1 > (int) used) {
00067        used = 2 * (width + 1);
00068        buf = typeRealloc(char, used, buf);
00069     }
00070 
00071     for (n = 0; n <= win->_maxy; ++n) {
00072        char *ep = buf;
00073        bool haveattrs, havecolors;
00074 
00075        /*
00076         * Dump A_CHARTEXT part.  It is more important to make the grid line up
00077         * in the trace file than to represent control- and wide-characters, so
00078         * we map those to '.' and '?' respectively.
00079         */
00080        for (j = 0; j < width; ++j) {
00081            chtype test = CharOf(win->_line[n].text[j]);
00082            ep[j] = (UChar(test) == test
00083 #if USE_WIDEC_SUPPORT
00084                    && (win->_line[n].text[j].chars[1] == 0)
00085 #endif
00086               )
00087               ? (iscntrl(UChar(test))
00088                  ? '.'
00089                  : UChar(test))
00090               : '?';
00091        }
00092        ep[j] = '\0';
00093        _tracef("%s[%2d] %3d%3d ='%s'",
00094               name, n,
00095               win->_line[n].firstchar,
00096               win->_line[n].lastchar,
00097               ep);
00098 
00099        /* dump A_COLOR part, will screw up if there are more than 96 */
00100        havecolors = FALSE;
00101        for (j = 0; j < width; ++j)
00102            if (AttrOf(win->_line[n].text[j]) & A_COLOR) {
00103               havecolors = TRUE;
00104               break;
00105            }
00106        if (havecolors) {
00107            ep = buf;
00108            for (j = 0; j < width; ++j)
00109               ep[j] = UChar(AttrOf(win->_line[n].text[j]) >>
00110                            NCURSES_ATTR_SHIFT) + ' ';
00111            ep[j] = '\0';
00112            _tracef("%*s[%2d]%*s='%s'", (int) strlen(name),
00113                   "colors", n, 8, " ", buf);
00114        }
00115 
00116        for (i = 0; i < 4; ++i) {
00117            const char *hex = " 123456789ABCDEF";
00118            attr_t mask = (0xf << ((i + 4) * 4));
00119 
00120            haveattrs = FALSE;
00121            for (j = 0; j < width; ++j)
00122               if (AttrOf(win->_line[n].text[j]) & mask) {
00123                   haveattrs = TRUE;
00124                   break;
00125               }
00126            if (haveattrs) {
00127               ep = buf;
00128               for (j = 0; j < width; ++j)
00129                   ep[j] = hex[(AttrOf(win->_line[n].text[j]) & mask) >>
00130                             ((i + 4) * 4)];
00131               ep[j] = '\0';
00132               _tracef("%*s%d[%2d]%*s='%s'", (int) strlen(name) -
00133                      1, "attrs", i, n, 8, " ", buf);
00134            }
00135        }
00136     }
00137 #if NO_LEAKS
00138     free(buf);
00139     buf = 0;
00140     used = 0;
00141 #endif
00142 }
00143 
00144 #else
00145 empty_module(_nc_lib_tracedmp)
00146 #endif /* TRACE */