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