]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/trace/lib_traceatr.c
d9e007517f76b72cd7ecb8f10d72ade4c2b2a927
[ncurses.git] / ncurses / trace / lib_traceatr.c
1 /****************************************************************************
2  * Copyright (c) 1998 Free Software Foundation, Inc.                        *
3  *                                                                          *
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:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
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.                               *
22  *                                                                          *
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       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32  ****************************************************************************/
33
34
35
36 /*
37  *      lib_traceatr.c - Tracing/Debugging routines (attributes)
38  */
39
40 #include <curses.priv.h>
41 #include <term.h>       /* acs_chars */
42
43 MODULE_ID("$Id: lib_traceatr.c,v 1.28 1998/03/21 18:39:36 tom Exp $")
44
45 #define COLOR_OF(c) (c < 0 || c > 7 ? "default" : colors[c].name)
46
47 #ifdef TRACE
48 char *_traceattr2(int bufnum, attr_t newmode)
49 {
50 char    *buf = _nc_trace_buf(bufnum, BUFSIZ);
51 char    *tmp = buf;
52 static const    struct {unsigned int val; const char *name;}
53 names[] =
54     {
55         { A_STANDOUT,           "A_STANDOUT" },
56         { A_UNDERLINE,          "A_UNDERLINE" },
57         { A_REVERSE,            "A_REVERSE" },
58         { A_BLINK,              "A_BLINK" },
59         { A_DIM,                "A_DIM" },
60         { A_BOLD,               "A_BOLD" },
61         { A_ALTCHARSET,         "A_ALTCHARSET" },
62         { A_INVIS,              "A_INVIS" },
63         { A_PROTECT,            "A_PROTECT" },
64         { A_CHARTEXT,           "A_CHARTEXT" },
65         { A_NORMAL,             "A_NORMAL" },
66         { A_COLOR,              "A_COLOR" },
67     },
68 colors[] =
69     {
70         { COLOR_BLACK,          "COLOR_BLACK" },
71         { COLOR_RED,            "COLOR_RED" },
72         { COLOR_GREEN,          "COLOR_GREEN" },
73         { COLOR_YELLOW,         "COLOR_YELLOW" },
74         { COLOR_BLUE,           "COLOR_BLUE" },
75         { COLOR_MAGENTA,        "COLOR_MAGENTA" },
76         { COLOR_CYAN,           "COLOR_CYAN" },
77         { COLOR_WHITE,          "COLOR_WHITE" },
78     };
79 size_t n;
80 unsigned save_nc_tracing = _nc_tracing;
81         _nc_tracing = 0;
82
83         strcpy(tmp++, "{");
84
85         for (n = 0; n < SIZEOF(names); n++) {
86                 if ((newmode & names[n].val) != 0) {
87                         if (buf[1] != '\0')
88                                 strcat(tmp, "|");
89                         strcat(tmp, names[n].name);
90                         tmp += strlen(tmp);
91
92                         if (names[n].val == A_COLOR)
93                         {
94                                 short pairnum = PAIR_NUMBER(newmode);
95                                 short fg, bg;
96         
97                                 if (pair_content(pairnum, &fg, &bg) == OK)
98                                         (void) sprintf(tmp,
99                                                 "{%d = {%s, %s}}",
100                                                 pairnum,
101                                                 COLOR_OF(fg),
102                                                 COLOR_OF(bg)
103                                                 );
104                                 else
105                                         (void) sprintf(tmp, "{%d}", pairnum);
106                         }
107                 }
108         }
109         if (AttrOf(newmode) == A_NORMAL) {
110                 if (buf[1] != '\0')
111                         strcat(tmp, "|");
112                 strcat(tmp, "A_NORMAL");
113         }
114
115         _nc_tracing = save_nc_tracing;
116         return (strcat(buf,"}"));
117 }
118
119 char *_traceattr(attr_t newmode)
120 {
121         return _traceattr2(0, newmode);
122 }
123
124 /* Trace 'int' return-values */
125 attr_t _nc_retrace_attr_t(attr_t code)
126 {
127         T((T_RETURN("%s"), _traceattr(code)));
128         return code;
129 }
130
131 char *_tracechtype2(int bufnum, chtype ch)
132 {
133 char    *buf = _nc_trace_buf(bufnum, BUFSIZ);
134 char    *found = 0;
135
136     strcpy(buf, "{");
137     if (ch & A_ALTCHARSET)
138     {
139         char    *cp;
140         static const    struct {unsigned int val; const char *name;}
141         names[] =
142         {
143             {'l', "ACS_ULCORNER"},      /* upper left corner */
144             {'m', "ACS_LLCORNER"},      /* lower left corner */
145             {'k', "ACS_URCORNER"},      /* upper right corner */
146             {'j', "ACS_LRCORNER"},      /* lower right corner */
147             {'t', "ACS_LTEE"},          /* tee pointing right */
148             {'u', "ACS_RTEE"},          /* tee pointing left */
149             {'v', "ACS_BTEE"},          /* tee pointing up */
150             {'w', "ACS_TTEE"},          /* tee pointing down */
151             {'q', "ACS_HLINE"},         /* horizontal line */
152             {'x', "ACS_VLINE"},         /* vertical line */
153             {'n', "ACS_PLUS"},          /* large plus or crossover */
154             {'o', "ACS_S1"},            /* scan line 1 */
155             {'s', "ACS_S9"},            /* scan line 9 */
156             {'`', "ACS_DIAMOND"},       /* diamond */
157             {'a', "ACS_CKBOARD"},       /* checker board (stipple) */
158             {'f', "ACS_DEGREE"},        /* degree symbol */
159             {'g', "ACS_PLMINUS"},       /* plus/minus */
160             {'~', "ACS_BULLET"},        /* bullet */
161             {',', "ACS_LARROW"},        /* arrow pointing left */
162             {'+', "ACS_RARROW"},        /* arrow pointing right */
163             {'.', "ACS_DARROW"},        /* arrow pointing down */
164             {'-', "ACS_UARROW"},        /* arrow pointing up */
165             {'h', "ACS_BOARD"},         /* board of squares */
166             {'i', "ACS_LANTERN"},       /* lantern symbol */
167             {'0', "ACS_BLOCK"},         /* solid square block */
168             {'p', "ACS_S3"},            /* scan line 3 */
169             {'r', "ACS_S7"},            /* scan line 7 */
170             {'y', "ACS_LEQUAL"},        /* less/equal */
171             {'z', "ACS_GEQUAL"},        /* greater/equal */
172             {'{', "ACS_PI"},            /* Pi */
173             {'|', "ACS_NEQUAL"},        /* not equal */
174             {'}', "ACS_STERLING"},      /* UK pound sign */
175             {'\0',(char *)0}
176         },
177         *sp;
178
179         for (cp = acs_chars; cp[0] && cp[1]; cp += 2)
180         {
181             if (TextOf(cp[1]) == TextOf(ch))
182             {
183                 found = cp;
184                 /* don't exit from loop - there may be redefinitions */
185             }
186         }
187
188         if (found != 0)
189         {
190             ch = TextOf(*found);
191             for (sp = names; sp->val; sp++)
192                 if (sp->val == ch)
193                 {
194                     (void) strcat(buf, sp->name);
195                     ch &= ~A_ALTCHARSET;
196                     break;
197                 }
198         }
199     }
200
201     if (found == 0)
202         (void) strcat(buf, _tracechar(TextOf(ch)));
203
204     if (AttrOf(ch) != A_NORMAL)
205         (void) sprintf(buf + strlen(buf), " | %s", _traceattr2(bufnum+20,AttrOf(ch)));
206
207     strcat(buf, "}");
208     return(buf);
209 }
210
211 char *_tracechtype(chtype ch)
212 {
213         return _tracechtype2(0, ch);
214 }
215 #else
216 extern  void _nc_lib_traceatr(void);
217         void _nc_lib_traceatr(void) { }
218 #endif /* TRACE */