summaryrefslogtreecommitdiffstats
path: root/lib/libcurses/lib_raw.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1997-12-03 05:20:47 +0000
committermillert <millert@openbsd.org>1997-12-03 05:20:47 +0000
commit6f4099fecac342eeff29dd2bf0512f777a62a591 (patch)
tree30035276ed4d5b07245464d724dd101dc9b5efb4 /lib/libcurses/lib_raw.c
parentmerge of ncurses-4.1-971129 (diff)
downloadwireguard-openbsd-6f4099fecac342eeff29dd2bf0512f777a62a591.tar.xz
wireguard-openbsd-6f4099fecac342eeff29dd2bf0512f777a62a591.zip
Merge of ncurses-4.1-971129
Diffstat (limited to 'lib/libcurses/lib_raw.c')
-rw-r--r--lib/libcurses/lib_raw.c158
1 files changed, 64 insertions, 94 deletions
diff --git a/lib/libcurses/lib_raw.c b/lib/libcurses/lib_raw.c
index 4cd1b953678..204d3424227 100644
--- a/lib/libcurses/lib_raw.c
+++ b/lib/libcurses/lib_raw.c
@@ -1,3 +1,5 @@
+/* $OpenBSD: lib_raw.c,v 1.3 1997/12/03 05:21:27 millert Exp $ */
+
/***************************************************************************
* COPYRIGHT NOTICE *
@@ -41,9 +43,9 @@
#include <curses.priv.h>
#include <term.h> /* cur_term */
-MODULE_ID("Id: lib_raw.c,v 1.16 1997/02/02 00:02:32 tom Exp $")
+MODULE_ID("Id: lib_raw.c,v 1.21 1997/11/01 19:05:35 tom Exp $")
-#ifdef SVR4_TERMIO
+#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE)
#define _POSIX_SOURCE
#endif
@@ -62,11 +64,32 @@ MODULE_ID("Id: lib_raw.c,v 1.16 1997/02/02 00:02:32 tom Exp $")
#define COOKED_INPUT (IXON|BRKINT|PARMRK)
#ifdef TRACE
+
+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,"} ");
+}
+
char *_tracebits(void)
/* describe the state of the terminal control bits exactly */
{
-static char buf[BUFSIZ];
-static const struct {unsigned int val; const char *name;}
+char *buf;
+static const BITNAMES
#ifdef TERMIOS
iflags[] =
@@ -95,8 +118,10 @@ cflags[] =
{
{CLOCAL, "CLOCAL"},
{CREAD, "CREAD"},
- {CSIZE, "CSIZE"},
{CSTOPB, "CSTOPB"},
+#if !defined(CS5) || !defined(CS8)
+ {CSIZE, "CSIZE"},
+#endif
{HUPCL, "HUPCL"},
{PARENB, "PARENB"},
{PARODD|PARENB, "PARODD"}, /* concession to readability */
@@ -112,72 +137,41 @@ lflags[] =
{ICANON, "ICANON"},
{ISIG, "ISIG"},
{NOFLSH, "NOFLSH"},
-#if TOSTOP != 0
{TOSTOP, "TOSTOP"},
-#endif
-#if IEXTEN != 0
{IEXTEN, "IEXTEN"},
-#endif
{0, NULL}
#define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
- },
- *sp;
+ };
+
+
+ buf = _nc_trace_buf(0,
+ 8 + sizeof(iflags) +
+ 8 + sizeof(oflags) +
+ 8 + sizeof(cflags) +
+ 8 + sizeof(lflags) +
+ 8);
if (cur_term->Nttyb.c_iflag & ALLIN)
- {
- (void) strcpy(buf, "iflags: {");
- for (sp = iflags; sp->val; sp++)
- if ((cur_term->Nttyb.c_iflag & 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,"} ");
- }
+ lookup_bits(buf, iflags, "iflags", cur_term->Nttyb.c_iflag);
if (cur_term->Nttyb.c_oflag & ALLOUT)
- {
- (void) strcat(buf, "oflags: {");
- for (sp = oflags; sp->val; sp++)
- if ((cur_term->Nttyb.c_oflag & 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,"} ");
- }
+ lookup_bits(buf, oflags, "oflags", cur_term->Nttyb.c_oflag);
if (cur_term->Nttyb.c_cflag & ALLCTRL)
- {
- (void) strcat(buf, "cflags: {");
- for (sp = cflags; sp->val; sp++)
- if ((cur_term->Nttyb.c_cflag & 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,"} ");
+ lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.c_cflag);
+
+#if defined(CS5) && defined(CS8)
+ switch (cur_term->Nttyb.c_cflag & CSIZE) {
+ case CS5: strcat(buf, "CS5 "); break;
+ case CS6: strcat(buf, "CS6 "); break;
+ case CS7: strcat(buf, "CS7 "); break;
+ case CS8: strcat(buf, "CS8 "); break;
+ default: strcat(buf, "CSIZE? "); break;
}
+#endif
if (cur_term->Nttyb.c_lflag & ALLLOCAL)
- {
- (void) strcat(buf, "lflags: {");
- for (sp = lflags; sp->val; sp++)
- if ((cur_term->Nttyb.c_lflag & 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,"} ");
- }
+ lookup_bits(buf, lflags, "lflags", cur_term->Nttyb.c_lflag);
#else
/* reference: ttcompat(4M) on SunOS 4.1 */
@@ -211,21 +205,14 @@ cflags[] =
{XTABS, "XTABS"},
{0, NULL}
#define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
- },
- *sp;
+ };
+
+ buf = _nc_trace_buf(0,
+ 8 + sizeof(cflags));
if (cur_term->Nttyb.sg_flags & ALLCTRL)
{
- (void) strcat(buf, "cflags: {");
- for (sp = cflags; sp->val; sp++)
- if ((cur_term->Nttyb.sg_flags & 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,"} ");
+ lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.sg_flags);
}
#endif
@@ -256,9 +243,7 @@ int raw(void)
#else
cur_term->Nttyb.sg_flags |= RAW;
#endif
- if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
- returnCode(ERR);
- returnCode(OK);
+ returnCode(_nc_set_curterm(&cur_term->Nttyb));
}
int cbreak(void)
@@ -278,9 +263,7 @@ int cbreak(void)
#else
cur_term->Nttyb.sg_flags |= CBREAK;
#endif
- if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
- returnCode(ERR);
- returnCode(OK);
+ returnCode(_nc_set_curterm( &cur_term->Nttyb));
}
int echo(void)
@@ -316,10 +299,7 @@ int qiflush(void)
BEFORE("qiflush");
cur_term->Nttyb.c_lflag &= ~(NOFLSH);
AFTER("qiflush");
- if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
- returnCode(ERR);
- else
- returnCode(OK);
+ returnCode(_nc_set_curterm( &cur_term->Nttyb));
#else
returnCode(ERR);
#endif
@@ -341,9 +321,7 @@ int noraw(void)
#else
cur_term->Nttyb.sg_flags &= ~(RAW|CBREAK);
#endif
- if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
- returnCode(ERR);
- returnCode(OK);
+ returnCode(_nc_set_curterm( &cur_term->Nttyb));
}
@@ -361,9 +339,7 @@ int nocbreak(void)
#else
cur_term->Nttyb.sg_flags &= ~CBREAK;
#endif
- if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
- returnCode(ERR);
- returnCode(OK);
+ returnCode(_nc_set_curterm( &cur_term->Nttyb));
}
int noecho(void)
@@ -396,10 +372,7 @@ int noqiflush(void)
BEFORE("noqiflush");
cur_term->Nttyb.c_lflag |= NOFLSH;
AFTER("noqiflush");
- if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
- returnCode(ERR);
- else
- returnCode(OK);
+ returnCode(_nc_set_curterm( &cur_term->Nttyb));
#else
returnCode(ERR);
#endif
@@ -425,10 +398,7 @@ int intrflush(WINDOW *win GCC_UNUSED, bool flag)
else
cur_term->Nttyb.c_lflag |= (NOFLSH);
AFTER("intrflush");
- if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
- returnCode(ERR);
- else
- returnCode(OK);
+ returnCode(_nc_set_curterm( &cur_term->Nttyb));
#else
returnCode(ERR);
#endif