1 /****************************************************************************
2 * Copyright (c) 1998,1999,2000 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 ****************************************************************************/
34 #include <curses.priv.h>
35 #include <term.h> /* cur_term */
37 MODULE_ID("$Id: lib_tracebits.c,v 1.7 2000/09/02 18:08:37 tom Exp $")
39 #if SVR4_TERMIO && !defined(_POSIX_SOURCE)
44 #include <sys/termio.h> /* needed for ISC */
51 /* may be undefined if we're using termio.h */
67 lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int val)
71 (void) strcat(buf, label);
72 (void) strcat(buf, ": {");
73 for (sp = table; sp->name; sp++)
75 && (val & sp->val) == sp->val) {
76 (void) strcat(buf, sp->name);
77 (void) strcat(buf, ", ");
79 if (buf[strlen(buf) - 2] == ',')
80 buf[strlen(buf) - 2] = '\0';
81 (void) strcat(buf, "} ");
86 /* describe the state of the terminal control bits exactly */
91 static const BITNAMES iflags[] =
105 #define ALLIN (BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF)
110 #define ALLOUT (OPOST)
116 #if !defined(CS5) || !defined(CS8)
121 {PARODD | PARENB, "PARODD"}, /* concession to readability */
123 #define ALLCTRL (CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD)
127 {ECHOE | ECHO, "ECHOE"}, /* concession to readability */
128 {ECHOK | ECHO, "ECHOK"}, /* concession to readability */
136 #define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
139 buf = _nc_trace_buf(0,
146 if (cur_term->Nttyb.c_iflag & ALLIN)
147 lookup_bits(buf, iflags, "iflags", cur_term->Nttyb.c_iflag);
149 if (cur_term->Nttyb.c_oflag & ALLOUT)
150 lookup_bits(buf, oflags, "oflags", cur_term->Nttyb.c_oflag);
152 if (cur_term->Nttyb.c_cflag & ALLCTRL)
153 lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.c_cflag);
155 #if defined(CS5) && defined(CS8)
178 char *result = "CSIZE? ";
179 int value = (cur_term->Nttyb.c_cflag & CSIZE);
183 for (n = 0; n < SIZEOF(csizes); n++) {
184 if (csizes[n].value == value) {
185 result = csizes[n].name;
194 if (cur_term->Nttyb.c_lflag & ALLLOCAL)
195 lookup_bits(buf, lflags, "lflags", cur_term->Nttyb.c_lflag);
198 /* reference: ttcompat(4M) on SunOS 4.1 */
215 static const BITNAMES cflags[] =
222 {LLITOUT, "LLITOUT"},
228 #define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
231 buf = _nc_trace_buf(0,
234 if (cur_term->Nttyb.sg_flags & ALLCTRL) {
235 lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.sg_flags);
244 static char tmp[] = "";