1 /****************************************************************************
2 * Copyright (c) 1998-2012,2015 Free Software Foundation, Inc. *
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: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
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. *
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 *
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 $")
40 #include <sys/termio.h> /* needed for ISC */
47 /* may be undefined if we're using termio.h */
79 #define TRACE_BUF_SIZE(num) (_nc_globals.tracebuf_ptr[num].size)
82 lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int val)
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++)
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 */
106 #define DATA(name) { name, { #name } }
107 #define DATA2(name,name2) { name, { #name2 } }
108 #define DATAX() { 0, { "" } }
109 static const BITNAMES iflags[] =
123 #define ALLIN (BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF)
127 DATA2(OFLAGS_TABS, XTABS),
133 #define ALLOUT (OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET)
139 #if !defined(CS5) || !defined(CS8)
144 DATA2(PARODD | PARENB, PARODD),
146 #define ALLCTRL (CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD)
150 DATA2(ECHOE | ECHO, ECHOE),
151 DATA2(ECHOK | ECHO, ECHOK),
159 #define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
162 buf = _nc_trace_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 {
185 #define CS_DATA(name) { name, { #name " " } }
195 const char *result = "CSIZE? ";
196 int value = (int) (tty->c_cflag & CSIZE);
200 for (n = 0; n < SIZEOF(csizes); n++) {
201 if (csizes[n].value == value) {
202 result = csizes[n].name;
207 _nc_STRCAT(buf, result, TRACE_BUF_SIZE(0));
211 if (tty->c_lflag & ALLLOCAL)
212 lookup_bits(buf, lflags, "lflags", tty->c_lflag);
215 /* reference: ttcompat(4M) on SunOS 4.1 */
232 static const BITNAMES cflags[] =
245 #define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
248 buf = _nc_trace_buf(0,
251 if (tty->sg_flags & ALLCTRL) {
252 lookup_bits(buf, cflags, "cflags", tty->sg_flags);
259 NCURSES_EXPORT(char *)
262 return _nc_trace_ttymode(&(cur_term->Nttyb));
265 EMPTY_MODULE(_nc_empty_lib_tracebits)