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.28 2020/02/02 23:34:34 tom Exp $")
41 #include <sys/termio.h> /* needed for ISC */
48 /* may be undefined if we're using termio.h */
80 #define TRACE_BUF_SIZE(num) (_nc_globals.tracebuf_ptr[num].size)
83 lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int val)
87 _nc_STRCAT(buf, label, TRACE_BUF_SIZE(0));
88 _nc_STRCAT(buf, ": {", TRACE_BUF_SIZE(0));
89 for (sp = table; sp->name[0]; sp++)
91 && (val & sp->val) == sp->val) {
92 _nc_STRCAT(buf, sp->name, TRACE_BUF_SIZE(0));
93 _nc_STRCAT(buf, ", ", TRACE_BUF_SIZE(0));
95 if (buf[strlen(buf) - 2] == ',')
96 buf[strlen(buf) - 2] = '\0';
97 _nc_STRCAT(buf, "} ", TRACE_BUF_SIZE(0));
100 NCURSES_EXPORT(char *)
101 _nc_trace_ttymode(TTY * tty)
102 /* describe the state of the terminal control bits exactly */
107 #define DATA(name) { name, { #name } }
108 #define DATA2(name,name2) { name, { #name2 } }
109 #define DATAX() { 0, { "" } }
110 static const BITNAMES iflags[] =
124 #define ALLIN (BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF)
128 DATA2(OFLAGS_TABS, XTABS),
134 #define ALLOUT (OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET|OFLAGS_TABS)
140 #if !defined(CS5) || !defined(CS8)
145 DATA2(PARODD | PARENB, PARODD),
147 #define ALLCTRL (CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD)
151 DATA2(ECHOE | ECHO, ECHOE),
152 DATA2(ECHOK | ECHO, ECHOK),
160 #define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
163 buf = _nc_trace_buf(0,
171 if (tty->c_iflag & ALLIN)
172 lookup_bits(buf, iflags, "iflags", tty->c_iflag);
174 if (tty->c_oflag & ALLOUT)
175 lookup_bits(buf, oflags, "oflags", tty->c_oflag);
177 if (tty->c_cflag & ALLCTRL)
178 lookup_bits(buf, cflags, "cflags", tty->c_cflag);
180 #if defined(CS5) && defined(CS8)
182 static const struct {
186 #define CS_DATA(name) { name, { #name " " } }
196 const char *result = "CSIZE? ";
197 int value = (int) (tty->c_cflag & CSIZE);
201 for (n = 0; n < SIZEOF(csizes); n++) {
202 if (csizes[n].value == value) {
203 result = csizes[n].name;
208 _nc_STRCAT(buf, result, TRACE_BUF_SIZE(0));
212 if (tty->c_lflag & ALLLOCAL)
213 lookup_bits(buf, lflags, "lflags", tty->c_lflag);
216 /* reference: ttcompat(4M) on SunOS 4.1 */
233 static const BITNAMES cflags[] =
246 #define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
249 buf = _nc_trace_buf(0,
252 if (tty->sg_flags & ALLCTRL) {
253 lookup_bits(buf, cflags, "cflags", tty->sg_flags);
260 NCURSES_EXPORT(char *)
263 return _nc_trace_ttymode(&(cur_term->Nttyb));
266 EMPTY_MODULE(_nc_empty_lib_tracebits)