1998-03-01 12:21:12 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (c) 1998 Free Software Foundation, Inc. *
|
|
|
|
* *
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a *
|
|
|
|
* copy of this software and associated documentation files (the *
|
|
|
|
* "Software"), to deal in the Software without restriction, including *
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish, *
|
|
|
|
* distribute, distribute with modifications, sublicense, and/or sell *
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is *
|
|
|
|
* furnished to do so, subject to the following conditions: *
|
|
|
|
* *
|
|
|
|
* The above copyright notice and this permission notice shall be included *
|
|
|
|
* in all copies or substantial portions of the Software. *
|
|
|
|
* *
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
|
|
|
|
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
|
|
|
|
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
|
|
|
|
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
|
|
|
|
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
|
|
|
|
* *
|
|
|
|
* Except as contained in this notice, the name(s) of the above copyright *
|
|
|
|
* holders shall not be used in advertising or otherwise to promote the *
|
|
|
|
* sale, use or other dealings in this Software without prior written *
|
|
|
|
* authorization. *
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
|
|
|
|
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
|
|
|
|
****************************************************************************/
|
1997-05-15 12:00:00 +08:00
|
|
|
|
|
|
|
#include <curses.priv.h>
|
|
|
|
#include <term.h> /* cur_term */
|
|
|
|
|
1999-10-24 12:32:42 +08:00
|
|
|
MODULE_ID("$Id: lib_tracebits.c,v 1.3 1999/08/21 21:43:48 tom Exp $")
|
1997-05-15 12:00:00 +08:00
|
|
|
|
1998-03-01 12:21:12 +08:00
|
|
|
#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE)
|
1997-05-15 12:00:00 +08:00
|
|
|
#define _POSIX_SOURCE
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if HAVE_SYS_TERMIO_H
|
|
|
|
#include <sys/termio.h> /* needed for ISC */
|
|
|
|
#endif
|
|
|
|
|
1998-03-01 12:21:12 +08:00
|
|
|
#ifdef __EMX__
|
|
|
|
#include <io.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#endif
|
|
|
|
|
1997-05-15 12:00:00 +08:00
|
|
|
/* may be undefined if we're using termio.h */
|
|
|
|
#ifndef TOSTOP
|
|
|
|
#define TOSTOP 0
|
|
|
|
#endif
|
|
|
|
#ifndef IEXTEN
|
|
|
|
#define IEXTEN 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef TRACE
|
1998-03-01 12:21:12 +08:00
|
|
|
|
|
|
|
typedef struct {unsigned int val; const char *name;} BITNAMES;
|
|
|
|
|
|
|
|
static void lookup_bits(char *buf, const BITNAMES *table, const char *label, unsigned int val)
|
|
|
|
{
|
|
|
|
const BITNAMES *sp;
|
|
|
|
|
|
|
|
(void) strcat(buf, label);
|
|
|
|
(void) strcat(buf, ": {");
|
|
|
|
for (sp = table; sp->name; sp++)
|
|
|
|
if (sp->val != 0
|
|
|
|
&& (val & sp->val) == sp->val)
|
|
|
|
{
|
|
|
|
(void) strcat(buf, sp->name);
|
|
|
|
(void) strcat(buf, ", ");
|
|
|
|
}
|
|
|
|
if (buf[strlen(buf) - 2] == ',')
|
|
|
|
buf[strlen(buf) - 2] = '\0';
|
|
|
|
(void) strcat(buf,"} ");
|
|
|
|
}
|
|
|
|
|
1999-10-24 12:32:42 +08:00
|
|
|
char *_nc_tracebits(void)
|
1997-05-15 12:00:00 +08:00
|
|
|
/* describe the state of the terminal control bits exactly */
|
|
|
|
{
|
1998-03-01 12:21:12 +08:00
|
|
|
char *buf;
|
|
|
|
static const BITNAMES
|
1997-05-15 12:00:00 +08:00
|
|
|
|
|
|
|
#ifdef TERMIOS
|
|
|
|
iflags[] =
|
|
|
|
{
|
|
|
|
{BRKINT, "BRKINT"},
|
|
|
|
{IGNBRK, "IGNBRK"},
|
|
|
|
{IGNPAR, "IGNPAR"},
|
|
|
|
{PARMRK, "PARMRK"},
|
|
|
|
{INPCK, "INPCK"},
|
|
|
|
{ISTRIP, "ISTRIP"},
|
|
|
|
{INLCR, "INLCR"},
|
|
|
|
{IGNCR, "IGNC"},
|
|
|
|
{ICRNL, "ICRNL"},
|
|
|
|
{IXON, "IXON"},
|
|
|
|
{IXOFF, "IXOFF"},
|
|
|
|
{0, NULL}
|
|
|
|
#define ALLIN (BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF)
|
|
|
|
},
|
|
|
|
oflags[] =
|
|
|
|
{
|
|
|
|
{OPOST, "OPOST"},
|
|
|
|
{0, NULL}
|
|
|
|
#define ALLOUT (OPOST)
|
|
|
|
},
|
|
|
|
cflags[] =
|
|
|
|
{
|
|
|
|
{CLOCAL, "CLOCAL"},
|
|
|
|
{CREAD, "CREAD"},
|
|
|
|
{CSTOPB, "CSTOPB"},
|
1998-03-01 12:21:12 +08:00
|
|
|
#if !defined(CS5) || !defined(CS8)
|
|
|
|
{CSIZE, "CSIZE"},
|
|
|
|
#endif
|
1997-05-15 12:00:00 +08:00
|
|
|
{HUPCL, "HUPCL"},
|
|
|
|
{PARENB, "PARENB"},
|
|
|
|
{PARODD|PARENB, "PARODD"}, /* concession to readability */
|
|
|
|
{0, NULL}
|
|
|
|
#define ALLCTRL (CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD)
|
|
|
|
},
|
|
|
|
lflags[] =
|
|
|
|
{
|
|
|
|
{ECHO, "ECHO"},
|
|
|
|
{ECHOE|ECHO, "ECHOE"}, /* concession to readability */
|
|
|
|
{ECHOK|ECHO, "ECHOK"}, /* concession to readability */
|
|
|
|
{ECHONL, "ECHONL"},
|
|
|
|
{ICANON, "ICANON"},
|
|
|
|
{ISIG, "ISIG"},
|
|
|
|
{NOFLSH, "NOFLSH"},
|
|
|
|
{TOSTOP, "TOSTOP"},
|
|
|
|
{IEXTEN, "IEXTEN"},
|
|
|
|
{0, NULL}
|
|
|
|
#define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
|
1998-03-01 12:21:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
buf = _nc_trace_buf(0,
|
|
|
|
8 + sizeof(iflags) +
|
|
|
|
8 + sizeof(oflags) +
|
|
|
|
8 + sizeof(cflags) +
|
|
|
|
8 + sizeof(lflags) +
|
|
|
|
8);
|
1997-05-15 12:00:00 +08:00
|
|
|
|
|
|
|
if (cur_term->Nttyb.c_iflag & ALLIN)
|
1998-03-01 12:21:12 +08:00
|
|
|
lookup_bits(buf, iflags, "iflags", cur_term->Nttyb.c_iflag);
|
1997-05-15 12:00:00 +08:00
|
|
|
|
|
|
|
if (cur_term->Nttyb.c_oflag & ALLOUT)
|
1998-03-01 12:21:12 +08:00
|
|
|
lookup_bits(buf, oflags, "oflags", cur_term->Nttyb.c_oflag);
|
1997-05-15 12:00:00 +08:00
|
|
|
|
|
|
|
if (cur_term->Nttyb.c_cflag & ALLCTRL)
|
1998-03-01 12:21:12 +08:00
|
|
|
lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.c_cflag);
|
|
|
|
|
|
|
|
#if defined(CS5) && defined(CS8)
|
|
|
|
switch (cur_term->Nttyb.c_cflag & CSIZE) {
|
1999-10-24 12:32:42 +08:00
|
|
|
#if defined(CS5) && (CS5 != 0)
|
1998-03-01 12:21:12 +08:00
|
|
|
case CS5: strcat(buf, "CS5 "); break;
|
1999-10-24 12:32:42 +08:00
|
|
|
#endif
|
|
|
|
#if defined(CS6) && (CS6 != 0)
|
1998-03-01 12:21:12 +08:00
|
|
|
case CS6: strcat(buf, "CS6 "); break;
|
1999-10-24 12:32:42 +08:00
|
|
|
#endif
|
|
|
|
#if defined(CS7) && (CS7 != 0)
|
1998-03-01 12:21:12 +08:00
|
|
|
case CS7: strcat(buf, "CS7 "); break;
|
1999-10-24 12:32:42 +08:00
|
|
|
#endif
|
|
|
|
#if defined(CS8) && (CS8 != 0)
|
1998-03-01 12:21:12 +08:00
|
|
|
case CS8: strcat(buf, "CS8 "); break;
|
1999-10-24 12:32:42 +08:00
|
|
|
#endif
|
1998-03-01 12:21:12 +08:00
|
|
|
default: strcat(buf, "CSIZE? "); break;
|
1997-05-15 12:00:00 +08:00
|
|
|
}
|
1998-03-01 12:21:12 +08:00
|
|
|
#endif
|
1997-05-15 12:00:00 +08:00
|
|
|
|
|
|
|
if (cur_term->Nttyb.c_lflag & ALLLOCAL)
|
1998-03-01 12:21:12 +08:00
|
|
|
lookup_bits(buf, lflags, "lflags", cur_term->Nttyb.c_lflag);
|
1997-05-15 12:00:00 +08:00
|
|
|
|
|
|
|
#else
|
|
|
|
/* reference: ttcompat(4M) on SunOS 4.1 */
|
|
|
|
#ifndef EVENP
|
|
|
|
#define EVENP 0
|
|
|
|
#endif
|
|
|
|
#ifndef LCASE
|
|
|
|
#define LCASE 0
|
|
|
|
#endif
|
|
|
|
#ifndef LLITOUT
|
|
|
|
#define LLITOUT 0
|
|
|
|
#endif
|
|
|
|
#ifndef ODDP
|
|
|
|
#define ODDP 0
|
|
|
|
#endif
|
|
|
|
#ifndef TANDEM
|
|
|
|
#define TANDEM 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
cflags[] =
|
|
|
|
{
|
|
|
|
{CBREAK, "CBREAK"},
|
|
|
|
{CRMOD, "CRMOD"},
|
|
|
|
{ECHO, "ECHO"},
|
|
|
|
{EVENP, "EVENP"},
|
|
|
|
{LCASE, "LCASE"},
|
|
|
|
{LLITOUT, "LLITOUT"},
|
|
|
|
{ODDP, "ODDP"},
|
|
|
|
{RAW, "RAW"},
|
|
|
|
{TANDEM, "TANDEM"},
|
|
|
|
{XTABS, "XTABS"},
|
|
|
|
{0, NULL}
|
|
|
|
#define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
|
1998-03-01 12:21:12 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
buf = _nc_trace_buf(0,
|
|
|
|
8 + sizeof(cflags));
|
1997-05-15 12:00:00 +08:00
|
|
|
|
|
|
|
if (cur_term->Nttyb.sg_flags & ALLCTRL)
|
|
|
|
{
|
1998-03-01 12:21:12 +08:00
|
|
|
lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.sg_flags);
|
1997-05-15 12:00:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
return(buf);
|
|
|
|
}
|
|
|
|
#else
|
1999-10-24 12:32:42 +08:00
|
|
|
char *_nc_tracebits(void) { static char tmp[] = ""; return tmp; }
|
1997-05-15 12:00:00 +08:00
|
|
|
#endif /* TRACE */
|