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