- * Reset the terminal mode bits to a sensible state. Very useful after
- * a child program dies in raw mode.
- */
-static void
-reset_mode(void)
-{
-#ifdef TERMIOS
- tcgetattr(STDERR_FILENO, &mode);
-#else
- stty(STDERR_FILENO,&mode);
-#endif
-
-#ifdef TERMIOS
-#if defined(VDISCARD) && defined(CDISCARD)
- mode.c_cc[VDISCARD] = CHK(mode.c_cc[VDISCARD], CDISCARD);
-#endif
- mode.c_cc[VEOF] = CHK(mode.c_cc[VEOF], CEOF);
- mode.c_cc[VERASE] = CHK(mode.c_cc[VERASE], CERASE);
-#if defined(VFLUSH) && defined(CFLUSH)
- mode.c_cc[VFLUSH] = CHK(mode.c_cc[VFLUSH], CFLUSH);
-#endif
- mode.c_cc[VINTR] = CHK(mode.c_cc[VINTR], CINTR);
- mode.c_cc[VKILL] = CHK(mode.c_cc[VKILL], CKILL);
-#if defined(VLNEXT) && defined(CLNEXT)
- mode.c_cc[VLNEXT] = CHK(mode.c_cc[VLNEXT], CLNEXT);
-#endif
- mode.c_cc[VQUIT] = CHK(mode.c_cc[VQUIT], CQUIT);
-#if defined(VREPRINT) && defined(CRPRNT)
- mode.c_cc[VREPRINT] = CHK(mode.c_cc[VREPRINT], CRPRNT);
-#endif
-#if defined(VSTART) && defined(CSTART)
- mode.c_cc[VSTART] = CHK(mode.c_cc[VSTART], CSTART);
-#endif
-#if defined(VSTOP) && defined(CSTOP)
- mode.c_cc[VSTOP] = CHK(mode.c_cc[VSTOP], CSTOP);
-#endif
-#if defined(VSUSP) && defined(CSUSP)
- mode.c_cc[VSUSP] = CHK(mode.c_cc[VSUSP], CSUSP);
-#endif
-#if defined(VWERASE) && defined(CWERASE)
- mode.c_cc[VWERASE] = CHK(mode.c_cc[VWERASE], CWERASE);
-#endif
-
- mode.c_iflag &= ~(IGNBRK | PARMRK | INPCK | ISTRIP | INLCR | IGNCR
-#ifdef IUCLC
- | IUCLC
-#endif
-#ifdef IXANY
- | IXANY
-#endif
- | IXOFF);
-
- mode.c_iflag |= (BRKINT | IGNPAR | ICRNL | IXON
-#ifdef IMAXBEL
- | IMAXBEL
-#endif
- );
-
- mode.c_oflag &= ~(0
-#ifdef OLCUC
- | OLCUC
-#endif
-#ifdef OCRNL
- | OCRNL
-#endif
-#ifdef ONOCR
- | ONOCR
-#endif
-#ifdef ONLRET
- | ONLRET
-#endif
-#ifdef OFILL
- | OFILL
-#endif
-#ifdef OFDEL
- | OFDEL
-#endif
-#ifdef NLDLY
- | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY
-#endif
- );
-
- mode.c_oflag |= (OPOST
-#ifdef ONLCR
- | ONLCR
-#endif
- );
-
- mode.c_cflag &= ~(CSIZE | CSTOPB | PARENB | PARODD | CLOCAL);
- mode.c_cflag |= (CS8 | CREAD);
- mode.c_lflag &= ~(ECHONL | NOFLSH
-#ifdef TOSTOP
- | TOSTOP
-#endif
-#ifdef ECHOPTR
- | ECHOPRT
-#endif
-#ifdef XCASE
- | XCASE
-#endif
- );
-
- mode.c_lflag |= (ISIG | ICANON | ECHO | ECHOE | ECHOK
-#ifdef ECHOCTL
- | ECHOCTL
-#endif
-#ifdef ECHOKE
- | ECHOKE
-#endif
- );
-#endif
-
-#ifdef TERMIOS
- tcsetattr(STDERR_FILENO, TCSADRAIN, &mode);
-#else
- stty(STDERR_FILENO, &mode);
-#endif
-}
-
-/*
- * Determine the erase, interrupt, and kill characters from the termcap
- * entry and command line and update their values in 'mode'.
- */
-static void
-set_control_chars(void)
-{
-#ifdef __OBSOLETE__
- /*
- * 4.4BSD logic for setting erasechar, left here in case there is some
- * necessary subtlety missed in the production code below that really
- * needs to be added someday (in particular, I don't understand what
- * the second if-statement involving the os flag is doing, and it makes
- * my head hurt when I try and follow out all the combinations).
- */
- char *bp, *p, bs_char, buf[1024];
-
- bp = buf;
- p = tgetstr("kb", &bp);
- if (p == 0 || p[1] != '\0')
- p = tgetstr("bc", &bp);
- if (p != 0 && p[1] == '\0')
- bs_char = p[0];
- else if (tgetflag("bs"))
- bs_char = CTRL('h');
- else
- bs_char = 0;
-
- if (terasechar==0 && !tgetflag("os") && mode.c_cc[VERASE] != CERASE) {
- if (tgetflag("bs") || bs_char != 0)
- terasechar = -1;
- }
- if (terasechar < 0)
- terasechar = (bs_char != 0) ? bs_char : CTRL('h');
-#else
- /* the real erasechar logic used now */
- char bs_char = 0;
-
- if (key_backspace != (char *)0)
- bs_char = key_backspace[0];
-
- if (terasechar <= 0)
- terasechar = (bs_char != 0) ? bs_char : CTRL('h');
-#endif /* __OBSOLETE__ */
-
-#ifdef TERMIOS
- if (mode.c_cc[VERASE] == 0 || terasechar != 0)
- mode.c_cc[VERASE] = terasechar ? terasechar : CERASE;
-
- if (mode.c_cc[VINTR] == 0 || intrchar != 0)
- mode.c_cc[VINTR] = intrchar ? intrchar : CINTR;
-
- if (mode.c_cc[VKILL] == 0 || tkillchar != 0)
- mode.c_cc[VKILL] = tkillchar ? tkillchar : CKILL;
-#endif
-}
-
-/*
- * Set up various conversions in 'mode', including parity, tabs, returns,
- * echo, and case, according to the termcap entry. If the program we're
- * running was named with a leading upper-case character, map external
- * uppercase to internal lowercase.