summaryrefslogtreecommitdiffstats
path: root/lib/libcurses/lib_raw.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>1997-11-26 04:01:02 +0000
committermillert <millert@openbsd.org>1997-11-26 04:01:02 +0000
commit010b00ebb3f4bdd576ec41ca1d5d0a8994e8fe5b (patch)
tree5ee5e7213ad9b412a927de7effdcb7c8ce4b489e /lib/libcurses/lib_raw.c
parentlibform from ncurses 4.1. Post 4.1 patches to be applied in a separate commit. (diff)
downloadwireguard-openbsd-010b00ebb3f4bdd576ec41ca1d5d0a8994e8fe5b.tar.xz
wireguard-openbsd-010b00ebb3f4bdd576ec41ca1d5d0a8994e8fe5b.zip
ncurses 4.1 + changes to work with our terminfo libs (instead of
the ncurses ones). Changes are #ifdef EXTERN_TERMINFO. Post 4.1 patches will be applied in a separate commit.
Diffstat (limited to 'lib/libcurses/lib_raw.c')
-rw-r--r--lib/libcurses/lib_raw.c413
1 files changed, 263 insertions, 150 deletions
diff --git a/lib/libcurses/lib_raw.c b/lib/libcurses/lib_raw.c
index 1971f9651bf..4cd1b953678 100644
--- a/lib/libcurses/lib_raw.c
+++ b/lib/libcurses/lib_raw.c
@@ -38,136 +38,274 @@
*
*/
-#include "curses.priv.h"
-#include "term.h" /* cur_term */
+#include <curses.priv.h>
+#include <term.h> /* cur_term */
-/*
- * COOKED_INPUT defines the collection of input mode bits to be
- * cleared when entering raw mode, then re-set by noraw().
- *
- * We used to clear ISTRIP and INPCK when going to raw mode. Keith
- * Bostic says that's wrong, because those are hardware bits that the
- * user has to get right in his/her initial environment -- he says
- * curses can't do any good by clearing these, and may do harm. In
- * 1995's world of 8N1 connections over error-correcting modems, all
- * the parity-check stuff is pretty nearly irrelevant anyway.
- *
- * What's supposed to happen when noraw() executes has never been very
- * well-defined. Yes, it should reset ISIG/ICANON/OPOST (historical
- * practice is for it to attempt to take the driver back to cooked
- * mode, rather going to some half-baked cbreak-like intermediate
- * level).
- *
- * We make a design choice here to turn off CR/LF translation a la BSD
- * when raw() is enabled, on the theory that a programmer requesting
- * raw() ideally wants an 8-bit data stream that's been messed with as
- * little as possible. The man pages document this.
- *
- * We originally opted for the simplest way to handle noraw(); just set all
- * the flags we cleared. Unfortunately, having noraw() set IGNCR
- * turned out to be too painful. So raw() now clears the COOKED_INPUT
- * flags, but also clears (ICRNL|INLCR|IGNCR) which noraw() doesn't
- * restore.
- *
- * Unfortunately, this means noraw() may still force some COOKED_INPUT
- * flags on that the user had initially cleared via stty. It'll all
- * come out in the wash when endwin() restores the user's original
- * input bits (we hope...)
- *
- */
-#define COOKED_INPUT (IXON|IGNBRK|BRKINT|PARMRK)
+MODULE_ID("Id: lib_raw.c,v 1.16 1997/02/02 00:02:32 tom Exp $")
+
+#ifdef SVR4_TERMIO
+#define _POSIX_SOURCE
+#endif
+
+#if HAVE_SYS_TERMIO_H
+#include <sys/termio.h> /* needed for ISC */
+#endif
+
+/* may be undefined if we're using termio.h */
+#ifndef TOSTOP
+#define TOSTOP 0
+#endif
+#ifndef IEXTEN
+#define IEXTEN 0
+#endif
+
+#define COOKED_INPUT (IXON|BRKINT|PARMRK)
+
+#ifdef TRACE
+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;}
+
+#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"},
+ {CSIZE, "CSIZE"},
+ {CSTOPB, "CSTOPB"},
+ {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"},
+#if TOSTOP != 0
+ {TOSTOP, "TOSTOP"},
+#endif
+#if IEXTEN != 0
+ {IEXTEN, "IEXTEN"},
+#endif
+ {0, NULL}
+#define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
+ },
+ *sp;
+
+ 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,"} ");
+ }
+
+ 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,"} ");
+ }
+
+ 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,"} ");
+ }
+
+ 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,"} ");
+ }
+
+#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)
+ },
+ *sp;
+
+ 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,"} ");
+ }
+
+#endif
+ return(buf);
+}
+
+#define BEFORE(N) if (_nc_tracing&TRACE_BITS) _tracef("%s before bits: %s", N, _tracebits())
+#define AFTER(N) if (_nc_tracing&TRACE_BITS) _tracef("%s after bits: %s", N, _tracebits())
+#else
+#define BEFORE(s)
+#define AFTER(s)
+#endif /* TRACE */
int raw(void)
{
- T(("raw() called"));
+ T((T_CALLED("raw()")));
SP->_raw = TRUE;
SP->_cbreak = TRUE;
#ifdef TERMIOS
- cur_term->Nttyb.c_lflag &= ~(ICANON|ISIG|IEXTEN);
- cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT|ICRNL|INLCR|IGNCR);
- cur_term->Nttyb.c_oflag &= ~(OPOST);
+ BEFORE("raw");
+ cur_term->Nttyb.c_lflag &= ~(ICANON|ISIG);
+ cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT);
cur_term->Nttyb.c_cc[VMIN] = 1;
cur_term->Nttyb.c_cc[VTIME] = 0;
- if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
- return ERR;
- else
- return OK;
+ AFTER("raw");
#else
cur_term->Nttyb.sg_flags |= RAW;
- stty(cur_term->Filedes, &cur_term->Nttyb);
- return OK;
#endif
+ if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
+ returnCode(ERR);
+ returnCode(OK);
}
int cbreak(void)
{
- T(("cbreak() called"));
+ T((T_CALLED("cbreak()")));
SP->_cbreak = TRUE;
#ifdef TERMIOS
- cur_term->Nttyb.c_lflag &= ~ICANON;
+ BEFORE("cbreak");
+ cur_term->Nttyb.c_lflag &= ~ICANON;
+ cur_term->Nttyb.c_iflag &= ~ICRNL;
cur_term->Nttyb.c_lflag |= ISIG;
cur_term->Nttyb.c_cc[VMIN] = 1;
cur_term->Nttyb.c_cc[VTIME] = 0;
- if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
- return ERR;
- else
- return OK;
+ AFTER("cbreak");
#else
cur_term->Nttyb.sg_flags |= CBREAK;
- stty(cur_term->Filedes, &cur_term->Nttyb);
- return OK;
#endif
+ if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
+ returnCode(ERR);
+ returnCode(OK);
}
int echo(void)
{
- T(("echo() called"));
+ T((T_CALLED("echo()")));
SP->_echo = TRUE;
-
-#ifdef TERMIOS
- cur_term->Nttyb.c_lflag |= ECHO;
- if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
- return ERR;
- else
- return OK;
-#else
- cur_term->Nttyb.sg_flags |= ECHO;
- stty(cur_term->Filedes, &cur_term->Nttyb);
- return OK;
-#endif
+
+ returnCode(OK);
}
int nl(void)
{
- T(("nl() called"));
+ T((T_CALLED("nl()")));
SP->_nl = TRUE;
-#ifdef TERMIOS
- /* the code used to set IXON|IXOFF here, Ghod knows why... */
- cur_term->Nttyb.c_iflag |= ICRNL;
- cur_term->Nttyb.c_oflag |= OPOST|ONLCR;
- if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
- return ERR;
- else
- return OK;
-#else
- cur_term->Nttyb.sg_flags |= CRMOD;
- stty(cur_term->Filedes, &cur_term->Nttyb);
- return OK;
-#endif
+ returnCode(OK);
}
int qiflush(void)
{
- T(("qiflush() called"));
+ T((T_CALLED("qiflush()")));
/*
* Note: this implementation may be wrong. See the comment under
@@ -175,107 +313,79 @@ int qiflush(void)
*/
#ifdef TERMIOS
+ BEFORE("qiflush");
cur_term->Nttyb.c_lflag &= ~(NOFLSH);
- if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
- return ERR;
+ AFTER("qiflush");
+ if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
+ returnCode(ERR);
else
- return OK;
+ returnCode(OK);
#else
- return ERR;
+ returnCode(ERR);
#endif
}
int noraw(void)
{
- T(("noraw() called"));
+ T((T_CALLED("noraw()")));
SP->_raw = FALSE;
SP->_cbreak = FALSE;
#ifdef TERMIOS
- cur_term->Nttyb.c_lflag |= ISIG|ICANON|IEXTEN;
+ BEFORE("noraw");
+ cur_term->Nttyb.c_lflag |= ISIG|ICANON;
cur_term->Nttyb.c_iflag |= COOKED_INPUT;
- cur_term->Nttyb.c_oflag |= OPOST;
- if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
- return ERR;
- else
- return OK;
+ AFTER("noraw");
#else
cur_term->Nttyb.sg_flags &= ~(RAW|CBREAK);
- stty(cur_term->Filedes, &cur_term->Nttyb);
- return OK;
#endif
-
+ if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
+ returnCode(ERR);
+ returnCode(OK);
}
int nocbreak(void)
{
- T(("nocbreak() called"));
+ T((T_CALLED("nocbreak()")));
SP->_cbreak = 0;
-
+
#ifdef TERMIOS
+ BEFORE("nocbreak");
cur_term->Nttyb.c_lflag |= ICANON;
- if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
- return ERR;
- else
- return OK;
-#else
+ cur_term->Nttyb.c_iflag |= ICRNL;
+ AFTER("nocbreak");
+#else
cur_term->Nttyb.sg_flags &= ~CBREAK;
- stty(cur_term->Filedes, &cur_term->Nttyb);
- return OK;
#endif
+ if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
+ returnCode(ERR);
+ returnCode(OK);
}
int noecho(void)
{
- T(("noecho() called"));
-
+ T((T_CALLED("noecho()")));
SP->_echo = FALSE;
-
-#ifdef TERMIOS
- /*
- * Turn off ECHONL to avoid having \n still be echoed when
- * cooked mode is in effect (that is, ICANON is on).
- */
- cur_term->Nttyb.c_lflag &= ~(ECHO|ECHONL);
- if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
- return ERR;
- else
- return OK;
-#else
- cur_term->Nttyb.sg_flags &= ~ECHO;
- stty(cur_term->Filedes, &cur_term->Nttyb);
- return OK;
-#endif
+ returnCode(OK);
}
int nonl(void)
{
- T(("nonl() called"));
+ T((T_CALLED("nonl()")));
SP->_nl = FALSE;
-
-#ifdef TERMIOS
- cur_term->Nttyb.c_iflag &= ~ICRNL;
- cur_term->Nttyb.c_oflag &= ~ONLCR;
- if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
- return ERR;
- else
- return OK;
-#else
- cur_term->Nttyb.sg_flags &= ~CRMOD;
- stty(cur_term->Filedes, &cur_term->Nttyb);
- return OK;
-#endif
+
+ returnCode(OK);
}
int noqiflush(void)
{
- T(("noqiflush() called"));
+ T((T_CALLED("noqiflush()")));
/*
* Note: this implementation may be wrong. See the comment under
@@ -283,19 +393,21 @@ int noqiflush(void)
*/
#ifdef TERMIOS
+ BEFORE("noqiflush");
cur_term->Nttyb.c_lflag |= NOFLSH;
- if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
- return ERR;
+ AFTER("noqiflush");
+ if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
+ returnCode(ERR);
else
- return OK;
+ returnCode(OK);
#else
- return ERR;
+ returnCode(ERR);
#endif
}
-int intrflush(WINDOW *win, bool flag)
+int intrflush(WINDOW *win GCC_UNUSED, bool flag)
{
- T(("intrflush() called"));
+ T((T_CALLED("intrflush(%d)"), flag));
/*
* This call does the same thing as the qiflush()/noqiflush()
@@ -307,16 +419,17 @@ int intrflush(WINDOW *win, bool flag)
*/
#ifdef TERMIOS
+ BEFORE("intrflush");
if (flag)
cur_term->Nttyb.c_lflag &= ~(NOFLSH);
else
cur_term->Nttyb.c_lflag |= (NOFLSH);
- if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
- return ERR;
+ AFTER("intrflush");
+ if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
+ returnCode(ERR);
else
- return OK;
+ returnCode(OK);
#else
- return ERR;
+ returnCode(ERR);
#endif
}
-