1 /****************************************************************************
2 * Copyright (c) 1998-2006,2007 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-on *
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.59 2007/06/09 17:22:10 tom Exp $")
44 #define COLOR_OF(c) ((c < 0) ? "default" : (c > 7 ? color_of(c) : colors[c].name))
48 static const char l_brace[] = StringOf(L_BRACE);
49 static const char r_brace[] = StringOf(R_BRACE);
53 #define my_buffer _nc_globals.traceatr_color_buf
54 #define my_select _nc_globals.traceatr_color_sel
55 #define my_cached _nc_globals.traceatr_color_last
62 my_select = !my_select;
63 if (c == COLOR_DEFAULT)
64 strcpy(my_buffer[my_select], "default");
66 sprintf(my_buffer[my_select], "color%d", c);
68 return my_buffer[my_select];
73 #endif /* !USE_TERMLIB */
75 NCURSES_EXPORT(char *)
76 _traceattr2(int bufnum, chtype newmode)
78 char *buf = _nc_trace_buf(bufnum, BUFSIZ);
86 { A_STANDOUT, "A_STANDOUT" },
87 { A_UNDERLINE, "A_UNDERLINE" },
88 { A_REVERSE, "A_REVERSE" },
89 { A_BLINK, "A_BLINK" },
92 { A_ALTCHARSET, "A_ALTCHARSET" },
93 { A_INVIS, "A_INVIS" },
94 { A_PROTECT, "A_PROTECT" },
95 { A_CHARTEXT, "A_CHARTEXT" },
96 { A_NORMAL, "A_NORMAL" },
97 { A_COLOR, "A_COLOR" },
106 { COLOR_BLACK, "COLOR_BLACK" },
107 { COLOR_RED, "COLOR_RED" },
108 { COLOR_GREEN, "COLOR_GREEN" },
109 { COLOR_YELLOW, "COLOR_YELLOW" },
110 { COLOR_BLUE, "COLOR_BLUE" },
111 { COLOR_MAGENTA, "COLOR_MAGENTA" },
112 { COLOR_CYAN, "COLOR_CYAN" },
113 { COLOR_WHITE, "COLOR_WHITE" },
117 #endif /* !USE_TERMLIB */
120 unsigned save_nc_tracing = _nc_tracing;
123 strcpy(buf, l_brace);
125 for (n = 0; n < SIZEOF(names); n++) {
126 if ((newmode & names[n].val) != 0) {
128 buf = _nc_trace_bufcat(bufnum, "|");
129 buf = _nc_trace_bufcat(bufnum, names[n].name);
131 if (names[n].val == A_COLOR) {
132 short pairnum = PAIR_NUMBER(newmode);
134 /* pair_content lives in libncurses */
135 (void) sprintf(temp, "{%d}", pairnum);
139 if (pair_content(pairnum, &fg, &bg) == OK) {
146 (void) sprintf(temp, "{%d}", pairnum);
149 buf = _nc_trace_bufcat(bufnum, temp);
153 if (ChAttrOf(newmode) == A_NORMAL) {
155 (void) _nc_trace_bufcat(bufnum, "|");
156 (void) _nc_trace_bufcat(bufnum, "A_NORMAL");
159 _nc_tracing = save_nc_tracing;
160 return (_nc_trace_bufcat(bufnum, r_brace));
163 NCURSES_EXPORT(char *)
164 _traceattr(attr_t newmode)
166 return _traceattr2(0, newmode);
169 /* Trace 'int' return-values */
170 NCURSES_EXPORT(attr_t)
171 _nc_retrace_attr_t(attr_t code)
173 T((T_RETURN("%s"), _traceattr(code)));
178 _nc_altcharset_name(attr_t attr, chtype ch)
185 const char *result = 0;
187 if ((attr & A_ALTCHARSET) && (acs_chars != 0)) {
191 static const ALT_NAMES names[] =
193 { 'l', "ACS_ULCORNER" }, /* upper left corner */
194 { 'm', "ACS_LLCORNER" }, /* lower left corner */
195 { 'k', "ACS_URCORNER" }, /* upper right corner */
196 { 'j', "ACS_LRCORNER" }, /* lower right corner */
197 { 't', "ACS_LTEE" }, /* tee pointing right */
198 { 'u', "ACS_RTEE" }, /* tee pointing left */
199 { 'v', "ACS_BTEE" }, /* tee pointing up */
200 { 'w', "ACS_TTEE" }, /* tee pointing down */
201 { 'q', "ACS_HLINE" }, /* horizontal line */
202 { 'x', "ACS_VLINE" }, /* vertical line */
203 { 'n', "ACS_PLUS" }, /* large plus or crossover */
204 { 'o', "ACS_S1" }, /* scan line 1 */
205 { 's', "ACS_S9" }, /* scan line 9 */
206 { '`', "ACS_DIAMOND" }, /* diamond */
207 { 'a', "ACS_CKBOARD" }, /* checker board (stipple) */
208 { 'f', "ACS_DEGREE" }, /* degree symbol */
209 { 'g', "ACS_PLMINUS" }, /* plus/minus */
210 { '~', "ACS_BULLET" }, /* bullet */
211 { ',', "ACS_LARROW" }, /* arrow pointing left */
212 { '+', "ACS_RARROW" }, /* arrow pointing right */
213 { '.', "ACS_DARROW" }, /* arrow pointing down */
214 { '-', "ACS_UARROW" }, /* arrow pointing up */
215 { 'h', "ACS_BOARD" }, /* board of squares */
216 { 'i', "ACS_LANTERN" }, /* lantern symbol */
217 { '0', "ACS_BLOCK" }, /* solid square block */
218 { 'p', "ACS_S3" }, /* scan line 3 */
219 { 'r', "ACS_S7" }, /* scan line 7 */
220 { 'y', "ACS_LEQUAL" }, /* less/equal */
221 { 'z', "ACS_GEQUAL" }, /* greater/equal */
222 { '{', "ACS_PI" }, /* Pi */
223 { '|', "ACS_NEQUAL" }, /* not equal */
224 { '}', "ACS_STERLING" }, /* UK pound sign */
230 for (cp = acs_chars; cp[0] && cp[1]; cp += 2) {
231 if (ChCharOf(cp[1]) == ChCharOf(ch)) {
233 /* don't exit from loop - there may be redefinitions */
238 ch = ChCharOf(*found);
239 for (sp = names; sp->val; sp++)
249 NCURSES_EXPORT(char *)
250 _tracechtype2(int bufnum, chtype ch)
254 strcpy(_nc_trace_buf(bufnum, BUFSIZ), l_brace);
255 if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) {
256 (void) _nc_trace_bufcat(bufnum, found);
258 (void) _nc_trace_bufcat(bufnum, _tracechar((int)ChCharOf(ch)));
260 if (ChAttrOf(ch) != A_NORMAL) {
261 (void) _nc_trace_bufcat(bufnum, " | ");
262 (void) _nc_trace_bufcat(bufnum,
263 _traceattr2(bufnum + 20, ChAttrOf(ch)));
266 return (_nc_trace_bufcat(bufnum, r_brace));
269 NCURSES_EXPORT(char *)
270 _tracechtype (chtype ch)
272 return _tracechtype2(0, ch);
275 /* Trace 'chtype' return-values */
276 NCURSES_EXPORT(chtype)
277 _nc_retrace_chtype (chtype code)
279 T((T_RETURN("%s"), _tracechtype(code)));
283 #if USE_WIDEC_SUPPORT
284 NCURSES_EXPORT(char *)
285 _tracecchar_t2 (int bufnum, const cchar_t *ch)
287 char *buf = _nc_trace_buf(bufnum, BUFSIZ);
291 strcpy(buf, l_brace);
294 if ((found = _nc_altcharset_name(attr, (chtype) CharOfD(ch))) != 0) {
295 (void) _nc_trace_bufcat(bufnum, found);
296 attr &= ~A_ALTCHARSET;
297 } else if (isWidecExt(CHDEREF(ch))) {
298 (void) _nc_trace_bufcat(bufnum, "{NAC}");
305 (void) _nc_trace_bufcat(bufnum, "{ ");
306 for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) {
307 PUTC_ch = ch->chars[PUTC_i];
308 if (PUTC_ch == L'\0')
310 PUTC_n = wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st);
312 if (PUTC_ch != L'\0') {
313 /* it could not be a multibyte sequence */
314 (void) _nc_trace_bufcat(bufnum, _tracechar(UChar(ch->chars[PUTC_i])));
318 for (n = 0; n < PUTC_n; n++) {
320 (void) _nc_trace_bufcat(bufnum, ", ");
321 (void) _nc_trace_bufcat(bufnum, _tracechar(UChar(PUTC_buf[n])));
324 (void) _nc_trace_bufcat(bufnum, " }");
326 if (attr != A_NORMAL) {
327 (void) _nc_trace_bufcat(bufnum, " | ");
328 (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr));
332 return (_nc_trace_bufcat(bufnum, r_brace));
335 NCURSES_EXPORT(char *)
336 _tracecchar_t (const cchar_t *ch)
338 return _tracecchar_t2(0, ch);
343 empty_module(_nc_lib_traceatr)