lib_traceatr.c revision 98503
155682Smarkm/**************************************************************************** 255682Smarkm * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. * 355682Smarkm * * 455682Smarkm * Permission is hereby granted, free of charge, to any person obtaining a * 555682Smarkm * copy of this software and associated documentation files (the * 655682Smarkm * "Software"), to deal in the Software without restriction, including * 755682Smarkm * without limitation the rights to use, copy, modify, merge, publish, * 855682Smarkm * distribute, distribute with modifications, sublicense, and/or sell * 955682Smarkm * copies of the Software, and to permit persons to whom the Software is * 1055682Smarkm * furnished to do so, subject to the following conditions: * 1155682Smarkm * * 1255682Smarkm * The above copyright notice and this permission notice shall be included * 1355682Smarkm * in all copies or substantial portions of the Software. * 1455682Smarkm * * 1555682Smarkm * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * 1655682Smarkm * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * 1755682Smarkm * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * 1855682Smarkm * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * 1955682Smarkm * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * 2055682Smarkm * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * 2155682Smarkm * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * 2255682Smarkm * * 2355682Smarkm * Except as contained in this notice, the name(s) of the above copyright * 2455682Smarkm * holders shall not be used in advertising or otherwise to promote the * 2555682Smarkm * sale, use or other dealings in this Software without prior written * 2655682Smarkm * authorization. * 2755682Smarkm ****************************************************************************/ 2855682Smarkm 2955682Smarkm/**************************************************************************** 3055682Smarkm * Author: Thomas Dickey 1996-2001 * 3155682Smarkm * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * 3255682Smarkm * and: Eric S. Raymond <esr@snark.thyrsus.com> * 3355682Smarkm ****************************************************************************/ 3455682Smarkm 3555682Smarkm/* 3655682Smarkm * lib_traceatr.c - Tracing/Debugging routines (attributes) 3755682Smarkm */ 38178825Sdfr 3955682Smarkm#include <curses.priv.h> 4055682Smarkm#include <term.h> /* acs_chars */ 4155682Smarkm 4255682SmarkmMODULE_ID("$Id: lib_traceatr.c,v 1.42 2002/06/16 00:35:01 tom Exp $") 4355682Smarkm 4455682Smarkm#define COLOR_OF(c) (c < 0 || c > 7 ? "default" : colors[c].name) 4555682Smarkm 4655682Smarkm#ifdef TRACE 4755682Smarkm 4855682Smarkmstatic const char l_brace[] = {L_BRACE, 0}; 4972445Sassarstatic const char r_brace[] = {R_BRACE, 0}; 5055682Smarkm 5155682SmarkmNCURSES_EXPORT(char *) 5255682Smarkm_traceattr2(int bufnum, attr_t newmode) 5355682Smarkm{ 5455682Smarkm char *buf = _nc_trace_buf(bufnum, BUFSIZ); 5555682Smarkm char *tmp = buf; 5655682Smarkm static const struct { 5755682Smarkm unsigned int val; 58178825Sdfr const char *name; 5955682Smarkm } names[] = 60178825Sdfr { 6155682Smarkm /* *INDENT-OFF* */ 62178825Sdfr { A_STANDOUT, "A_STANDOUT" }, 63178825Sdfr { A_UNDERLINE, "A_UNDERLINE" }, 64178825Sdfr { A_REVERSE, "A_REVERSE" }, 6555682Smarkm { A_BLINK, "A_BLINK" }, 6655682Smarkm { A_DIM, "A_DIM" }, 6755682Smarkm { A_BOLD, "A_BOLD" }, 6855682Smarkm { A_ALTCHARSET, "A_ALTCHARSET" }, 6955682Smarkm { A_INVIS, "A_INVIS" }, 7055682Smarkm { A_PROTECT, "A_PROTECT" }, 7155682Smarkm { A_CHARTEXT, "A_CHARTEXT" }, 7255682Smarkm { A_NORMAL, "A_NORMAL" }, 7355682Smarkm { A_COLOR, "A_COLOR" }, 7455682Smarkm /* *INDENT-ON* */ 7555682Smarkm 7655682Smarkm }, 7755682Smarkm colors[] = 7855682Smarkm { 7955682Smarkm /* *INDENT-OFF* */ 8055682Smarkm { COLOR_BLACK, "COLOR_BLACK" }, 8155682Smarkm { COLOR_RED, "COLOR_RED" }, 8255682Smarkm { COLOR_GREEN, "COLOR_GREEN" }, 8355682Smarkm { COLOR_YELLOW, "COLOR_YELLOW" }, 8455682Smarkm { COLOR_BLUE, "COLOR_BLUE" }, 8555682Smarkm { COLOR_MAGENTA, "COLOR_MAGENTA" }, 8655682Smarkm { COLOR_CYAN, "COLOR_CYAN" }, 8755682Smarkm { COLOR_WHITE, "COLOR_WHITE" }, 8855682Smarkm /* *INDENT-ON* */ 8955682Smarkm 9055682Smarkm }; 9155682Smarkm size_t n; 9255682Smarkm unsigned save_nc_tracing = _nc_tracing; 9355682Smarkm _nc_tracing = 0; 9455682Smarkm 9555682Smarkm strcpy(tmp++, l_brace); 9655682Smarkm 9755682Smarkm for (n = 0; n < SIZEOF(names); n++) { 9855682Smarkm if ((newmode & names[n].val) != 0) { 9955682Smarkm if (buf[1] != '\0') 10055682Smarkm strcat(tmp, "|"); 10155682Smarkm strcat(tmp, names[n].name); 10255682Smarkm tmp += strlen(tmp); 10355682Smarkm 10455682Smarkm if (names[n].val == A_COLOR) { 10555682Smarkm short pairnum = PAIR_NUMBER(newmode); 10655682Smarkm short fg, bg; 10755682Smarkm 10855682Smarkm if (pair_content(pairnum, &fg, &bg) == OK) 10955682Smarkm (void) sprintf(tmp, 11055682Smarkm "{%d = {%s, %s}}", 11155682Smarkm pairnum, 11255682Smarkm COLOR_OF(fg), 11355682Smarkm COLOR_OF(bg) 11455682Smarkm ); 11555682Smarkm else 11655682Smarkm (void) sprintf(tmp, "{%d}", pairnum); 11755682Smarkm } 11855682Smarkm } 11955682Smarkm } 12055682Smarkm if (ChAttrOf(newmode) == A_NORMAL) { 12155682Smarkm if (buf[1] != '\0') 12255682Smarkm strcat(tmp, "|"); 12355682Smarkm strcat(tmp, "A_NORMAL"); 12455682Smarkm } 12555682Smarkm 12655682Smarkm _nc_tracing = save_nc_tracing; 12755682Smarkm return (strcat(buf, r_brace)); 12855682Smarkm} 12955682Smarkm 13055682SmarkmNCURSES_EXPORT(char *) 13155682Smarkm_traceattr(attr_t newmode) 13255682Smarkm{ 13355682Smarkm return _traceattr2(0, newmode); 13455682Smarkm} 13555682Smarkm 13655682Smarkm/* Trace 'int' return-values */ 13755682SmarkmNCURSES_EXPORT(attr_t) 13855682Smarkm_nc_retrace_attr_t(attr_t code) 13955682Smarkm{ 14055682Smarkm T((T_RETURN("%s"), _traceattr(code))); 14155682Smarkm return code; 14255682Smarkm} 14355682Smarkm 14455682Smarkmconst char * 14555682Smarkm_nc_altcharset_name(attr_t attr, chtype ch) 14655682Smarkm{ 14755682Smarkm const char *result = 0; 14855682Smarkm 14955682Smarkm if (attr & A_ALTCHARSET) { 15055682Smarkm char *cp; 15155682Smarkm char *found = 0; 15255682Smarkm static const struct { 15355682Smarkm unsigned int val; 15455682Smarkm const char *name; 15555682Smarkm } names[] = 15655682Smarkm { 15755682Smarkm /* *INDENT-OFF* */ 15855682Smarkm { 'l', "ACS_ULCORNER" }, /* upper left corner */ 15955682Smarkm { 'm', "ACS_LLCORNER" }, /* lower left corner */ 16055682Smarkm { 'k', "ACS_URCORNER" }, /* upper right corner */ 16155682Smarkm { 'j', "ACS_LRCORNER" }, /* lower right corner */ 16255682Smarkm { 't', "ACS_LTEE" }, /* tee pointing right */ 16355682Smarkm { 'u', "ACS_RTEE" }, /* tee pointing left */ 16455682Smarkm { 'v', "ACS_BTEE" }, /* tee pointing up */ 16555682Smarkm { 'w', "ACS_TTEE" }, /* tee pointing down */ 16655682Smarkm { 'q', "ACS_HLINE" }, /* horizontal line */ 16755682Smarkm { 'x', "ACS_VLINE" }, /* vertical line */ 168 { 'n', "ACS_PLUS" }, /* large plus or crossover */ 169 { 'o', "ACS_S1" }, /* scan line 1 */ 170 { 's', "ACS_S9" }, /* scan line 9 */ 171 { '`', "ACS_DIAMOND" }, /* diamond */ 172 { 'a', "ACS_CKBOARD" }, /* checker board (stipple) */ 173 { 'f', "ACS_DEGREE" }, /* degree symbol */ 174 { 'g', "ACS_PLMINUS" }, /* plus/minus */ 175 { '~', "ACS_BULLET" }, /* bullet */ 176 { ',', "ACS_LARROW" }, /* arrow pointing left */ 177 { '+', "ACS_RARROW" }, /* arrow pointing right */ 178 { '.', "ACS_DARROW" }, /* arrow pointing down */ 179 { '-', "ACS_UARROW" }, /* arrow pointing up */ 180 { 'h', "ACS_BOARD" }, /* board of squares */ 181 { 'i', "ACS_LANTERN" }, /* lantern symbol */ 182 { '0', "ACS_BLOCK" }, /* solid square block */ 183 { 'p', "ACS_S3" }, /* scan line 3 */ 184 { 'r', "ACS_S7" }, /* scan line 7 */ 185 { 'y', "ACS_LEQUAL" }, /* less/equal */ 186 { 'z', "ACS_GEQUAL" }, /* greater/equal */ 187 { '{', "ACS_PI" }, /* Pi */ 188 { '|', "ACS_NEQUAL" }, /* not equal */ 189 { '}', "ACS_STERLING" }, /* UK pound sign */ 190 { '\0', (char *) 0 } 191 /* *INDENT-OFF* */ 192 }, 193 *sp; 194 195 for (cp = acs_chars; cp[0] && cp[1]; cp += 2) { 196 if (ChCharOf(cp[1]) == ChCharOf(ch)) { 197 found = cp; 198 /* don't exit from loop - there may be redefinitions */ 199 } 200 } 201 202 if (found != 0) { 203 ch = ChCharOf(*found); 204 for (sp = names; sp->val; sp++) 205 if (sp->val == ch) { 206 result = sp->name; 207 break; 208 } 209 } 210 } 211 return result; 212} 213 214NCURSES_EXPORT(char *) 215_tracechtype2(int bufnum, chtype ch) 216{ 217 char *buf = _nc_trace_buf(bufnum, BUFSIZ); 218 const char *found; 219 220 strcpy(buf, l_brace); 221 if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) { 222 (void) strcat(buf, found); 223 } else 224 (void) strcat(buf, _tracechar(ChCharOf(ch))); 225 226 if (ChAttrOf(ch) != A_NORMAL) 227 (void) sprintf(buf + strlen(buf), " | %s", 228 _traceattr2(bufnum + 20, ChAttrOf(ch))); 229 230 return (strcat(buf, r_brace)); 231} 232 233NCURSES_EXPORT(char *) 234_tracechtype (chtype ch) 235{ 236 return _tracechtype2(0, ch); 237} 238 239/* Trace 'chtype' return-values */ 240NCURSES_EXPORT(attr_t) 241_nc_retrace_chtype (attr_t code) 242{ 243 T((T_RETURN("%s"), _tracechtype(code))); 244 return code; 245} 246 247#if USE_WIDEC_SUPPORT 248NCURSES_EXPORT(char *) 249_tracecchar_t2 (int bufnum, const cchar_t *ch) 250{ 251 char *buf = _nc_trace_buf(bufnum, BUFSIZ); 252 attr_t attr; 253 const char *found; 254 255 strcpy(buf, l_brace); 256 if (ch != 0) { 257 attr = AttrOfD(ch); 258 if ((found = _nc_altcharset_name(attr, CharOfD(ch))) != 0) { 259 (void) strcat(buf, found); 260 attr &= ~A_ALTCHARSET; 261 } else if (!isnac(CHDEREF(ch))) { 262 PUTC_DATA; 263 int n; 264 265 memset (&PUT_st, '\0', sizeof (PUT_st)); 266 PUTC_i = 0; 267 (void) strcat(buf, "{ "); 268 do { 269 PUTC_ch = PUTC_i < CCHARW_MAX ? ch->chars[PUTC_i] : L'\0'; 270 PUTC_n = wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st); 271 if (PUTC_ch == L'\0') 272 --PUTC_n; 273 if (PUTC_n <= 0) 274 break; 275 for (n = 0; n < PUTC_n; n++) { 276 if (n) 277 (void) strcat(buf, ", "); 278 (void) strcat(buf, _tracechar(UChar(PUTC_buf[n]))); 279 } 280 ++PUTC_i; 281 } while (PUTC_ch != L'\0'); 282 (void) strcat(buf, " }"); 283 } 284 if (attr != A_NORMAL) 285 (void) sprintf(buf + strlen(buf), " | %s", 286 _traceattr2(bufnum + 20, attr)); 287 } 288 289 return (strcat(buf, r_brace)); 290} 291 292NCURSES_EXPORT(char *) 293_tracecchar_t (const cchar_t *ch) 294{ 295 return _tracecchar_t2(0, ch); 296} 297#endif 298 299#else 300empty_module(_nc_lib_traceatr) 301#endif /* TRACE */ 302