1 /****************************************************************************
2 * Copyright (c) 1998-2002,2006 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.13 2006/12/10 01:33:00 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 */
68 lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int val)
72 (void) strcat(buf, label);
73 (void) strcat(buf, ": {");
74 for (sp = table; sp->name; sp++)
76 && (val & sp->val) == sp->val) {
77 (void) strcat(buf, sp->name);
78 (void) strcat(buf, ", ");
80 if (buf[strlen(buf) - 2] == ',')
81 buf[strlen(buf) - 2] = '\0';
82 (void) strcat(buf, "} ");
85 NCURSES_EXPORT(char *)
86 _nc_trace_ttymode(TTY * tty)
87 /* describe the state of the terminal control bits exactly */
92 static const BITNAMES iflags[] =
106 #define ALLIN (BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF)
110 {OFLAGS_TABS, "XTABS"},
112 #define ALLOUT (OPOST)
118 #if !defined(CS5) || !defined(CS8)
123 {PARODD | PARENB, "PARODD"}, /* concession to readability */
125 #define ALLCTRL (CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD)
129 {ECHOE | ECHO, "ECHOE"}, /* concession to readability */
130 {ECHOK | ECHO, "ECHOK"}, /* concession to readability */
138 #define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
141 buf = _nc_trace_buf(0,
148 if (tty->c_iflag & ALLIN)
149 lookup_bits(buf, iflags, "iflags", tty->c_iflag);
151 if (tty->c_oflag & ALLOUT)
152 lookup_bits(buf, oflags, "oflags", tty->c_oflag);
154 if (tty->c_cflag & ALLCTRL)
155 lookup_bits(buf, cflags, "cflags", tty->c_cflag);
157 #if defined(CS5) && defined(CS8)
180 const char *result = "CSIZE? ";
181 int value = (tty->c_cflag & CSIZE);
185 for (n = 0; n < SIZEOF(csizes); n++) {
186 if (csizes[n].value == value) {
187 result = csizes[n].name;
196 if (tty->c_lflag & ALLLOCAL)
197 lookup_bits(buf, lflags, "lflags", tty->c_lflag);
200 /* reference: ttcompat(4M) on SunOS 4.1 */
217 static const BITNAMES cflags[] =
224 {LLITOUT, "LLITOUT"},
230 #define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
233 buf = _nc_trace_buf(0,
236 if (tty->sg_flags & ALLCTRL) {
237 lookup_bits(buf, cflags, "cflags", tty->sg_flags);
243 NCURSES_EXPORT(char *)
246 return _nc_trace_ttymode(&(cur_term->Nttyb));
249 empty_module(_nc_tracebits)