1 /****************************************************************************
2 * Copyright (c) 1998 Free Software Foundation, Inc. *
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: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
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. *
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 *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 ****************************************************************************/
37 * lib_traceatr.c - Tracing/Debugging routines (attributes)
41 #define TRACE /* turn on internal defs for this module */
44 #include <curses.priv.h>
45 #include <term.h> /* acs_chars */
47 MODULE_ID("$Id: lib_traceatr.c,v 1.25 1998/02/11 12:14:00 tom Exp $")
49 #define COLOR_OF(c) (c < 0 || c > 7 ? "default" : colors[c].name)
51 char *_traceattr2(int bufnum, attr_t newmode)
53 char *buf = _nc_trace_buf(bufnum, BUFSIZ);
55 static const struct {unsigned int val; const char *name;}
58 { A_STANDOUT, "A_STANDOUT" },
59 { A_UNDERLINE, "A_UNDERLINE" },
60 { A_REVERSE, "A_REVERSE" },
61 { A_BLINK, "A_BLINK" },
64 { A_ALTCHARSET, "A_ALTCHARSET" },
65 { A_INVIS, "A_INVIS" },
66 { A_PROTECT, "A_PROTECT" },
67 { A_CHARTEXT, "A_CHARTEXT" },
68 { A_NORMAL, "A_NORMAL" },
69 { A_COLOR, "A_COLOR" },
73 { COLOR_BLACK, "COLOR_BLACK" },
74 { COLOR_RED, "COLOR_RED" },
75 { COLOR_GREEN, "COLOR_GREEN" },
76 { COLOR_YELLOW, "COLOR_YELLOW" },
77 { COLOR_BLUE, "COLOR_BLUE" },
78 { COLOR_MAGENTA, "COLOR_MAGENTA" },
79 { COLOR_CYAN, "COLOR_CYAN" },
80 { COLOR_WHITE, "COLOR_WHITE" },
83 unsigned save_nc_tracing = _nc_tracing;
88 for (n = 0; n < SIZEOF(names); n++) {
89 if ((newmode & names[n].val) != 0) {
92 strcat(tmp, names[n].name);
95 if (names[n].val == A_COLOR)
97 short pairnum = PAIR_NUMBER(newmode);
100 if (pair_content(pairnum, &fg, &bg) == OK)
108 (void) sprintf(tmp, "{%d}", pairnum);
112 if (AttrOf(newmode) == A_NORMAL) {
115 strcat(tmp, "A_NORMAL");
118 _nc_tracing = save_nc_tracing;
119 return (strcat(buf,"}"));
122 char *_traceattr(attr_t newmode)
124 return _traceattr2(0, newmode);
127 /* Trace 'int' return-values */
128 attr_t _nc_retrace_attr_t(attr_t code)
130 T((T_RETURN("%s"), _traceattr(code)));
134 char *_tracechtype2(int bufnum, chtype ch)
136 char *buf = _nc_trace_buf(bufnum, BUFSIZ);
140 if (ch & A_ALTCHARSET)
143 static const struct {unsigned int val; const char *name;}
146 {'l', "ACS_ULCORNER"}, /* upper left corner */
147 {'m', "ACS_LLCORNER"}, /* lower left corner */
148 {'k', "ACS_URCORNER"}, /* upper right corner */
149 {'j', "ACS_LRCORNER"}, /* lower right corner */
150 {'t', "ACS_LTEE"}, /* tee pointing right */
151 {'u', "ACS_RTEE"}, /* tee pointing left */
152 {'v', "ACS_BTEE"}, /* tee pointing up */
153 {'w', "ACS_TTEE"}, /* tee pointing down */
154 {'q', "ACS_HLINE"}, /* horizontal line */
155 {'x', "ACS_VLINE"}, /* vertical line */
156 {'n', "ACS_PLUS"}, /* large plus or crossover */
157 {'o', "ACS_S1"}, /* scan line 1 */
158 {'s', "ACS_S9"}, /* scan line 9 */
159 {'`', "ACS_DIAMOND"}, /* diamond */
160 {'a', "ACS_CKBOARD"}, /* checker board (stipple) */
161 {'f', "ACS_DEGREE"}, /* degree symbol */
162 {'g', "ACS_PLMINUS"}, /* plus/minus */
163 {'~', "ACS_BULLET"}, /* bullet */
164 {',', "ACS_LARROW"}, /* arrow pointing left */
165 {'+', "ACS_RARROW"}, /* arrow pointing right */
166 {'.', "ACS_DARROW"}, /* arrow pointing down */
167 {'-', "ACS_UARROW"}, /* arrow pointing up */
168 {'h', "ACS_BOARD"}, /* board of squares */
169 {'i', "ACS_LANTERN"}, /* lantern symbol */
170 {'0', "ACS_BLOCK"}, /* solid square block */
171 {'p', "ACS_S3"}, /* scan line 3 */
172 {'r', "ACS_S7"}, /* scan line 7 */
173 {'y', "ACS_LEQUAL"}, /* less/equal */
174 {'z', "ACS_GEQUAL"}, /* greater/equal */
175 {'{', "ACS_PI"}, /* Pi */
176 {'|', "ACS_NEQUAL"}, /* not equal */
177 {'}', "ACS_STERLING"}, /* UK pound sign */
182 for (cp = acs_chars; cp[0] && cp[1]; cp += 2)
184 if (TextOf(cp[1]) == TextOf(ch))
187 /* don't exit from loop - there may be redefinitions */
194 for (sp = names; sp->val; sp++)
197 (void) strcat(buf, sp->name);
205 (void) strcat(buf, _tracechar(TextOf(ch)));
207 if (AttrOf(ch) != A_NORMAL)
208 (void) sprintf(buf + strlen(buf), " | %s", _traceattr2(bufnum+20,AttrOf(ch)));
214 char *_tracechtype(chtype ch)
216 return _tracechtype2(0, ch);