1 /****************************************************************************
2 * Copyright (c) 1998-2003,2004 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: Thomas Dickey 1996-2003 *
31 * and: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
32 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
33 ****************************************************************************/
36 * lib_traceatr.c - Tracing/Debugging routines (attributes)
39 #include <curses.priv.h>
40 #include <term.h> /* acs_chars */
42 MODULE_ID("$Id: lib_traceatr.c,v 1.48 2004/01/25 22:31:38 tom Exp $")
44 #define COLOR_OF(c) (c < 0 || c > 7 ? "default" : colors[c].name)
48 static const char l_brace[] = {L_BRACE, 0};
49 static const char r_brace[] = {R_BRACE, 0};
51 NCURSES_EXPORT(char *)
52 _traceattr2(int bufnum, attr_t newmode)
54 char *buf = _nc_trace_buf(bufnum, BUFSIZ);
62 { A_STANDOUT, "A_STANDOUT" },
63 { A_UNDERLINE, "A_UNDERLINE" },
64 { A_REVERSE, "A_REVERSE" },
65 { A_BLINK, "A_BLINK" },
68 { A_ALTCHARSET, "A_ALTCHARSET" },
69 { A_INVIS, "A_INVIS" },
70 { A_PROTECT, "A_PROTECT" },
71 { A_CHARTEXT, "A_CHARTEXT" },
72 { A_NORMAL, "A_NORMAL" },
73 { A_COLOR, "A_COLOR" },
80 { COLOR_BLACK, "COLOR_BLACK" },
81 { COLOR_RED, "COLOR_RED" },
82 { COLOR_GREEN, "COLOR_GREEN" },
83 { COLOR_YELLOW, "COLOR_YELLOW" },
84 { COLOR_BLUE, "COLOR_BLUE" },
85 { COLOR_MAGENTA, "COLOR_MAGENTA" },
86 { COLOR_CYAN, "COLOR_CYAN" },
87 { COLOR_WHITE, "COLOR_WHITE" },
92 unsigned save_nc_tracing = _nc_tracing;
97 for (n = 0; n < SIZEOF(names); n++) {
98 if ((newmode & names[n].val) != 0) {
100 buf = _nc_trace_bufcat(bufnum, "|");
101 buf = _nc_trace_bufcat(bufnum, names[n].name);
103 if (names[n].val == A_COLOR) {
104 short pairnum = PAIR_NUMBER(newmode);
107 if (pair_content(pairnum, &fg, &bg) == OK) {
114 (void) sprintf(temp, "{%d}", pairnum);
116 buf = _nc_trace_bufcat(bufnum, temp);
120 if (ChAttrOf(newmode) == A_NORMAL) {
122 (void) _nc_trace_bufcat(bufnum, "|");
123 (void) _nc_trace_bufcat(bufnum, "A_NORMAL");
126 _nc_tracing = save_nc_tracing;
127 return (_nc_trace_bufcat(bufnum, r_brace));
130 NCURSES_EXPORT(char *)
131 _traceattr(attr_t newmode)
133 return _traceattr2(0, newmode);
136 /* Trace 'int' return-values */
137 NCURSES_EXPORT(attr_t)
138 _nc_retrace_attr_t(attr_t code)
140 T((T_RETURN("%s"), _traceattr(code)));
145 _nc_altcharset_name(attr_t attr, chtype ch)
147 const char *result = 0;
149 if ((attr & A_ALTCHARSET) && (acs_chars != 0)) {
152 static const struct {
158 { 'l', "ACS_ULCORNER" }, /* upper left corner */
159 { 'm', "ACS_LLCORNER" }, /* lower left corner */
160 { 'k', "ACS_URCORNER" }, /* upper right corner */
161 { 'j', "ACS_LRCORNER" }, /* lower right corner */
162 { 't', "ACS_LTEE" }, /* tee pointing right */
163 { 'u', "ACS_RTEE" }, /* tee pointing left */
164 { 'v', "ACS_BTEE" }, /* tee pointing up */
165 { 'w', "ACS_TTEE" }, /* tee pointing down */
166 { 'q', "ACS_HLINE" }, /* horizontal line */
167 { '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 */
195 for (cp = acs_chars; cp[0] && cp[1]; cp += 2) {
196 if (ChCharOf(cp[1]) == ChCharOf(ch)) {
198 /* don't exit from loop - there may be redefinitions */
203 ch = ChCharOf(*found);
204 for (sp = names; sp->val; sp++)
214 NCURSES_EXPORT(char *)
215 _tracechtype2(int bufnum, chtype ch)
219 strcpy(_nc_trace_buf(bufnum, BUFSIZ), l_brace);
220 if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) {
221 (void) _nc_trace_bufcat(bufnum, found);
223 (void) _nc_trace_bufcat(bufnum, _tracechar(ChCharOf(ch)));
225 if (ChAttrOf(ch) != A_NORMAL) {
226 (void) _nc_trace_bufcat(bufnum, " | ");
227 (void) _nc_trace_bufcat(bufnum,
228 _traceattr2(bufnum + 20, ChAttrOf(ch)));
231 return (_nc_trace_bufcat(bufnum, r_brace));
234 NCURSES_EXPORT(char *)
235 _tracechtype (chtype ch)
237 return _tracechtype2(0, ch);
240 /* Trace 'chtype' return-values */
241 NCURSES_EXPORT(chtype)
242 _nc_retrace_chtype (chtype code)
244 T((T_RETURN("%s"), _tracechtype(code)));
248 #if USE_WIDEC_SUPPORT
249 NCURSES_EXPORT(char *)
250 _tracecchar_t2 (int bufnum, const cchar_t *ch)
252 char *buf = _nc_trace_buf(bufnum, BUFSIZ);
256 strcpy(buf, l_brace);
259 if ((found = _nc_altcharset_name(attr, CharOfD(ch))) != 0) {
260 (void) _nc_trace_bufcat(bufnum, found);
261 attr &= ~A_ALTCHARSET;
262 } else if (isnac(CHDEREF(ch))) {
263 (void) _nc_trace_bufcat(bufnum, "{NAC}");
269 (void) _nc_trace_bufcat(bufnum, "{ ");
271 PUTC_ch = PUTC_i < CCHARW_MAX ? ch->chars[PUTC_i] : L'\0';
272 PUTC_n = wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st);
273 if (PUTC_ch == L'\0')
276 if (PUTC_ch != L'\0') {
277 /* it could not be a multibyte sequence */
278 (void) _nc_trace_bufcat(bufnum, _tracechar(UChar(ch->chars[PUTC_i])));
282 for (n = 0; n < PUTC_n; n++) {
284 (void) _nc_trace_bufcat(bufnum, ", ");
285 (void) _nc_trace_bufcat(bufnum, _tracechar(UChar(PUTC_buf[n])));
288 } while (PUTC_ch != L'\0');
289 (void) _nc_trace_bufcat(bufnum, " }");
291 if (attr != A_NORMAL) {
292 (void) _nc_trace_bufcat(bufnum, " | ");
293 (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr));
297 return (_nc_trace_bufcat(bufnum, r_brace));
300 NCURSES_EXPORT(char *)
301 _tracecchar_t (const cchar_t *ch)
303 return _tracecchar_t2(0, ch);
308 empty_module(_nc_lib_traceatr)