libncurses: updated to 6.0
[tomato.git] / release / src / router / libncurses / ncurses / trace / lib_tracebits.c
blobf880b674403164a3ac373c0597444da4f822c9f8
1 /****************************************************************************
2 * Copyright (c) 1998-2012,2015 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 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 * and: Thomas E. Dickey 1996-on *
33 ****************************************************************************/
35 #include <curses.priv.h>
37 MODULE_ID("$Id: lib_tracebits.c,v 1.26 2015/04/19 14:58:39 tom Exp $")
39 #if HAVE_SYS_TERMIO_H
40 #include <sys/termio.h> /* needed for ISC */
41 #endif
43 #ifdef __EMX__
44 #include <io.h>
45 #endif
47 /* may be undefined if we're using termio.h */
48 #ifndef TOSTOP
49 #define TOSTOP 0
50 #endif
52 #ifndef IEXTEN
53 #define IEXTEN 0
54 #endif
56 #ifndef ONLCR
57 #define ONLCR 0
58 #endif
60 #ifndef OCRNL
61 #define OCRNL 0
62 #endif
64 #ifndef ONOCR
65 #define ONOCR 0
66 #endif
68 #ifndef ONLRET
69 #define ONLRET 0
70 #endif
72 #ifdef TRACE
74 typedef struct {
75 unsigned int val;
76 const char name[8];
77 } BITNAMES;
79 #define TRACE_BUF_SIZE(num) (_nc_globals.tracebuf_ptr[num].size)
81 static void
82 lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int val)
84 const BITNAMES *sp;
86 _nc_STRCAT(buf, label, TRACE_BUF_SIZE(0));
87 _nc_STRCAT(buf, ": {", TRACE_BUF_SIZE(0));
88 for (sp = table; sp->name[0]; sp++)
89 if (sp->val != 0
90 && (val & sp->val) == sp->val) {
91 _nc_STRCAT(buf, sp->name, TRACE_BUF_SIZE(0));
92 _nc_STRCAT(buf, ", ", TRACE_BUF_SIZE(0));
94 if (buf[strlen(buf) - 2] == ',')
95 buf[strlen(buf) - 2] = '\0';
96 _nc_STRCAT(buf, "} ", TRACE_BUF_SIZE(0));
99 NCURSES_EXPORT(char *)
100 _nc_trace_ttymode(TTY * tty)
101 /* describe the state of the terminal control bits exactly */
103 char *buf;
105 #ifdef TERMIOS
106 #define DATA(name) { name, { #name } }
107 #define DATA2(name,name2) { name, { #name2 } }
108 #define DATAX() { 0, { "" } }
109 static const BITNAMES iflags[] =
111 DATA(BRKINT),
112 DATA(IGNBRK),
113 DATA(IGNPAR),
114 DATA(PARMRK),
115 DATA(INPCK),
116 DATA(ISTRIP),
117 DATA(INLCR),
118 DATA(IGNCR),
119 DATA(ICRNL),
120 DATA(IXON),
121 DATA(IXOFF),
122 DATAX()
123 #define ALLIN (BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF)
124 }, oflags[] =
126 DATA(OPOST),
127 DATA2(OFLAGS_TABS, XTABS),
128 DATA(ONLCR),
129 DATA(OCRNL),
130 DATA(ONOCR),
131 DATA(ONLRET),
132 DATAX()
133 #define ALLOUT (OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET)
134 }, cflags[] =
136 DATA(CLOCAL),
137 DATA(CREAD),
138 DATA(CSTOPB),
139 #if !defined(CS5) || !defined(CS8)
140 DATA(CSIZE),
141 #endif
142 DATA(HUPCL),
143 DATA(PARENB),
144 DATA2(PARODD | PARENB, PARODD),
145 DATAX()
146 #define ALLCTRL (CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD)
147 }, lflags[] =
149 DATA(ECHO),
150 DATA2(ECHOE | ECHO, ECHOE),
151 DATA2(ECHOK | ECHO, ECHOK),
152 DATA(ECHONL),
153 DATA(ICANON),
154 DATA(ISIG),
155 DATA(NOFLSH),
156 DATA(TOSTOP),
157 DATA(IEXTEN),
158 DATAX()
159 #define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
162 buf = _nc_trace_buf(0,
163 8 + sizeof(iflags) +
164 8 + sizeof(oflags) +
165 8 + sizeof(cflags) +
166 8 + sizeof(lflags) +
168 if (buf != 0) {
170 if (tty->c_iflag & ALLIN)
171 lookup_bits(buf, iflags, "iflags", tty->c_iflag);
173 if (tty->c_oflag & ALLOUT)
174 lookup_bits(buf, oflags, "oflags", tty->c_oflag);
176 if (tty->c_cflag & ALLCTRL)
177 lookup_bits(buf, cflags, "cflags", tty->c_cflag);
179 #if defined(CS5) && defined(CS8)
181 static const struct {
182 int value;
183 const char name[5];
184 } csizes[] = {
185 #define CS_DATA(name) { name, { #name " " } }
186 CS_DATA(CS5),
187 #ifdef CS6
188 CS_DATA(CS6),
189 #endif
190 #ifdef CS7
191 CS_DATA(CS7),
192 #endif
193 CS_DATA(CS8),
195 const char *result = "CSIZE? ";
196 int value = (int) (tty->c_cflag & CSIZE);
197 unsigned n;
199 if (value != 0) {
200 for (n = 0; n < SIZEOF(csizes); n++) {
201 if (csizes[n].value == value) {
202 result = csizes[n].name;
203 break;
207 _nc_STRCAT(buf, result, TRACE_BUF_SIZE(0));
209 #endif
211 if (tty->c_lflag & ALLLOCAL)
212 lookup_bits(buf, lflags, "lflags", tty->c_lflag);
214 #else
215 /* reference: ttcompat(4M) on SunOS 4.1 */
216 #ifndef EVENP
217 #define EVENP 0
218 #endif
219 #ifndef LCASE
220 #define LCASE 0
221 #endif
222 #ifndef LLITOUT
223 #define LLITOUT 0
224 #endif
225 #ifndef ODDP
226 #define ODDP 0
227 #endif
228 #ifndef TANDEM
229 #define TANDEM 0
230 #endif
232 static const BITNAMES cflags[] =
234 DATA(CBREAK),
235 DATA(CRMOD),
236 DATA(ECHO),
237 DATA(EVENP),
238 DATA(LCASE),
239 DATA(LLITOUT),
240 DATA(ODDP),
241 DATA(RAW),
242 DATA(TANDEM),
243 DATA(XTABS),
244 DATAX()
245 #define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
248 buf = _nc_trace_buf(0,
249 8 + sizeof(cflags));
250 if (buf != 0) {
251 if (tty->sg_flags & ALLCTRL) {
252 lookup_bits(buf, cflags, "cflags", tty->sg_flags);
255 #endif
256 return (buf);
259 NCURSES_EXPORT(char *)
260 _nc_tracebits(void)
262 return _nc_trace_ttymode(&(cur_term->Nttyb));
264 #else
265 EMPTY_MODULE(_nc_empty_lib_tracebits)
266 #endif /* TRACE */