lib_tracedmp.c revision 97049
1/**************************************************************************** 2 * Copyright (c) 1998,2000,2001 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: Thomas E. Dickey 1996-2001 * 31 * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * 32 * and: Eric S. Raymond <esr@snark.thyrsus.com> * 33 ****************************************************************************/ 34 35/* 36 * lib_tracedmp.c - Tracing/Debugging routines 37 */ 38 39#include <curses.priv.h> 40#include <ctype.h> 41 42MODULE_ID("$Id: lib_tracedmp.c,v 1.22 2001/11/03 15:45:35 tom Exp $") 43 44#ifdef TRACE 45NCURSES_EXPORT(void) 46_tracedump(const char *name, WINDOW *win) 47{ 48 static char *buf = 0; 49 static size_t used = 0; 50 51 int i, j, n, width; 52 53 /* compute narrowest possible display width */ 54 for (width = i = 0; i <= win->_maxy; ++i) { 55 n = 0; 56 for (j = 0; j <= win->_maxx; ++j) 57 if (CharOf(win->_line[i].text[j]) != L(' ')) 58 n = j; 59 60 if (n > width) 61 width = n; 62 } 63 if (width < win->_maxx) 64 ++width; 65 if (++width + 1 > (int) used) { 66 used = 2 * (width + 1); 67 buf = _nc_doalloc(buf, used); 68 } 69 70 for (n = 0; n <= win->_maxy; ++n) { 71 char *ep = buf; 72 bool haveattrs, havecolors; 73 74 /* 75 * Dump A_CHARTEXT part. It is more important to make the grid line up 76 * in the trace file than to represent control- and wide-characters, so 77 * we map those to '.' and '?' respectively. 78 */ 79 for (j = 0; j < width; ++j) { 80 chtype test = CharOf(win->_line[n].text[j]); 81 ep[j] = (UChar(test) == test 82#if USE_WIDEC_SUPPORT 83 && (win->_line[n].text[j].chars[1] == 0) 84#endif 85 ) 86 ? (iscntrl(UChar(test)) 87 ? '.' 88 : UChar(test)) 89 : '?'; 90 } 91 ep[j] = '\0'; 92 _tracef("%s[%2d] %3d%3d ='%s'", 93 name, n, 94 win->_line[n].firstchar, 95 win->_line[n].lastchar, 96 ep); 97 98 /* dump A_COLOR part, will screw up if there are more than 96 */ 99 havecolors = FALSE; 100 for (j = 0; j < width; ++j) 101 if (AttrOf(win->_line[n].text[j]) & A_COLOR) { 102 havecolors = TRUE; 103 break; 104 } 105 if (havecolors) { 106 ep = buf; 107 for (j = 0; j < width; ++j) 108 ep[j] = UChar(CharOf(win->_line[n].text[j]) >> 109 NCURSES_ATTR_SHIFT) + ' '; 110 ep[j] = '\0'; 111 _tracef("%*s[%2d]%*s='%s'", (int) strlen(name), 112 "colors", n, 8, " ", buf); 113 } 114 115 for (i = 0; i < 4; ++i) { 116 const char *hex = " 123456789ABCDEF"; 117 attr_t mask = (0xf << ((i + 4) * 4)); 118 119 haveattrs = FALSE; 120 for (j = 0; j < width; ++j) 121 if (AttrOf(win->_line[n].text[j]) & mask) { 122 haveattrs = TRUE; 123 break; 124 } 125 if (haveattrs) { 126 ep = buf; 127 for (j = 0; j < width; ++j) 128 ep[j] = hex[(AttrOf(win->_line[n].text[j]) & mask) >> 129 ((i + 4) * 4)]; 130 ep[j] = '\0'; 131 _tracef("%*s%d[%2d]%*s='%s'", (int) strlen(name) - 132 1, "attrs", i, n, 8, " ", buf); 133 } 134 } 135 } 136#if NO_LEAKS 137 free(buf); 138 used = 0; 139#endif 140} 141 142#else 143empty_module(_nc_lib_tracedmp) 144#endif /* TRACE */ 145