lib_tracedmp.c revision 174994
1207536Smav/**************************************************************************** 2207536Smav * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * 3207536Smav * * 4207536Smav * Permission is hereby granted, free of charge, to any person obtaining a * 5207536Smav * copy of this software and associated documentation files (the * 6207536Smav * "Software"), to deal in the Software without restriction, including * 7207536Smav * without limitation the rights to use, copy, modify, merge, publish, * 8207536Smav * distribute, distribute with modifications, sublicense, and/or sell * 9207536Smav * copies of the Software, and to permit persons to whom the Software is * 10207536Smav * furnished to do so, subject to the following conditions: * 11207536Smav * * 12207536Smav * The above copyright notice and this permission notice shall be included * 13207536Smav * in all copies or substantial portions of the Software. * 14207536Smav * * 15207536Smav * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 16207536Smav * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 17207536Smav * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 18207536Smav * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 19207536Smav * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 20207536Smav * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 21207536Smav * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 22207536Smav * * 23207536Smav * Except as contained in this notice, the name(s) of the above copyright * 24207536Smav * holders shall not be used in advertising or otherwise to promote the * 25207536Smav * sale, use or other dealings in this Software without prior written * 26207536Smav * authorization. * 27207536Smav ****************************************************************************/ 28207536Smav 29207536Smav/**************************************************************************** 30207536Smav * Author: Thomas E. Dickey 1996-on * 31207536Smav * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * 32207536Smav * and: Eric S. Raymond <esr@snark.thyrsus.com> * 33207536Smav ****************************************************************************/ 34207536Smav 35207536Smav/* 36207536Smav * lib_tracedmp.c - Tracing/Debugging routines 37207536Smav */ 38207536Smav 39207536Smav#include <curses.priv.h> 40207536Smav#include <ctype.h> 41207536Smav 42207536SmavMODULE_ID("$Id: lib_tracedmp.c,v 1.29 2007/06/30 23:01:19 tom Exp $") 43207536Smav 44207536Smav#ifdef TRACE 45207536Smav 46220097Smav#define my_buffer _nc_globals.tracedmp_buf 47220097Smav#define my_length _nc_globals.tracedmp_used 48207536Smav 49207536SmavNCURSES_EXPORT(void) 50207536Smav_tracedump(const char *name, WINDOW *win) 51207536Smav{ 52207536Smav int i, j, n, width; 53207536Smav 54207536Smav /* compute narrowest possible display width */ 55207536Smav for (width = i = 0; i <= win->_maxy; ++i) { 56207536Smav n = 0; 57207536Smav for (j = 0; j <= win->_maxx; ++j) { 58207536Smav if (CharOf(win->_line[i].text[j]) != L(' ') 59207536Smav || AttrOf(win->_line[i].text[j]) != A_NORMAL 60207536Smav || GetPair(win->_line[i].text[j]) != 0) { 61207536Smav n = j; 62207536Smav } 63207536Smav } 64207536Smav 65207536Smav if (n > width) 66238873Shrs width = n; 67207536Smav } 68207536Smav if (width < win->_maxx) 69266046Sian ++width; 70266046Sian if (++width + 1 > (int) my_length) { 71207536Smav my_length = 2 * (width + 1); 72207536Smav my_buffer = typeRealloc(char, my_length, my_buffer); 73207536Smav } 74207536Smav 75207536Smav for (n = 0; n <= win->_maxy; ++n) { 76207536Smav char *ep = my_buffer; 77207536Smav bool haveattrs, havecolors; 78207536Smav 79207536Smav /* 80207536Smav * Dump A_CHARTEXT part. It is more important to make the grid line up 81266152Sian * in the trace file than to represent control- and wide-characters, so 82266152Sian * we map those to '.' and '?' respectively. 83266152Sian */ 84220097Smav for (j = 0; j < width; ++j) { 85220097Smav chtype test = CharOf(win->_line[n].text[j]); 86220097Smav ep[j] = (UChar(test) == test 87207536Smav#if USE_WIDEC_SUPPORT 88207536Smav && (win->_line[n].text[j].chars[1] == 0) 89207536Smav#endif 90207536Smav ) 91207536Smav ? (iscntrl(UChar(test)) 92207536Smav ? '.' 93207536Smav : UChar(test)) 94207536Smav : '?'; 95207536Smav } 96207536Smav ep[j] = '\0'; 97207536Smav _tracef("%s[%2d] %3ld%3ld ='%s'", 98207536Smav name, n, 99207536Smav (long) win->_line[n].firstchar, 100207536Smav (long) win->_line[n].lastchar, 101207536Smav ep); 102207536Smav 103207536Smav /* if there are multi-column characters on the line, print them now */ 104207536Smav if_WIDEC({ 105207536Smav bool multicolumn = FALSE; 106207536Smav for (j = 0; j < width; ++j) 107207536Smav if (WidecExt(win->_line[n].text[j]) != 0) { 108207536Smav multicolumn = TRUE; 109207536Smav break; 110207536Smav } 111207536Smav if (multicolumn) { 112207536Smav ep = my_buffer; 113207536Smav for (j = 0; j < width; ++j) { 114207536Smav int test = WidecExt(win->_line[n].text[j]); 115207536Smav if (test) { 116207536Smav ep[j] = test + '0'; 117207536Smav } else { 118207536Smav ep[j] = ' '; 119207536Smav } 120207536Smav } 121207536Smav ep[j] = '\0'; 122207536Smav _tracef("%*s[%2d]%*s='%s'", (int) strlen(name), 123207536Smav "widec", n, 8, " ", my_buffer); 124207536Smav } 125207536Smav }); 126207536Smav 127207536Smav /* dump A_COLOR part, will screw up if there are more than 96 */ 128207536Smav havecolors = FALSE; 129207536Smav for (j = 0; j < width; ++j) 130207536Smav if (GetPair(win->_line[n].text[j]) != 0) { 131207536Smav havecolors = TRUE; 132207536Smav break; 133207536Smav } 134207536Smav if (havecolors) { 135207536Smav ep = my_buffer; 136207536Smav for (j = 0; j < width; ++j) { 137207536Smav int pair = GetPair(win->_line[n].text[j]); 138207536Smav if (pair >= 52) 139207536Smav ep[j] = '?'; 140207536Smav else if (pair >= 36) 141207536Smav ep[j] = pair + 'A'; 142207536Smav else if (pair >= 10) 143207536Smav ep[j] = pair + 'a'; 144236952Smav else if (pair >= 1) 145236952Smav ep[j] = pair + '0'; 146207536Smav else 147208414Smav ep[j] = ' '; 148208414Smav } 149207536Smav ep[j] = '\0'; 150207536Smav _tracef("%*s[%2d]%*s='%s'", (int) strlen(name), 151207536Smav "colors", n, 8, " ", my_buffer); 152207536Smav } 153207536Smav 154207536Smav for (i = 0; i < 4; ++i) { 155207536Smav const char *hex = " 123456789ABCDEF"; 156207536Smav attr_t mask = (0xf << ((i + 4) * 4)); 157207536Smav 158207536Smav haveattrs = FALSE; 159207536Smav for (j = 0; j < width; ++j) 160207536Smav if (AttrOf(win->_line[n].text[j]) & mask) { 161207536Smav haveattrs = TRUE; 162207536Smav break; 163207536Smav } 164207536Smav if (haveattrs) { 165207536Smav ep = my_buffer; 166207536Smav for (j = 0; j < width; ++j) 167207536Smav ep[j] = hex[(AttrOf(win->_line[n].text[j]) & mask) >> 168207536Smav ((i + 4) * 4)]; 169207536Smav ep[j] = '\0'; 170207536Smav _tracef("%*s%d[%2d]%*s='%s'", (int) strlen(name) - 171207536Smav 1, "attrs", i, n, 8, " ", my_buffer); 172207536Smav } 173207536Smav } 174207536Smav } 175207536Smav#if NO_LEAKS 176207536Smav free(my_buffer); 177207536Smav my_buffer = 0; 178207536Smav my_length = 0; 179207536Smav#endif 180207536Smav} 181207536Smav 182207536Smav#else 183207536Smavempty_module(_nc_lib_tracedmp) 184207536Smav#endif /* TRACE */ 185207536Smav