1 /****************************************************************************
2 * Copyright (c) 1998-2010,2011 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 * and: Juergen Pfeifer *
34 ****************************************************************************/
37 * lib_traceatr.c - Tracing/Debugging routines (attributes)
40 #include <curses.priv.h>
43 #define CUR SP_TERMTYPE
46 MODULE_ID("$Id: lib_traceatr.c,v 1.74 2011/01/22 19:48:01 tom Exp $")
48 #define COLOR_OF(c) ((c < 0) ? "default" : (c > 7 ? color_of(c) : colors[c].name))
52 static const char l_brace
[] = StringOf(L_BRACE
);
53 static const char r_brace
[] = StringOf(R_BRACE
);
57 #define my_buffer _nc_globals.traceatr_color_buf
58 #define my_select _nc_globals.traceatr_color_sel
59 #define my_cached _nc_globals.traceatr_color_last
66 my_select
= !my_select
;
67 if (c
== COLOR_DEFAULT
)
68 strcpy(my_buffer
[my_select
], "default");
70 sprintf(my_buffer
[my_select
], "color%d", c
);
72 return my_buffer
[my_select
];
77 #endif /* !USE_TERMLIB */
79 NCURSES_EXPORT(char *)
80 _traceattr2(int bufnum
, chtype newmode
)
88 { A_STANDOUT
, "A_STANDOUT" },
89 { A_UNDERLINE
, "A_UNDERLINE" },
90 { A_REVERSE
, "A_REVERSE" },
91 { A_BLINK
, "A_BLINK" },
94 { A_ALTCHARSET
, "A_ALTCHARSET" },
95 { A_INVIS
, "A_INVIS" },
96 { A_PROTECT
, "A_PROTECT" },
97 { A_CHARTEXT
, "A_CHARTEXT" },
98 { A_NORMAL
, "A_NORMAL" },
99 { A_COLOR
, "A_COLOR" },
108 { COLOR_BLACK
, "COLOR_BLACK" },
109 { COLOR_RED
, "COLOR_RED" },
110 { COLOR_GREEN
, "COLOR_GREEN" },
111 { COLOR_YELLOW
, "COLOR_YELLOW" },
112 { COLOR_BLUE
, "COLOR_BLUE" },
113 { COLOR_MAGENTA
, "COLOR_MAGENTA" },
114 { COLOR_CYAN
, "COLOR_CYAN" },
115 { COLOR_WHITE
, "COLOR_WHITE" },
119 #endif /* !USE_TERMLIB */
123 char *result
= _nc_trace_buf(bufnum
, BUFSIZ
);
126 unsigned save_nc_tracing
= _nc_tracing
;
130 strcpy(result
, l_brace
);
132 for (n
= 0; n
< SIZEOF(names
); n
++) {
133 if ((newmode
& names
[n
].val
) != 0) {
134 if (result
[1] != '\0')
135 (void) _nc_trace_bufcat(bufnum
, "|");
136 result
= _nc_trace_bufcat(bufnum
, names
[n
].name
);
138 if (names
[n
].val
== A_COLOR
) {
139 short pairnum
= (short) PairNumber(newmode
);
141 /* pair_content lives in libncurses */
142 (void) sprintf(temp
, "{%d}", pairnum
);
146 if (pair_content(pairnum
, &fg
, &bg
) == OK
) {
153 (void) sprintf(temp
, "{%d}", pairnum
);
156 result
= _nc_trace_bufcat(bufnum
, temp
);
160 if (ChAttrOf(newmode
) == A_NORMAL
) {
161 if (result
!= 0 && result
[1] != '\0')
162 (void) _nc_trace_bufcat(bufnum
, "|");
163 (void) _nc_trace_bufcat(bufnum
, "A_NORMAL");
166 _nc_tracing
= save_nc_tracing
;
167 result
= _nc_trace_bufcat(bufnum
, r_brace
);
172 NCURSES_EXPORT(char *)
173 _traceattr(attr_t newmode
)
175 return _traceattr2(0, newmode
);
178 /* Trace 'int' return-values */
180 _nc_retrace_int_attr_t(attr_t code
)
182 T((T_RETURN("%s"), _traceattr(code
)));
186 /* Trace 'attr_t' return-values */
187 NCURSES_EXPORT(attr_t
)
188 _nc_retrace_attr_t(attr_t code
)
190 T((T_RETURN("%s"), _traceattr(code
)));
195 _nc_altcharset_name(attr_t attr
, chtype ch
)
202 SCREEN
*sp
= CURRENT_SCREEN
;
204 static const ALT_NAMES names
[] =
206 {'l', "ACS_ULCORNER"}, /* upper left corner */
207 {'m', "ACS_LLCORNER"}, /* lower left corner */
208 {'k', "ACS_URCORNER"}, /* upper right corner */
209 {'j', "ACS_LRCORNER"}, /* lower right corner */
210 {'t', "ACS_LTEE"}, /* tee pointing right */
211 {'u', "ACS_RTEE"}, /* tee pointing left */
212 {'v', "ACS_BTEE"}, /* tee pointing up */
213 {'w', "ACS_TTEE"}, /* tee pointing down */
214 {'q', "ACS_HLINE"}, /* horizontal line */
215 {'x', "ACS_VLINE"}, /* vertical line */
216 {'n', "ACS_PLUS"}, /* large plus or crossover */
217 {'o', "ACS_S1"}, /* scan line 1 */
218 {'s', "ACS_S9"}, /* scan line 9 */
219 {'`', "ACS_DIAMOND"}, /* diamond */
220 {'a', "ACS_CKBOARD"}, /* checker board (stipple) */
221 {'f', "ACS_DEGREE"}, /* degree symbol */
222 {'g', "ACS_PLMINUS"}, /* plus/minus */
223 {'~', "ACS_BULLET"}, /* bullet */
224 {',', "ACS_LARROW"}, /* arrow pointing left */
225 {'+', "ACS_RARROW"}, /* arrow pointing right */
226 {'.', "ACS_DARROW"}, /* arrow pointing down */
227 {'-', "ACS_UARROW"}, /* arrow pointing up */
228 {'h', "ACS_BOARD"}, /* board of squares */
229 {'i', "ACS_LANTERN"}, /* lantern symbol */
230 {'0', "ACS_BLOCK"}, /* solid square block */
231 {'p', "ACS_S3"}, /* scan line 3 */
232 {'r', "ACS_S7"}, /* scan line 7 */
233 {'y', "ACS_LEQUAL"}, /* less/equal */
234 {'z', "ACS_GEQUAL"}, /* greater/equal */
235 {'{', "ACS_PI"}, /* Pi */
236 {'|', "ACS_NEQUAL"}, /* not equal */
237 {'}', "ACS_STERLING"}, /* UK pound sign */
241 const char *result
= 0;
246 if ((attr
& A_ALTCHARSET
) && (acs_chars
!= 0)) {
249 const ALT_NAMES
*strp
;
251 for (cp
= acs_chars
; cp
[0] && cp
[1]; cp
+= 2) {
252 if (ChCharOf(UChar(cp
[1])) == ChCharOf(ch
)) {
254 /* don't exit from loop - there may be redefinitions */
259 ch
= ChCharOf(UChar(*found
));
260 for (strp
= names
; strp
->val
; strp
++)
261 if (strp
->val
== ch
) {
270 NCURSES_EXPORT(char *)
271 _tracechtype2(int bufnum
, chtype ch
)
274 char *result
= _nc_trace_buf(bufnum
, BUFSIZ
);
277 strcpy(result
, l_brace
);
278 if ((found
= _nc_altcharset_name(ChAttrOf(ch
), ch
)) != 0) {
279 (void) _nc_trace_bufcat(bufnum
, found
);
281 (void) _nc_trace_bufcat(bufnum
,
282 _nc_tracechar(CURRENT_SCREEN
,
283 (int) ChCharOf(ch
)));
285 if (ChAttrOf(ch
) != A_NORMAL
) {
286 (void) _nc_trace_bufcat(bufnum
, " | ");
287 (void) _nc_trace_bufcat(bufnum
,
288 _traceattr2(bufnum
+ 20, ChAttrOf(ch
)));
291 result
= _nc_trace_bufcat(bufnum
, r_brace
);
296 NCURSES_EXPORT(char *)
297 _tracechtype(chtype ch
)
299 return _tracechtype2(0, ch
);
302 /* Trace 'chtype' return-values */
303 NCURSES_EXPORT(chtype
)
304 _nc_retrace_chtype(chtype code
)
306 T((T_RETURN("%s"), _tracechtype(code
)));
310 #if USE_WIDEC_SUPPORT
311 NCURSES_EXPORT(char *)
312 _tracecchar_t2(int bufnum
, const cchar_t
*ch
)
314 char *result
= _nc_trace_buf(bufnum
, BUFSIZ
);
319 strcpy(result
, l_brace
);
322 if ((found
= _nc_altcharset_name(attr
, (chtype
) CharOfD(ch
))) != 0) {
323 (void) _nc_trace_bufcat(bufnum
, found
);
324 attr
&= ~A_ALTCHARSET
;
325 } else if (isWidecExt(CHDEREF(ch
))) {
326 (void) _nc_trace_bufcat(bufnum
, "{NAC}");
333 (void) _nc_trace_bufcat(bufnum
, "{ ");
334 for (PUTC_i
= 0; PUTC_i
< CCHARW_MAX
; ++PUTC_i
) {
335 PUTC_ch
= ch
->chars
[PUTC_i
];
336 if (PUTC_ch
== L
'\0') {
338 (void) _nc_trace_bufcat(bufnum
, "\\000");
341 PUTC_n
= (int) wcrtomb(PUTC_buf
, ch
->chars
[PUTC_i
], &PUT_st
);
343 if (PUTC_ch
!= L
'\0') {
344 /* it could not be a multibyte sequence */
345 (void) _nc_trace_bufcat(bufnum
,
346 _nc_tracechar(CURRENT_SCREEN
,
347 UChar(ch
->chars
[PUTC_i
])));
351 for (n
= 0; n
< PUTC_n
; n
++) {
353 (void) _nc_trace_bufcat(bufnum
, ", ");
354 (void) _nc_trace_bufcat(bufnum
,
355 _nc_tracechar(CURRENT_SCREEN
,
356 UChar(PUTC_buf
[n
])));
359 (void) _nc_trace_bufcat(bufnum
, " }");
361 if (attr
!= A_NORMAL
) {
362 (void) _nc_trace_bufcat(bufnum
, " | ");
363 (void) _nc_trace_bufcat(bufnum
, _traceattr2(bufnum
+ 20, attr
));
367 result
= _nc_trace_bufcat(bufnum
, r_brace
);
372 NCURSES_EXPORT(char *)
373 _tracecchar_t(const cchar_t
*ch
)
375 return _tracecchar_t2(0, ch
);
380 EMPTY_MODULE(_nc_lib_traceatr
)