2 /***************************************************************************
4 ****************************************************************************
5 * ncurses is copyright (C) 1992-1995 *
7 * zmbenhal@netcom.com *
9 * esr@snark.thyrsus.com *
11 * Permission is hereby granted to reproduce and distribute ncurses *
12 * by any means and for any fee, whether alone or as part of a *
13 * larger distribution, in source or in binary form, PROVIDED *
14 * this notice is included with any such distribution, and is not *
15 * removed from any of its header files. Mention of ncurses in any *
16 * applications linked with it is highly appreciated. *
18 * ncurses comes AS IS with no warranty, implied or expressed. *
20 ***************************************************************************/
25 * lib_traceatr.c - Tracing/Debugging routines (attributes)
29 #define TRACE /* turn on internal defs for this module */
32 #include <curses.priv.h>
33 #include <term.h> /* acs_chars */
35 MODULE_ID("$Id: lib_traceatr.c,v 1.20 1997/05/06 11:07:27 tom Exp $")
37 #define COLOR_OF(c) (c < 0 || c > 7 ? "default" : colors[c].name)
39 char * _nc_trace_buf(int bufnum, size_t want)
50 if ((size_t)(bufnum+1) > have) {
51 size_t need = (bufnum + 1) * 2;
52 size_t used = sizeof(*list) * need;
53 list = (list == 0) ? malloc(used) : realloc(list, used);
55 list[have++].text = 0;
58 if (list[bufnum].text == 0)
60 list[bufnum].text = malloc(want);
61 list[bufnum].size = want;
63 else if (want > list[bufnum].size) {
64 list[bufnum].text = realloc(list[bufnum].text, want);
65 list[bufnum].size = want;
67 *(list[bufnum].text) = '\0';
68 return list[bufnum].text;
71 char *_traceattr2(int bufnum, attr_t newmode)
73 char *buf = _nc_trace_buf(bufnum, BUFSIZ);
75 static const struct {unsigned int val; const char *name;}
78 { A_STANDOUT, "A_STANDOUT" },
79 { A_UNDERLINE, "A_UNDERLINE" },
80 { A_REVERSE, "A_REVERSE" },
81 { A_BLINK, "A_BLINK" },
84 { A_ALTCHARSET, "A_ALTCHARSET" },
85 { A_INVIS, "A_INVIS" },
86 { A_PROTECT, "A_PROTECT" },
87 { A_CHARTEXT, "A_CHARTEXT" },
88 { A_NORMAL, "A_NORMAL" },
89 { A_COLOR, "A_COLOR" },
93 { COLOR_BLACK, "COLOR_BLACK" },
94 { COLOR_RED, "COLOR_RED" },
95 { COLOR_GREEN, "COLOR_GREEN" },
96 { COLOR_YELLOW, "COLOR_YELLOW" },
97 { COLOR_BLUE, "COLOR_BLUE" },
98 { COLOR_MAGENTA, "COLOR_MAGENTA" },
99 { COLOR_CYAN, "COLOR_CYAN" },
100 { COLOR_WHITE, "COLOR_WHITE" },
103 unsigned save_nc_tracing = _nc_tracing;
108 for (n = 0; n < sizeof(names)/sizeof(names[0]); n++) {
109 if ((newmode & names[n].val) != 0) {
112 strcat(tmp, names[n].name);
115 if (names[n].val == A_COLOR)
117 short pairnum = PAIR_NUMBER(newmode);
120 if (pair_content(pairnum, &fg, &bg) == OK)
128 (void) sprintf(tmp, "{%d}", pairnum);
132 if (AttrOf(newmode) == A_NORMAL) {
135 strcat(tmp, "A_NORMAL");
138 _nc_tracing = save_nc_tracing;
139 return (strcat(buf,"}"));
142 char *_traceattr(attr_t newmode)
144 return _traceattr2(0, newmode);
147 char *_tracechtype2(int bufnum, chtype ch)
149 char *buf = _nc_trace_buf(bufnum, BUFSIZ);
153 if (ch & A_ALTCHARSET)
156 static const struct {unsigned int val; const char *name;}
159 {'l', "ACS_ULCORNER"}, /* upper left corner */
160 {'m', "ACS_LLCORNER"}, /* lower left corner */
161 {'k', "ACS_URCORNER"}, /* upper right corner */
162 {'j', "ACS_LRCORNER"}, /* lower right corner */
163 {'t', "ACS_LTEE"}, /* tee pointing right */
164 {'u', "ACS_RTEE"}, /* tee pointing left */
165 {'v', "ACS_BTEE"}, /* tee pointing up */
166 {'w', "ACS_TTEE"}, /* tee pointing down */
167 {'q', "ACS_HLINE"}, /* horizontal line */
168 {'x', "ACS_VLINE"}, /* vertical line */
169 {'n', "ACS_PLUS"}, /* large plus or crossover */
170 {'o', "ACS_S1"}, /* scan line 1 */
171 {'s', "ACS_S9"}, /* scan line 9 */
172 {'`', "ACS_DIAMOND"}, /* diamond */
173 {'a', "ACS_CKBOARD"}, /* checker board (stipple) */
174 {'f', "ACS_DEGREE"}, /* degree symbol */
175 {'g', "ACS_PLMINUS"}, /* plus/minus */
176 {'~', "ACS_BULLET"}, /* bullet */
177 {',', "ACS_LARROW"}, /* arrow pointing left */
178 {'+', "ACS_RARROW"}, /* arrow pointing right */
179 {'.', "ACS_DARROW"}, /* arrow pointing down */
180 {'-', "ACS_UARROW"}, /* arrow pointing up */
181 {'h', "ACS_BOARD"}, /* board of squares */
182 {'I', "ACS_LANTERN"}, /* lantern symbol */
183 {'0', "ACS_BLOCK"}, /* solid square block */
184 {'p', "ACS_S3"}, /* scan line 3 */
185 {'r', "ACS_S7"}, /* scan line 7 */
186 {'y', "ACS_LEQUAL"}, /* less/equal */
187 {'z', "ACS_GEQUAL"}, /* greater/equal */
188 {'{', "ACS_PI"}, /* Pi */
189 {'|', "ACS_NEQUAL"}, /* not equal */
190 {'}', "ACS_STERLING"}, /* UK pound sign */
195 for (cp = acs_chars; cp[0] && cp[1]; cp += 2)
197 if (TextOf(cp[1]) == TextOf(ch))
200 /* don't exit from loop - there may be redefinitions */
207 for (sp = names; sp->val; sp++)
210 (void) strcat(buf, sp->name);
218 (void) strcat(buf, _tracechar(TextOf(ch)));
220 if (AttrOf(ch) != A_NORMAL)
221 (void) sprintf(buf + strlen(buf), " | %s", _traceattr2(bufnum+20,AttrOf(ch)));
227 char *_tracechtype(chtype ch)
229 return _tracechtype2(0, ch);