changed to remember and restore TSTP handler, and also to resnapshot tty state when...
authorMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Sat, 5 Jun 1993 07:12:01 +0000 (23:12 -0800)
committerMarc Teitelbaum <marc@ucbvax.Berkeley.EDU>
Sat, 5 Jun 1993 07:12:01 +0000 (23:12 -0800)
SCCS-vsn: lib/libcurses/curses.h 5.38
SCCS-vsn: lib/libcurses/addbytes.c 5.22
SCCS-vsn: lib/libcurses/cr_put.c 5.21
SCCS-vsn: lib/libcurses/scroll.c 5.13
SCCS-vsn: lib/libcurses/tstp.c 5.9
SCCS-vsn: lib/libcurses/initscr.c 5.16
SCCS-vsn: lib/libcurses/tty.c 5.17

usr/src/lib/libcurses/addbytes.c
usr/src/lib/libcurses/cr_put.c
usr/src/lib/libcurses/curses.h
usr/src/lib/libcurses/initscr.c
usr/src/lib/libcurses/scroll.c
usr/src/lib/libcurses/tstp.c
usr/src/lib/libcurses/tty.c

index 15a13b4..4e74443 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)addbytes.c 5.21 (Berkeley) %G%";
+static char sccsid[] = "@(#)addbytes.c 5.22 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <curses.h>
 #endif /* not lint */
 
 #include <curses.h>
@@ -114,7 +114,7 @@ newline:                    if (y == win->maxy - 1) {
                        SYNCH_OUT;
                        wclrtoeol(win);
                        SYNCH_IN;
                        SYNCH_OUT;
                        wclrtoeol(win);
                        SYNCH_IN;
-                       if (__orig_termios.c_oflag & ONLCR)
+                       if (__baset.c_oflag & ONLCR)
                                x = 0;
                        goto newline;
                case '\r':
                                x = 0;
                        goto newline;
                case '\r':
index 5ca6cea..6e88284 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)cr_put.c   5.20 (Berkeley) %G%";
+static char sccsid[] = "@(#)cr_put.c   5.21 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <curses.h>
 #endif /* not lint */
 
 #include <curses.h>
@@ -257,7 +257,7 @@ plod(cnt, in_refresh)
         * If we will later need a \n which will turn into a \r\n by the
         * system or the terminal, then don't bother to try to \r.
         */
         * If we will later need a \n which will turn into a \r\n by the
         * system or the terminal, then don't bother to try to \r.
         */
-       if ((!(__orig_termios.c_oflag & ONLCR) ||
+       if ((!(__baset.c_oflag & ONLCR) ||
            !__pfast) && outline < destline)
                goto dontcr;
 
            !__pfast) && outline < destline)
                goto dontcr;
 
@@ -299,7 +299,7 @@ dontcr:     while (outline < destline) {
                        plodput('\n');
                if (plodcnt < 0)
                        goto out;
                        plodput('\n');
                if (plodcnt < 0)
                        goto out;
-               if (!(__orig_termios.c_oflag & ONLCR) || __pfast == 0)
+               if (!(__baset.c_oflag & ONLCR) || __pfast == 0)
                        outcol = 0;
        }
        if (BT)
                        outcol = 0;
        }
        if (BT)
index 9c0af3d..d2d182b 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)curses.h    5.37 (Berkeley) %G%
+ *     @(#)curses.h    5.38 (Berkeley) %G%
  */
 
 #ifndef _CURSES_H_
  */
 
 #ifndef _CURSES_H_
 #define        _putchar(c)     __cputchar(c)
 
 /* Old-style terminal modes access. */
 #define        _putchar(c)     __cputchar(c)
 
 /* Old-style terminal modes access. */
-#define        baudrate()      (cfgetospeed(&__orig_termios))
+#define        baudrate()      (cfgetospeed(&__baset))
 #define        crmode()        cbreak()
 #define        crmode()        cbreak()
-#define        erasechar()     (__orig_termios.c_cc[VERASE])
-#define        killchar()      (__orig_termios.c_cc[VKILL])
+#define        erasechar()     (__baset.c_cc[VERASE])
+#define        killchar()      (__baset.c_cc[VKILL])
 #define        nocrmode()      nocbreak()
 #define        nocrmode()      nocbreak()
-#define        ospeed          (cfgetospeed(&__orig_termios))
+#define        ospeed          (cfgetospeed(&__baset))
 #endif /* _CURSES_PRIVATE */
 
 extern char     GT;                    /* Gtty indicates tabs. */
 #endif /* _CURSES_PRIVATE */
 
 extern char     GT;                    /* Gtty indicates tabs. */
@@ -126,7 +126,10 @@ typedef struct __window {          /* Window structure. */
 extern WINDOW  *curscr;                /* Current screen. */
 extern WINDOW  *stdscr;                /* Standard screen. */
 
 extern WINDOW  *curscr;                /* Current screen. */
 extern WINDOW  *stdscr;                /* Standard screen. */
 
-extern struct termios __orig_termios;  /* Original terminal modes. */
+extern struct termios __orig_termios;  /* Terminal state before curses */
+extern struct termios __baset;         /* Our base terminal state */
+extern int __tcaction;                 /* Controls whether tcsetattr will
+                                          ignore hardware settings */
 
 extern int      COLS;                  /* Columns on the screen. */
 extern int      LINES;                 /* Lines on the screen. */
 
 extern int      COLS;                  /* Columns on the screen. */
 extern int      LINES;                 /* Lines on the screen. */
@@ -273,6 +276,8 @@ void         __CTRACE __P((const char *, ...));
 u_int   __hash __P((char *, int));
 void    __id_subwins __P((WINDOW *));
 int     __mvcur __P((int, int, int, int, int));
 u_int   __hash __P((char *, int));
 void    __id_subwins __P((WINDOW *));
 int     __mvcur __P((int, int, int, int, int));
+void    __restore_stophandler __P((void));
+void    __set_stophandler __P((void));
 void    __set_subwin __P((WINDOW *, WINDOW *));
 void    __startwin __P((void));
 void    __stop_signal_handler __P((int));
 void    __set_subwin __P((WINDOW *, WINDOW *));
 void    __startwin __P((void));
 void    __stop_signal_handler __P((int));
index 0a18bfa..5ac6b34 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)initscr.c  5.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)initscr.c  5.16 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <curses.h>
 #endif /* not lint */
 
 #include <curses.h>
@@ -57,7 +57,7 @@ initscr()
                return (NULL);
        }
 
                return (NULL);
        }
 
-       (void)signal(SIGTSTP, __stop_signal_handler);
+       __set_stophandler();
 
 #ifdef DEBUG
        __CTRACE("initscr: LINES = %d, COLS = %d\n", LINES, COLS);
 
 #ifdef DEBUG
        __CTRACE("initscr: LINES = %d, COLS = %d\n", LINES, COLS);
index e3fb517..f9d2ce6 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)scroll.c   5.12 (Berkeley) %G%";
+static char sccsid[] = "@(#)scroll.c   5.13 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <curses.h>
 #endif /* not lint */
 
 #include <curses.h>
@@ -36,7 +36,7 @@ scroll(win)
 
        if (win == curscr) {
                putchar('\n');
 
        if (win == curscr) {
                putchar('\n');
-               if (__orig_termios.c_oflag & ONLCR)
+               if (__baset.c_oflag & ONLCR)
                        win->curx = 0;
 #ifdef DEBUG
                __CTRACE("scroll: win == curscr\n");
                        win->curx = 0;
 #ifdef DEBUG
                __CTRACE("scroll: win == curscr\n");
index c79f6aa..f69720a 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)tstp.c     5.8 (Berkeley) %G%";
+static char sccsid[] = "@(#)tstp.c     5.9 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <curses.h>
 #endif /* not lint */
 
 #include <curses.h>
@@ -15,6 +15,7 @@ static char sccsid[] = "@(#)tstp.c    5.8 (Berkeley) %G%";
 #include <termios.h>
 #include <unistd.h>
 
 #include <termios.h>
 #include <unistd.h>
 
+
 /*
  * stop_signal_handler --
  *     Handle stop signals.
 /*
  * stop_signal_handler --
  *     Handle stop signals.
@@ -26,7 +27,7 @@ __stop_signal_handler(signo)
        struct termios save;
        sigset_t oset, set;
 
        struct termios save;
        sigset_t oset, set;
 
-       /* Get the current terminal state. */
+       /* Get the current terminal state (which the user may have changed). */
        if (tcgetattr(STDIN_FILENO, &save))
                return;
 
        if (tcgetattr(STDIN_FILENO, &save))
                return;
 
@@ -50,16 +51,19 @@ __stop_signal_handler(signo)
        (void)sigprocmask(SIG_UNBLOCK, &set, NULL);
 
        /* Stop ourselves. */
        (void)sigprocmask(SIG_UNBLOCK, &set, NULL);
 
        /* Stop ourselves. */
-       (void)signal(SIGTSTP, SIG_DFL);
+       __restore_stophandler();
        (void)kill(0, SIGTSTP);
 
        /* Time passes ... */
 
        /* Reset the curses SIGTSTP signal handler. */
        (void)kill(0, SIGTSTP);
 
        /* Time passes ... */
 
        /* Reset the curses SIGTSTP signal handler. */
-       (void)signal(SIGTSTP, __stop_signal_handler);
+       __set_stophandler();
+
+       /* save the new "default" terminal state */
+       (void)tcgetattr(STDIN_FILENO, &__orig_termios);
 
 
-       /* Reset the terminal state its mode when we stopped. */
-       (void)tcsetattr(STDIN_FILENO, TCSADRAIN, &save);
+       /* Reset the terminal state to the mode just before we stopped. */
+       (void)tcsetattr(STDIN_FILENO, __tcaction, &save);
 
        /* Restart the screen. */
        __startwin();
 
        /* Restart the screen. */
        __startwin();
@@ -70,3 +74,23 @@ __stop_signal_handler(signo)
        /* Reset the signals. */
        (void)sigprocmask(SIG_SETMASK, &oset, NULL);
 }
        /* Reset the signals. */
        (void)sigprocmask(SIG_SETMASK, &oset, NULL);
 }
+
+static void (*otstpfn)() = SIG_DFL;
+
+/*
+ * Set the TSTP handler.
+ */
+void
+__set_stophandler()
+{
+       otstpfn = signal(SIGTSTP, __stop_signal_handler);
+}
+
+/*
+ * Restore the TSTP handler.
+ */
+void
+__restore_stophandler()
+{
+       (void)signal(SIGTSTP, otstpfn);
+}
index 5337b2c..8a49a93 100644 (file)
@@ -6,7 +6,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)tty.c      5.16 (Berkeley) %G%";
+static char sccsid[] = "@(#)tty.c      5.17 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/ioctl.h>
 #endif /* not lint */
 
 #include <sys/ioctl.h>
@@ -23,13 +23,15 @@ static char sccsid[] = "@(#)tty.c   5.16 (Berkeley) %G%";
  * See also the comments in getterm().
  */
 #ifdef TCSASOFT
  * See also the comments in getterm().
  */
 #ifdef TCSASOFT
-#define        TCACTION (TCSASOFT | TCSADRAIN)         /* ignore hardware settings */
+int __tcaction = TCSASOFT | TCSADRAIN;         /* ignore hardware settings */
 #else
 #else
-#define        TCACTION  TCSADRAIN
+int __tcaction = TCSADRAIN;
 #endif
 
 #endif
 
-struct termios __orig_termios;
-static struct termios baset, cbreakt, rawt, *curt;
+/* was, pfast = rand() % HARDTABS; */
+
+struct termios __orig_termios, __baset;
+static struct termios cbreakt, rawt, *curt;
 static int useraw;
 
 #ifndef        OXTABS
 static int useraw;
 
 #ifndef        OXTABS
@@ -52,11 +54,11 @@ gettmode()
        if (tcgetattr(STDIN_FILENO, &__orig_termios))
                return (ERR);
 
        if (tcgetattr(STDIN_FILENO, &__orig_termios))
                return (ERR);
 
-       GT = (__orig_termios.c_oflag & OXTABS) == 0;
-       NONL = (__orig_termios.c_oflag & ONLCR) == 0;
+       __baset = __orig_termios;
+       __baset.c_oflag &= ~OXTABS;
 
 
-       baset = __orig_termios;
-       baset.c_oflag &= ~OXTABS;
+       GT = 0;         /* historical. was used before we wired OXTABS off */
+       NONL = (__baset.c_oflag & ONLCR) == 0;
 
        /*
         * XXX
 
        /*
         * XXX
@@ -65,7 +67,7 @@ gettmode()
         * as the VEOL element.  This means that, if VEOF was ^D, the
         * default VMIN is 4.  Majorly stupid.
         */
         * as the VEOL element.  This means that, if VEOF was ^D, the
         * default VMIN is 4.  Majorly stupid.
         */
-       cbreakt = baset;
+       cbreakt = __baset;
        cbreakt.c_lflag &= ~ICANON;
        cbreakt.c_cc[VMIN] = 1;
        cbreakt.c_cc[VTIME] = 0;
        cbreakt.c_lflag &= ~ICANON;
        cbreakt.c_cc[VMIN] = 1;
        cbreakt.c_cc[VTIME] = 0;
@@ -88,8 +90,8 @@ gettmode()
        rawt.c_cflag |= CS8;
 #endif
 
        rawt.c_cflag |= CS8;
 #endif
 
-       curt = &baset;
-       return (tcsetattr(STDIN_FILENO, TCACTION, &baset) ? ERR : OK);
+       curt = &__baset;
+       return (tcsetattr(STDIN_FILENO, __tcaction, &__baset) ? ERR : OK);
 }
 
 int
 }
 
 int
@@ -97,15 +99,15 @@ raw()
 {
        useraw = __pfast = __rawmode = 1;
        curt = &rawt;
 {
        useraw = __pfast = __rawmode = 1;
        curt = &rawt;
-       return (tcsetattr(STDIN_FILENO, TCACTION, &rawt));
+       return (tcsetattr(STDIN_FILENO, __tcaction, &rawt));
 }
 
 int
 noraw()
 {
        useraw = __pfast = __rawmode = 0;
 }
 
 int
 noraw()
 {
        useraw = __pfast = __rawmode = 0;
-       curt = &baset;
-       return (tcsetattr(STDIN_FILENO, TCACTION, &baset));
+       curt = &__baset;
+       return (tcsetattr(STDIN_FILENO, __tcaction, &__baset));
 }
 
 int
 }
 
 int
@@ -114,7 +116,7 @@ cbreak()
 
        __rawmode = 1;
        curt = useraw ? &rawt : &cbreakt;
 
        __rawmode = 1;
        curt = useraw ? &rawt : &cbreakt;
-       return (tcsetattr(STDIN_FILENO, TCACTION, curt));
+       return (tcsetattr(STDIN_FILENO, __tcaction, curt));
 }
 
 int
 }
 
 int
@@ -122,8 +124,8 @@ nocbreak()
 {
 
        __rawmode = 0;
 {
 
        __rawmode = 0;
-       curt = useraw ? &rawt : &baset;
-       return (tcsetattr(STDIN_FILENO, TCACTION, curt));
+       curt = useraw ? &rawt : &__baset;
+       return (tcsetattr(STDIN_FILENO, __tcaction, curt));
 }
        
 int
 }
        
 int
@@ -131,10 +133,10 @@ echo()
 {
        rawt.c_lflag |= ECHO;
        cbreakt.c_lflag |= ECHO;
 {
        rawt.c_lflag |= ECHO;
        cbreakt.c_lflag |= ECHO;
-       baset.c_lflag |= ECHO;
+       __baset.c_lflag |= ECHO;
        
        __echoit = 1;
        
        __echoit = 1;
-       return (tcsetattr(STDIN_FILENO, TCACTION, curt));
+       return (tcsetattr(STDIN_FILENO, __tcaction, curt));
 }
 
 int
 }
 
 int
@@ -142,10 +144,10 @@ noecho()
 {
        rawt.c_lflag &= ~ECHO;
        cbreakt.c_lflag &= ~ECHO;
 {
        rawt.c_lflag &= ~ECHO;
        cbreakt.c_lflag &= ~ECHO;
-       baset.c_lflag &= ~ECHO;
+       __baset.c_lflag &= ~ECHO;
        
        __echoit = 0;
        
        __echoit = 0;
-       return (tcsetattr(STDIN_FILENO, TCACTION, curt));
+       return (tcsetattr(STDIN_FILENO, __tcaction, curt));
 }
 
 int
 }
 
 int
@@ -155,11 +157,11 @@ nl()
        rawt.c_oflag |= ONLCR;
        cbreakt.c_iflag |= ICRNL;
        cbreakt.c_oflag |= ONLCR;
        rawt.c_oflag |= ONLCR;
        cbreakt.c_iflag |= ICRNL;
        cbreakt.c_oflag |= ONLCR;
-       baset.c_iflag |= ICRNL;
-       baset.c_oflag |= ONLCR;
+       __baset.c_iflag |= ICRNL;
+       __baset.c_oflag |= ONLCR;
 
        __pfast = __rawmode;
 
        __pfast = __rawmode;
-       return (tcsetattr(STDIN_FILENO, TCACTION, curt));
+       return (tcsetattr(STDIN_FILENO, __tcaction, curt));
 }
 
 int
 }
 
 int
@@ -169,11 +171,11 @@ nonl()
        rawt.c_oflag &= ~ONLCR;
        cbreakt.c_iflag &= ~ICRNL;
        cbreakt.c_oflag &= ~ONLCR;
        rawt.c_oflag &= ~ONLCR;
        cbreakt.c_iflag &= ~ICRNL;
        cbreakt.c_oflag &= ~ONLCR;
-       baset.c_iflag &= ~ICRNL;
-       baset.c_oflag &= ~ONLCR;
+       __baset.c_iflag &= ~ICRNL;
+       __baset.c_oflag &= ~ONLCR;
 
        __pfast = 1;
 
        __pfast = 1;
-       return (tcsetattr(STDIN_FILENO, TCACTION, curt));
+       return (tcsetattr(STDIN_FILENO, __tcaction, curt));
 }
 
 void
 }
 
 void
@@ -202,7 +204,7 @@ endwin()
        (void)fflush(stdout);
        (void)setvbuf(stdout, NULL, _IOLBF, 0);
 
        (void)fflush(stdout);
        (void)setvbuf(stdout, NULL, _IOLBF, 0);
 
-       return (tcsetattr(STDIN_FILENO, TCACTION, &__orig_termios));
+       return (tcsetattr(STDIN_FILENO, __tcaction, &__orig_termios));
 }
 
 /*
 }
 
 /*
@@ -220,5 +222,5 @@ savetty()
 int
 resetty()
 {
 int
 resetty()
 {
-       return (tcsetattr(STDIN_FILENO, TCACTION, &savedtty));
+       return (tcsetattr(STDIN_FILENO, __tcaction, &savedtty));
 }
 }