switch to POSIX tty, old code still supported under OLD_TTY
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Mon, 13 Aug 1990 06:26:13 +0000 (22:26 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Mon, 13 Aug 1990 06:26:13 +0000 (22:26 -0800)
SCCS-vsn: usr.bin/window/wwpty.c 3.19
SCCS-vsn: usr.bin/window/wwsize.c 3.10
SCCS-vsn: usr.bin/window/wwdata.c 3.19
SCCS-vsn: usr.bin/window/main.c 3.42
SCCS-vsn: usr.bin/window/ttgeneric.c 3.46
SCCS-vsn: usr.bin/window/wwsuspend.c 3.14
SCCS-vsn: usr.bin/window/wwtty.c 3.17
SCCS-vsn: usr.bin/window/ttinit.c 3.27
SCCS-vsn: usr.bin/window/wwend.c 3.16
SCCS-vsn: usr.bin/window/win.c 3.25
SCCS-vsn: usr.bin/window/ww.h 3.61
SCCS-vsn: usr.bin/window/wwenviron.c 3.27
SCCS-vsn: usr.bin/window/wwgets.c 3.16
SCCS-vsn: usr.bin/window/wwinit.c 3.40
SCCS-vsn: usr.bin/window/wwiomux.c 3.26

15 files changed:
usr/src/usr.bin/window/main.c
usr/src/usr.bin/window/ttgeneric.c
usr/src/usr.bin/window/ttinit.c
usr/src/usr.bin/window/win.c
usr/src/usr.bin/window/ww.h
usr/src/usr.bin/window/wwdata.c
usr/src/usr.bin/window/wwend.c
usr/src/usr.bin/window/wwenviron.c
usr/src/usr.bin/window/wwgets.c
usr/src/usr.bin/window/wwinit.c
usr/src/usr.bin/window/wwiomux.c
usr/src/usr.bin/window/wwpty.c
usr/src/usr.bin/window/wwsize.c
usr/src/usr.bin/window/wwsuspend.c
usr/src/usr.bin/window/wwtty.c

index a063a1f..152da77 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     3.41 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     3.42 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "defs.h"
 #endif /* not lint */
 
 #include "defs.h"
@@ -93,7 +93,7 @@ char **argv;
                exit(1);
        }
 
                exit(1);
        }
 
-#ifndef POSIX_TTY
+#ifdef OLD_TTY
        if (debug)
                wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
        if (xflag) {
        if (debug)
                wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
        if (xflag) {
@@ -115,7 +115,7 @@ char **argv;
        }
 #endif
        if (debug || xflag)
        }
 #endif
        if (debug || xflag)
-               (void) wwsettty(0, &wwnewtty, &wwoldtty);
+               (void) wwsettty(0, &wwnewtty);
 
        if ((cmdwin = wwopen(wwbaud > 2400 ? WWO_REVERSE : 0, 1, wwncol,
                             0, 0, 0)) == 0) {
 
        if ((cmdwin = wwopen(wwbaud > 2400 ? WWO_REVERSE : 0, 1, wwncol,
                             0, 0, 0)) == 0) {
index 826a92a..2ef2d4e 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ttgeneric.c        3.45 (Berkeley) %G%";
+static char sccsid[] = "@(#)ttgeneric.c        3.46 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -367,15 +367,7 @@ tt_generic()
 {
        gen_PC = tttgetstr("pc");
        PC = gen_PC ? *gen_PC->ts_str : 0;
 {
        gen_PC = tttgetstr("pc");
        PC = gen_PC ? *gen_PC->ts_str : 0;
-#ifndef POSIX_TTY
-       ospeed = wwoldtty.ww_sgttyb.sg_ospeed;
-#else
-#ifdef CBAUD
-       ospeed = wwoldtty.ww_termios.c_cflag & CBAUD;
-#else
-       ospeed = wwoldtty.ww_termios.c_ospeed;  /* XXX */
-#endif
-#endif
+       ospeed = wwospeed;
 
        gen_CM = ttxgetstr("cm");               /* may not work */
        gen_IM = ttxgetstr("im");
 
        gen_CM = ttxgetstr("cm");               /* may not work */
        gen_IM = ttxgetstr("im");
index cdd1762..a5b45e0 100644 (file)
@@ -9,14 +9,11 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ttinit.c   3.26 (Berkeley) %G%";
+static char sccsid[] = "@(#)ttinit.c   3.27 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #include "tt.h"
 #endif /* not lint */
 
 #include "ww.h"
 #include "tt.h"
-#ifdef POSIX_TTY
-#include <sys/ioctl.h>
-#endif
 
 int tt_h19();
 int tt_h29();
 
 int tt_h19();
 int tt_h29();
@@ -47,7 +44,6 @@ ttinit()
        register struct tt_tab *tp;
        register char *p, *q;
        register char *t;
        register struct tt_tab *tp;
        register char *p, *q;
        register char *t;
-       struct winsize winsize;
        int ttflush();
 
        tt_strp = tt_strings;
        int ttflush();
 
        tt_strp = tt_strings;
@@ -90,12 +86,8 @@ ttinit()
                wwerrno = WWE_CANTDO;
                return -1;
        }
                wwerrno = WWE_CANTDO;
                return -1;
        }
-       if (ioctl(0, TIOCGWINSZ, (char *)&winsize) >= 0) {
-               if (winsize.ws_row != 0)
-                       tt.tt_nrow = winsize.ws_row;
-               if (winsize.ws_col != 0)
-                       tt.tt_ncol = winsize.ws_col;
-       }
+       if (wwgetttysize(0, &tt.tt_nrow, &tt.tt_ncol) < 0)
+               return -1;
        tt.tt_scroll_top = 0;
        tt.tt_scroll_bot = tt.tt_nrow - 1;
        tt.tt_flush = ttflush;
        tt.tt_scroll_top = 0;
        tt.tt_scroll_bot = tt.tt_nrow - 1;
        tt.tt_flush = ttflush;
index 5dc3a0d..54c49da 100644 (file)
@@ -9,14 +9,11 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)win.c      3.24 (Berkeley) %G%";
+static char sccsid[] = "@(#)win.c      3.25 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "defs.h"
 #include "char.h"
 #endif /* not lint */
 
 #include "defs.h"
 #include "char.h"
-#ifdef POSIX_TTY
-#include <sys/ioctl.h>
-#endif
 
 /*
  * Higher level routines for dealing with windows.
 
 /*
  * Higher level routines for dealing with windows.
@@ -278,17 +275,19 @@ register struct ww *w;
 stopwin(w)
        register struct ww *w;
 {
 stopwin(w)
        register struct ww *w;
 {
-       w->ww_stopped = 1;
-       if (w->ww_pty >= 0 && w->ww_ispty)
-               (void) ioctl(w->ww_pty, TIOCSTOP, (char *)0);
+       if (w->ww_pty >= 0 && w->ww_ispty && wwstoptty(w->ww_pty) < 0)
+               error("Can't stop output: %s.", wwerror());
+       else
+               w->ww_stopped = 1;
 }
 
 startwin(w)
        register struct ww *w;
 {
 }
 
 startwin(w)
        register struct ww *w;
 {
-       w->ww_stopped = 0;
-       if (w->ww_pty >= 0 && w->ww_ispty)
-               (void) ioctl(w->ww_pty, TIOCSTART, (char *)0);
+       if (w->ww_pty >= 0 && w->ww_ispty && wwstarttty(w->ww_pty) < 0)
+               error("Can't start output: %s.", wwerror());
+       else
+               w->ww_stopped = 0;
 }
 
 sizewin(w, nrow, ncol)
 }
 
 sizewin(w, nrow, ncol)
index 523ae46..cefc6b1 100644 (file)
@@ -7,10 +7,10 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)ww.h        3.60 (Berkeley) %G%
+ *     @(#)ww.h        3.61 (Berkeley) %G%
  */
 
  */
 
-#ifndef POSIX_TTY
+#ifdef OLD_TTY
 #include <sgtty.h>
 #else
 #include <termios.h>
 #include <sgtty.h>
 #else
 #include <termios.h>
@@ -91,7 +91,7 @@ struct ww {
 
        /* state of a tty */
 struct ww_tty {
 
        /* state of a tty */
 struct ww_tty {
-#ifndef POSIX_TTY
+#ifdef OLD_TTY
        struct sgttyb ww_sgttyb;
        struct tchars ww_tchars;
        struct ltchars ww_ltchars;
        struct sgttyb ww_sgttyb;
        struct tchars ww_tchars;
        struct ltchars ww_ltchars;
@@ -200,8 +200,8 @@ union ww_char **wwos;               /* the old (current) screen */
 union ww_char **wwns;          /* the new (desired) screen */
 char *wwtouched;               /* wwns changed flags */
 struct ww_update *wwupd;       /* for display update */
 union ww_char **wwns;          /* the new (desired) screen */
 char *wwtouched;               /* wwns changed flags */
 struct ww_update *wwupd;       /* for display update */
-extern int wwbaudmap[];                /* maps stty() baud rate code into number */
-int wwbaud;                    /* wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed] */
+int wwospeed;                  /* output baud rate, copied from wwoldtty */
+int wwbaud;                    /* wwospeed converted into actual number */
 int wwcursorrow, wwcursorcol;  /* where we want the cursor to be */
 int wwerrno;                   /* error number */
 
 int wwcursorrow, wwcursorcol;  /* where we want the cursor to be */
 int wwerrno;                   /* error number */
 
index dafe3cc..42a64bc 100644 (file)
@@ -9,26 +9,5 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwdata.c   3.18 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwdata.c   3.19 (Berkeley) %G%";
 #endif /* not lint */
 #endif /* not lint */
-
-#include "ww.h"
-
-int wwbaudmap[] = {
-       0,
-       50,
-       75,
-       110,
-       134,
-       150,
-       200,
-       300,
-       600,
-       1200,
-       1800,
-       2400,
-       4800,
-       9600,
-       19200,
-       38400
-};
index aa2db90..0d2c680 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwend.c    3.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwend.c    3.16 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -18,5 +18,5 @@ static char sccsid[] = "@(#)wwend.c   3.15 (Berkeley) %G%";
 wwend()
 {
        xxend();
 wwend()
 {
        xxend();
-       (void) wwsettty(0, &wwoldtty, &wwnewtty);
+       (void) wwsettty(0, &wwoldtty);
 }
 }
index 82c22c0..1aa6636 100644 (file)
@@ -9,11 +9,11 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwenviron.c        3.26 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwenviron.c        3.27 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
-#ifdef POSIX_TTY
+#if !defined(OLD_TTY) && !defined(TIOCSCTTY) && !defined(TIOCNOTTY)
 #include <sys/ioctl.h>
 #endif
 #include <sys/signal.h>
 #include <sys/ioctl.h>
 #endif
 #include <sys/signal.h>
@@ -38,16 +38,11 @@ register struct ww *wp;
        (void) close(i);
 #endif
        if ((i = wp->ww_socket) < 0) {
        (void) close(i);
 #endif
        if ((i = wp->ww_socket) < 0) {
-               struct winsize winsize;
-
                if ((i = open(wp->ww_ttyname, 2)) < 0)
                        goto bad;
                if ((i = open(wp->ww_ttyname, 2)) < 0)
                        goto bad;
-               if (wwsettty(i, &wwwintty, (struct ww_tty *)0) < 0)
+               if (wwsettty(i, &wwwintty) < 0)
                        goto bad;
                        goto bad;
-               winsize.ws_row = wp->ww_w.nr;
-               winsize.ws_col = wp->ww_w.nc;
-               winsize.ws_xpixel = winsize.ws_ypixel = 0;
-               if (ioctl(i, TIOCSWINSZ, (char *)&winsize) < 0)
+               if (wwsetttysize(i, wp->ww_w.nr, wp->ww_w.nc) < 0)
                        goto bad;
        }
        (void) dup2(i, 0);
                        goto bad;
        }
        (void) dup2(i, 0);
@@ -56,7 +51,7 @@ register struct ww *wp;
        for (i = wwdtablesize - 1; i > 2; i--)
                (void) close(i);
 #ifdef TIOCSCTTY
        for (i = wwdtablesize - 1; i > 2; i--)
                (void) close(i);
 #ifdef TIOCSCTTY
-       (void) setsid(0);
+       (void) setsid();
        (void) ioctl(0, TIOCSCTTY, 0);
 #else
        (void) ioctl(0, TIOCSPGRP, (char *)&pgrp);
        (void) ioctl(0, TIOCSCTTY, 0);
 #else
        (void) ioctl(0, TIOCSPGRP, (char *)&pgrp);
index 37f3a4f..51d12b7 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwgets.c   3.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwgets.c   3.16 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -29,7 +29,7 @@ register struct ww *w;
                wwcurtowin(w);
                while ((c = wwgetc()) < 0)
                        wwiomux();
                wwcurtowin(w);
                while ((c = wwgetc()) < 0)
                        wwiomux();
-#ifndef POSIX_TTY
+#ifdef OLD_TTY
                if (c == wwoldtty.ww_sgttyb.sg_erase)
 #else
                if (c == wwoldtty.ww_termios.c_cc[VERASE])
                if (c == wwoldtty.ww_sgttyb.sg_erase)
 #else
                if (c == wwoldtty.ww_termios.c_cc[VERASE])
@@ -38,7 +38,7 @@ register struct ww *w;
                        if (p > buf)
                                rub(*--p, w);
                } else
                        if (p > buf)
                                rub(*--p, w);
                } else
-#ifndef POSIX_TTY
+#ifdef OLD_TTY
                if (c == wwoldtty.ww_sgttyb.sg_kill)
 #else
                if (c == wwoldtty.ww_termios.c_cc[VKILL])
                if (c == wwoldtty.ww_sgttyb.sg_kill)
 #else
                if (c == wwoldtty.ww_termios.c_cc[VKILL])
@@ -47,7 +47,7 @@ register struct ww *w;
                        while (p > buf)
                                rub(*--p, w);
                } else
                        while (p > buf)
                                rub(*--p, w);
                } else
-#ifndef POSIX_TTY
+#ifdef OLD_TTY
                if (c == wwoldtty.ww_ltchars.t_werasc)
 #else
                if (c == wwoldtty.ww_termios.c_cc[VWERASE])
                if (c == wwoldtty.ww_ltchars.t_werasc)
 #else
                if (c == wwoldtty.ww_termios.c_cc[VWERASE])
index e3fbc0f..76315ba 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwinit.c   3.39 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwinit.c   3.40 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -39,7 +39,7 @@ wwinit()
        if (wwgettty(0, &wwoldtty) < 0)
                return -1;
        wwwintty = wwoldtty;
        if (wwgettty(0, &wwoldtty) < 0)
                return -1;
        wwwintty = wwoldtty;
-#ifndef POSIX_TTY
+#ifdef OLD_TTY
        wwwintty.ww_sgttyb.sg_flags &= ~XTABS;
        wwnewtty.ww_sgttyb = wwoldtty.ww_sgttyb;
        wwnewtty.ww_sgttyb.sg_erase = -1;
        wwwintty.ww_sgttyb.sg_flags &= ~XTABS;
        wwnewtty.ww_sgttyb = wwoldtty.ww_sgttyb;
        wwnewtty.ww_sgttyb.sg_erase = -1;
@@ -61,6 +61,12 @@ wwinit()
        wwnewtty.ww_lmode = wwoldtty.ww_lmode | LLITOUT;
        wwnewtty.ww_ldisc = wwoldtty.ww_ldisc;
 #else
        wwnewtty.ww_lmode = wwoldtty.ww_lmode | LLITOUT;
        wwnewtty.ww_ldisc = wwoldtty.ww_ldisc;
 #else
+#ifndef OXTABS
+#define OXTABS XTABS
+#endif
+#ifndef _POSIX_VDISABLE
+#define _POSIX_VDISABLE -1
+#endif
        wwwintty.ww_termios.c_oflag &= ~OXTABS;
        wwnewtty.ww_termios = wwoldtty.ww_termios;
        wwnewtty.ww_termios.c_iflag &=
        wwwintty.ww_termios.c_oflag &= ~OXTABS;
        wwnewtty.ww_termios = wwoldtty.ww_termios;
        wwnewtty.ww_termios.c_iflag &=
@@ -70,11 +76,11 @@ wwinit()
        wwnewtty.ww_termios.c_cflag &= ~(CSIZE | PARENB);
        wwnewtty.ww_termios.c_cflag |= CS8;
        wwnewtty.ww_termios.c_lflag = 0;
        wwnewtty.ww_termios.c_cflag &= ~(CSIZE | PARENB);
        wwnewtty.ww_termios.c_cflag |= CS8;
        wwnewtty.ww_termios.c_lflag = 0;
-       for (i = 0; i < NCC; i++)
+       for (i = 0; i < NCCS; i++)
                wwnewtty.ww_termios.c_cc[i] = _POSIX_VDISABLE;
 #endif
        wwnewtty.ww_fflags = wwoldtty.ww_fflags | FASYNC;
                wwnewtty.ww_termios.c_cc[i] = _POSIX_VDISABLE;
 #endif
        wwnewtty.ww_fflags = wwoldtty.ww_fflags | FASYNC;
-       if (wwsettty(0, &wwnewtty, &wwoldtty) < 0)
+       if (wwsettty(0, &wwnewtty) < 0)
                goto bad;
 
        if ((wwterm = getenv("TERM")) == 0) {
                goto bad;
 
        if ((wwterm = getenv("TERM")) == 0) {
@@ -85,15 +91,70 @@ wwinit()
                wwerrno = WWE_BADTERM;
                goto bad;
        }
                wwerrno = WWE_BADTERM;
                goto bad;
        }
-#ifndef POSIX_TTY
-       wwbaud = wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed];
+#ifdef OLD_TTY
+       wwospeed = wwoldtty.ww_sgttyb.sg_ospeed;
 #else
 #else
-#ifdef CBAUD
-       wwbaud = wwbaudmap[wwoldtty.ww_termios.c_cflag & CBAUD];
+       wwospeed = cfgetospeed(&wwoldtty.ww_termios);
+#endif
+       switch (wwospeed) {
+       default:
+       case B0:
+               wwbaud = 0;
+               break;
+       case B50:
+               wwbaud = 50;
+               break;
+       case B75:
+               wwbaud = 75;
+               break;
+       case B110:
+               wwbaud = 110;
+               break;
+       case B134:
+               wwbaud = 134;
+               break;
+       case B150:
+               wwbaud = 150;
+               break;
+       case B200:
+               wwbaud = 200;
+               break;
+       case B300:
+               wwbaud = 300;
+               break;
+       case B600:
+               wwbaud = 600;
+               break;
+       case B1200:
+               wwbaud = 1200;
+               break;
+       case B1800:
+               wwbaud = 1800;
+               break;
+       case B2400:
+               wwbaud = 2400;
+               break;
+       case B4800:
+               wwbaud = 4800;
+               break;
+       case B9600:
+               wwbaud = 9600;
+               break;
+#ifdef B19200
+       case B19200:
 #else
 #else
-       wwbaud = wwoldtty.ww_termios.c_ospeed;
+       case EXTA:
 #endif
 #endif
+               wwbaud = 19200;
+               break;
+#ifdef B38400
+       case B38400:
+#else
+       case EXTB:
 #endif
 #endif
+               wwbaud = 38400;
+               break;
+       }
 
        if (xxinit() < 0)
                goto bad;
 
        if (xxinit() < 0)
                goto bad;
@@ -207,7 +268,7 @@ bad:
         * Don't bother to free storage.  We're supposed
         * to exit when wwinit fails anyway.
         */
         * Don't bother to free storage.  We're supposed
         * to exit when wwinit fails anyway.
         */
-       (void) wwsettty(0, &wwoldtty, &wwnewtty);
+       (void) wwsettty(0, &wwoldtty);
        (void) signal(SIGIO, SIG_DFL);
        (void) sigsetmask(s);
        return -1;
        (void) signal(SIGIO, SIG_DFL);
        (void) sigsetmask(s);
        return -1;
index a475d26..896afcc 100644 (file)
@@ -9,13 +9,13 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwiomux.c  3.25 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwiomux.c  3.26 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #include <sys/time.h>
 #include <sys/types.h>
 #endif /* not lint */
 
 #include "ww.h"
 #include <sys/time.h>
 #include <sys/types.h>
-#ifdef POSIX_TTY
+#if !defined(OLD_TTY) && !defined(TIOCPKT_DATA)
 #include <sys/ioctl.h>
 #endif
 #include <fcntl.h>
 #include <sys/ioctl.h>
 #endif
 #include <fcntl.h>
index 22e8e73..ac2ba7a 100644 (file)
@@ -9,11 +9,11 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwpty.c    3.18 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwpty.c    3.19 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
-#ifdef POSIX_TTY
+#if !defined(OLD_TTY) && !defined(TIOCPKT)
 #include <sys/ioctl.h>
 #endif
 
 #include <sys/ioctl.h>
 #endif
 
index a32f8fc..8d52aab 100644 (file)
@@ -9,13 +9,10 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwsize.c   3.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwsize.c   3.10 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
-#ifdef POSIX_TTY
-#include <sys/ioctl.h>
-#endif
 
 /*
  * Resize a window.  Should be unattached.
 
 /*
  * Resize a window.  Should be unattached.
@@ -152,14 +149,8 @@ register struct ww *w;
        /*
         * Fool with pty.
         */
        /*
         * Fool with pty.
         */
-       if (w->ww_ispty && w->ww_pty >= 0) {
-               struct winsize winsize;
-
-               winsize.ws_row = nrow;
-               winsize.ws_col = ncol;
-               winsize.ws_xpixel = winsize.ws_ypixel = 0;
-               (void) ioctl(w->ww_pty, TIOCSWINSZ, (char *)&winsize);
-       }
+       if (w->ww_ispty && w->ww_pty >= 0)
+               (void) wwsetttysize(w->ww_pty, nrow, ncol);
        return 0;
 bad:
        if (win != 0)
        return 0;
 bad:
        if (win != 0)
index b00edb4..b7063ef 100644 (file)
@@ -9,7 +9,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwsuspend.c        3.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwsuspend.c        3.14 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -25,7 +25,7 @@ wwsuspend()
        (void) signal(SIGTSTP, SIG_DFL);
        (void) kill(0, SIGTSTP);
        (void) signal(SIGTSTP, SIG_IGN);
        (void) signal(SIGTSTP, SIG_DFL);
        (void) kill(0, SIGTSTP);
        (void) signal(SIGTSTP, SIG_IGN);
-       (void) wwsettty(0, &wwnewtty, &wwoldtty);
+       (void) wwsettty(0, &wwnewtty);
        xxstart();
        wwredraw();             /* XXX, clears the screen twice */
        (void) signal(SIGTSTP, oldsig);
        xxstart();
        wwredraw();             /* XXX, clears the screen twice */
        (void) signal(SIGTSTP, oldsig);
index a57074d..5b6b8f9 100644 (file)
@@ -9,16 +9,19 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwtty.c    3.16 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwtty.c    3.17 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #include <fcntl.h>
 #endif /* not lint */
 
 #include "ww.h"
 #include <fcntl.h>
+#if !defined(OLD_TTY) && !defined(TIOCGWINSZ)
+#include <sys/ioctl.h>
+#endif
 
 wwgettty(d, t)
 register struct ww_tty *t;
 {
 
 wwgettty(d, t)
 register struct ww_tty *t;
 {
-#ifndef POSIX_TTY
+#ifdef OLD_TTY
        if (ioctl(d, TIOCGETP, (char *)&t->ww_sgttyb) < 0)
                goto bad;
        if (ioctl(d, TIOCGETC, (char *)&t->ww_tchars) < 0)
        if (ioctl(d, TIOCGETP, (char *)&t->ww_sgttyb) < 0)
                goto bad;
        if (ioctl(d, TIOCGETC, (char *)&t->ww_tchars) < 0)
@@ -46,12 +49,13 @@ bad:
  * 'o' is the current modes.  We set the line discipline only if
  * it changes, to avoid unnecessary flushing of typeahead.
  */
  * 'o' is the current modes.  We set the line discipline only if
  * it changes, to avoid unnecessary flushing of typeahead.
  */
-wwsettty(d, t, o)
-register struct ww_tty *t, *o;
+wwsettty(d, t)
+register struct ww_tty *t;
 {
 {
-#ifndef POSIX_TTY
-       /* for buggy tty driver that doesn't wait for output to drain */
+#ifdef OLD_TTY
        int i;
        int i;
+
+       /* XXX, for buggy tty drivers that don't wait for output to drain */
        while (ioctl(d, TIOCOUTQ, &i) >= 0 && i > 0)
                usleep(100000);
        if (ioctl(d, TIOCSETN, (char *)&t->ww_sgttyb) < 0)
        while (ioctl(d, TIOCOUTQ, &i) >= 0 && i > 0)
                usleep(100000);
        if (ioctl(d, TIOCSETN, (char *)&t->ww_sgttyb) < 0)
@@ -62,10 +66,16 @@ register struct ww_tty *t, *o;
                goto bad;
        if (ioctl(d, TIOCLSET, (char *)&t->ww_lmode) < 0)
                goto bad;
                goto bad;
        if (ioctl(d, TIOCLSET, (char *)&t->ww_lmode) < 0)
                goto bad;
-       if ((o == 0 || t->ww_ldisc != o->ww_ldisc) &&
+       if (ioctl(d, TIOCGETD, (char *)&i) < 0)
+               goto bad;
+       if (t->ww_ldisc != i &&
            ioctl(d, TIOCSETD, (char *)&t->ww_ldisc) < 0)
                goto bad;
 #else
            ioctl(d, TIOCSETD, (char *)&t->ww_ldisc) < 0)
                goto bad;
 #else
+#ifdef sun
+       /* XXX, for buggy tty drivers that don't wait for output to drain */
+       (void) tcdrain(d);
+#endif
        if (tcsetattr(d, TCSADRAIN, &t->ww_termios) < 0)
                goto bad;
 #endif
        if (tcsetattr(d, TCSADRAIN, &t->ww_termios) < 0)
                goto bad;
 #endif
@@ -76,3 +86,68 @@ bad:
        wwerrno = WWE_SYS;
        return -1;
 }
        wwerrno = WWE_SYS;
        return -1;
 }
+
+/*
+ * The ttysize and stop-start routines must also work
+ * on the control side of pseudoterminals.
+ */
+
+wwgetttysize(d, r, c)
+       int *r, *c;
+{
+       struct winsize winsize;
+
+       if (ioctl(d, TIOCGWINSZ, (char *)&winsize) < 0) {
+               wwerrno = WWE_SYS;
+               return -1;
+       }
+       if (winsize.ws_row != 0)
+               *r = winsize.ws_row;
+       if (winsize.ws_col != 0)
+               *c = winsize.ws_col;
+       return 0;
+}
+
+wwsetttysize(d, r, c)
+{
+       struct winsize winsize;
+
+       winsize.ws_row = r;
+       winsize.ws_col = c;
+       winsize.ws_xpixel = winsize.ws_ypixel = 0;
+       if (ioctl(d, TIOCSWINSZ, (char *)&winsize) < 0) {
+               wwerrno = WWE_SYS;
+               return -1;
+       }
+       return 0;
+}
+
+wwstoptty(d)
+{
+#if !defined(OLD_TTY) && defined(TCOOFF)
+       /* not guaranteed to work on the pty side */
+       if (tcflow(d, TCOOFF) < 0)
+#else
+       if (ioctl(d, TIOCSTOP, (char *)0) < 0)
+#endif
+       {
+               wwerrno = WWE_SYS;
+               return -1;
+       }
+       return 0;
+}
+
+wwstarttty(d)
+{
+#if !defined(OLD_TTY) && defined(TCOON)
+       /* not guaranteed to work on the pty side */
+       if (tcflow(d, TCOON) < 0)
+#else
+       if (ioctl(d, TIOCSTART, (char *)0) < 0)
+#endif
+       {
+               wwerrno = WWE_SYS;
+               return -1;
+       }
+       return 0;
+}