1 /****************************************************************************
2 * Copyright (c) 1998 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.3 1999/08/21 21:43:48 tom Exp $")
39 #if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE)
44 #include <sys/termio.h> /* needed for ISC */
52 /* may be undefined if we're using termio.h */
62 typedef struct {unsigned int val; const char *name;} BITNAMES;
64 static void lookup_bits(char *buf, const BITNAMES *table, const char *label, unsigned int val)
68 (void) strcat(buf, label);
69 (void) strcat(buf, ": {");
70 for (sp = table; sp->name; sp++)
72 && (val & sp->val) == sp->val)
74 (void) strcat(buf, sp->name);
75 (void) strcat(buf, ", ");
77 if (buf[strlen(buf) - 2] == ',')
78 buf[strlen(buf) - 2] = '\0';
79 (void) strcat(buf,"} ");
82 char *_nc_tracebits(void)
83 /* describe the state of the terminal control bits exactly */
103 #define ALLIN (BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF)
109 #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)
128 {ECHOE|ECHO, "ECHOE"}, /* concession to readability */
129 {ECHOK|ECHO, "ECHOK"}, /* concession to readability */
137 #define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
141 buf = _nc_trace_buf(0,
148 if (cur_term->Nttyb.c_iflag & ALLIN)
149 lookup_bits(buf, iflags, "iflags", cur_term->Nttyb.c_iflag);
151 if (cur_term->Nttyb.c_oflag & ALLOUT)
152 lookup_bits(buf, oflags, "oflags", cur_term->Nttyb.c_oflag);
154 if (cur_term->Nttyb.c_cflag & ALLCTRL)
155 lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.c_cflag);
157 #if defined(CS5) && defined(CS8)
158 switch (cur_term->Nttyb.c_cflag & CSIZE) {
159 #if defined(CS5) && (CS5 != 0)
160 case CS5: strcat(buf, "CS5 "); break;
162 #if defined(CS6) && (CS6 != 0)
163 case CS6: strcat(buf, "CS6 "); break;
165 #if defined(CS7) && (CS7 != 0)
166 case CS7: strcat(buf, "CS7 "); break;
168 #if defined(CS8) && (CS8 != 0)
169 case CS8: strcat(buf, "CS8 "); break;
171 default: strcat(buf, "CSIZE? "); break;
175 if (cur_term->Nttyb.c_lflag & ALLLOCAL)
176 lookup_bits(buf, lflags, "lflags", cur_term->Nttyb.c_lflag);
179 /* reference: ttcompat(4M) on SunOS 4.1 */
203 {LLITOUT, "LLITOUT"},
209 #define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
212 buf = _nc_trace_buf(0,
215 if (cur_term->Nttyb.sg_flags & ALLCTRL)
217 lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.sg_flags);
224 char *_nc_tracebits(void) { static char tmp[] = ""; return tmp; }