1 /****************************************************************************
2 * Copyright 2019,2020 Thomas E. Dickey *
3 * Copyright 1998-2012,2015 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
32 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
33 * and: Thomas E. Dickey 1996-on *
34 ****************************************************************************/
36 #include <curses.priv.h>
38 MODULE_ID("$Id: lib_tracebits.c,v 1.30 2020/09/05 22:54:47 tom Exp $")
41 #include <sys/termio.h> /* needed for ISC */
48 /* may be undefined if we're using termio.h */
75 #if defined(EXP_WIN32_DRIVER)
83 const char name[BITNAMELEN];
86 #define TRACE_BUF_SIZE(num) (_nc_globals.tracebuf_ptr[num].size)
89 lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int val)
93 _nc_STRCAT(buf, label, TRACE_BUF_SIZE(0));
94 _nc_STRCAT(buf, ": {", TRACE_BUF_SIZE(0));
95 for (sp = table; sp->name[0]; sp++)
97 && (val & sp->val) == sp->val) {
98 _nc_STRCAT(buf, sp->name, TRACE_BUF_SIZE(0));
99 _nc_STRCAT(buf, ", ", TRACE_BUF_SIZE(0));
101 if (buf[strlen(buf) - 2] == ',')
102 buf[strlen(buf) - 2] = '\0';
103 _nc_STRCAT(buf, "} ", TRACE_BUF_SIZE(0));
106 NCURSES_EXPORT(char *)
107 _nc_trace_ttymode(TTY * tty)
108 /* describe the state of the terminal control bits exactly */
113 #define DATA(name) { name, { #name } }
114 #define DATA2(name,name2) { name, { #name2 } }
115 #define DATAX() { 0, { "" } }
116 static const BITNAMES iflags[] =
130 #define ALLIN (BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF)
134 DATA2(OFLAGS_TABS, XTABS),
140 #define ALLOUT (OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET|OFLAGS_TABS)
146 #if !defined(CS5) || !defined(CS8)
151 DATA2(PARODD | PARENB, PARODD),
153 #define ALLCTRL (CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD)
157 DATA2(ECHOE | ECHO, ECHOE),
158 DATA2(ECHOK | ECHO, ECHOK),
166 #define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
169 buf = _nc_trace_buf(0,
177 if (tty->c_iflag & ALLIN)
178 lookup_bits(buf, iflags, "iflags", tty->c_iflag);
180 if (tty->c_oflag & ALLOUT)
181 lookup_bits(buf, oflags, "oflags", tty->c_oflag);
183 if (tty->c_cflag & ALLCTRL)
184 lookup_bits(buf, cflags, "cflags", tty->c_cflag);
186 #if defined(CS5) && defined(CS8)
188 static const struct {
192 #define CS_DATA(name) { name, { #name " " } }
202 const char *result = "CSIZE? ";
203 int value = (int) (tty->c_cflag & CSIZE);
207 for (n = 0; n < SIZEOF(csizes); n++) {
208 if (csizes[n].value == value) {
209 result = csizes[n].name;
214 _nc_STRCAT(buf, result, TRACE_BUF_SIZE(0));
218 if (tty->c_lflag & ALLLOCAL)
219 lookup_bits(buf, lflags, "lflags", tty->c_lflag);
221 #elif defined(EXP_WIN32_DRIVER)
222 #define DATA(name) { name, { #name } }
223 static const BITNAMES dwFlagsOut[] =
225 DATA(ENABLE_PROCESSED_OUTPUT),
226 DATA(ENABLE_WRAP_AT_EOL_OUTPUT),
227 DATA(ENABLE_VIRTUAL_TERMINAL_PROCESSING),
228 DATA(DISABLE_NEWLINE_AUTO_RETURN),
229 DATA(ENABLE_LVB_GRID_WORLDWIDE)
231 static const BITNAMES dwFlagsIn[] =
233 DATA(ENABLE_PROCESSED_INPUT),
234 DATA(ENABLE_LINE_INPUT),
235 DATA(ENABLE_ECHO_INPUT),
236 DATA(ENABLE_MOUSE_INPUT),
237 DATA(ENABLE_INSERT_MODE),
238 DATA(ENABLE_QUICK_EDIT_MODE),
239 DATA(ENABLE_EXTENDED_FLAGS),
240 DATA(ENABLE_AUTO_POSITION),
241 DATA(ENABLE_VIRTUAL_TERMINAL_INPUT)
244 buf = _nc_trace_buf(0,
245 8 + sizeof(dwFlagsOut) +
246 8 + sizeof(dwFlagsIn));
248 lookup_bits(buf, dwFlagsIn, "dwIn", tty->dwFlagIn);
249 lookup_bits(buf, dwFlagsOut, "dwOut", tty->dwFlagOut);
252 /* reference: ttcompat(4M) on SunOS 4.1 */
269 static const BITNAMES cflags[] =
282 #define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
285 buf = _nc_trace_buf(0,
288 if (tty->sg_flags & ALLCTRL) {
289 lookup_bits(buf, cflags, "cflags", tty->sg_flags);
296 NCURSES_EXPORT(char *)
299 return _nc_trace_ttymode(&(cur_term->Nttyb));
302 EMPTY_MODULE(_nc_empty_lib_tracebits)