1 /****************************************************************************
2 * Copyright (c) 1998-2007,2008 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>
36 #include <term.h> /* cur_term */
38 MODULE_ID("$Id: lib_tracebits.c,v 1.17 2008/08/03 16:09:26 tom Exp $")
40 #if SVR4_TERMIO && !defined(_POSIX_SOURCE)
45 #include <sys/termio.h> /* needed for ISC */
52 /* may be undefined if we're using termio.h */
85 lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int val)
89 (void) strcat(buf, label);
90 (void) strcat(buf, ": {");
91 for (sp = table; sp->name; sp++)
93 && (val & sp->val) == sp->val) {
94 (void) strcat(buf, sp->name);
95 (void) strcat(buf, ", ");
97 if (buf[strlen(buf) - 2] == ',')
98 buf[strlen(buf) - 2] = '\0';
99 (void) strcat(buf, "} ");
102 NCURSES_EXPORT(char *)
103 _nc_trace_ttymode(TTY * tty)
104 /* describe the state of the terminal control bits exactly */
109 static const BITNAMES iflags[] =
123 #define ALLIN (BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF)
127 {OFLAGS_TABS, "XTABS"},
133 #define ALLOUT (OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET)
139 #if !defined(CS5) || !defined(CS8)
144 {PARODD | PARENB, "PARODD"}, /* concession to readability */
146 #define ALLCTRL (CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD)
150 {ECHOE | ECHO, "ECHOE"}, /* concession to readability */
151 {ECHOK | ECHO, "ECHOK"}, /* concession to readability */
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)
185 #define CS_DATA(name) { name, #name " " }
195 const char *result = "CSIZE? ";
196 int value = (tty->c_cflag & CSIZE);
200 for (n = 0; n < SIZEOF(csizes); n++) {
201 if (csizes[n].value == value) {
202 result = csizes[n].name;
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[] =
239 {LLITOUT, "LLITOUT"},
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_tracebits)