first try at POSIX tty
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Sun, 3 Jun 1990 06:15:20 +0000 (22:15 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Sun, 3 Jun 1990 06:15:20 +0000 (22:15 -0800)
SCCS-vsn: usr.bin/window/wwpty.c 3.16
SCCS-vsn: usr.bin/window/wwsize.c 3.7
SCCS-vsn: usr.bin/window/main.c 3.39
SCCS-vsn: usr.bin/window/ttgeneric.c 3.43
SCCS-vsn: usr.bin/window/wwtty.c 3.14
SCCS-vsn: usr.bin/window/ttinit.c 3.24
SCCS-vsn: usr.bin/window/win.c 3.22
SCCS-vsn: usr.bin/window/ww.h 3.58
SCCS-vsn: usr.bin/window/wwenviron.c 3.24
SCCS-vsn: usr.bin/window/wwgets.c 3.13
SCCS-vsn: usr.bin/window/wwinit.c 3.37
SCCS-vsn: usr.bin/window/wwiomux.c 3.23

12 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/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/wwtty.c

index 0b3f534..23ab712 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     3.38 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     3.39 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "defs.h"
 #endif /* not lint */
 
 #include "defs.h"
@@ -99,12 +99,28 @@ char **argv;
                (void) fprintf(stderr, "%s.\n", wwerror());
                exit(1);
        }
                (void) fprintf(stderr, "%s.\n", wwerror());
                exit(1);
        }
+
+#ifndef POSIX_TTY
        if (debug)
                wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
        if (xflag) {
                wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc;
                wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc;
        }
        if (debug)
                wwnewtty.ww_tchars.t_quitc = wwoldtty.ww_tchars.t_quitc;
        if (xflag) {
                wwnewtty.ww_tchars.t_stopc = wwoldtty.ww_tchars.t_stopc;
                wwnewtty.ww_tchars.t_startc = wwoldtty.ww_tchars.t_startc;
        }
+#else
+       if (debug) {
+               wwnewtty.ww_termios.c_cc[VQUIT] =
+                       wwoldtty.ww_termios.c_cc[VQUIT];
+               wwnewtty.ww_termios.c_lflag |= ISIG;
+       }
+       if (xflag) {
+               wwnewtty.ww_termios.c_cc[VSTOP] =
+                       wwoldtty.ww_termios.c_cc[VSTOP];
+               wwnewtty.ww_termios.c_cc[VSTART] =
+                       wwoldtty.ww_termios.c_cc[VSTART];
+               wwnewtty.ww_termios.c_iflag |= IXON;
+       }
+#endif
        if (debug || xflag)
                (void) wwsettty(0, &wwnewtty, &wwoldtty);
 
        if (debug || xflag)
                (void) wwsettty(0, &wwnewtty, &wwoldtty);
 
index 091edca..745e61c 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ttgeneric.c        3.42 (Berkeley) %G%";
+static char sccsid[] = "@(#)ttgeneric.c        3.43 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -374,7 +374,15 @@ 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;
        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
 
        gen_CM = ttxgetstr("cm");               /* may not work */
        gen_IM = ttxgetstr("im");
 
        gen_CM = ttxgetstr("cm");               /* may not work */
        gen_IM = ttxgetstr("im");
@@ -469,12 +477,18 @@ tt_generic()
        if (gen_UG > 0 || gen_US && gen_SO && ttstrcmp(gen_US, gen_SO) == 0)
                gen_US = 0;
 
        if (gen_UG > 0 || gen_US && gen_SO && ttstrcmp(gen_US, gen_SO) == 0)
                gen_US = 0;
 
-       if (gen_IM->ts_n == 0)
+       if (gen_IM && gen_IM->ts_n == 0) {
+               free((char *) gen_IM);
                gen_IM = 0;
                gen_IM = 0;
-       if (gen_EI->ts_n == 0)
+       }
+       if (gen_EI && gen_EI->ts_n == 0) {
+               free((char *) gen_EI);
                gen_EI = 0;
                gen_EI = 0;
-       if (gen_IC->ts_n == 0)
+       }
+       if (gen_IC && gen_IC->ts_n == 0) {
+               free((char *) gen_IC);
                gen_IC = 0;
                gen_IC = 0;
+       }
        if (gen_IM)
                tt.tt_inschar = gen_inschar;
        else if (gen_IC)
        if (gen_IM)
                tt.tt_inschar = gen_inschar;
        else if (gen_IC)
index a79b5af..9b321a3 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ttinit.c   3.23 (Berkeley) %G%";
+static char sccsid[] = "@(#)ttinit.c   3.24 (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();
index 4babc67..5b0afc9 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)win.c      3.21 (Berkeley) %G%";
+static char sccsid[] = "@(#)win.c      3.22 (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.
index 53ff14a..ca55b5b 100644 (file)
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  *
- *     @(#)ww.h        3.57 (Berkeley) %G%
+ *     @(#)ww.h        3.58 (Berkeley) %G%
  */
 
  */
 
+#ifndef POSIX_TTY
 #include <sgtty.h>
 #include <sgtty.h>
+#else
+#include <termios.h>
+#endif
 #include <setjmp.h>
 #include <machine/endian.h>
 
 #include <setjmp.h>
 #include <machine/endian.h>
 
@@ -94,11 +98,15 @@ struct ww {
 
        /* state of a tty */
 struct ww_tty {
 
        /* state of a tty */
 struct ww_tty {
+#ifndef POSIX_TTY
        struct sgttyb ww_sgttyb;
        struct tchars ww_tchars;
        struct ltchars ww_ltchars;
        int ww_lmode;
        int ww_ldisc;
        struct sgttyb ww_sgttyb;
        struct tchars ww_tchars;
        struct ltchars ww_ltchars;
        int ww_lmode;
        int ww_ldisc;
+#else
+       struct termios ww_termios;
+#endif
        int ww_fflags;
 };
 
        int ww_fflags;
 };
 
index ace782f..4c7f4ec 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwenviron.c        3.23 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwenviron.c        3.24 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
+#ifdef POSIX_TTY
+#include <sys/ioctl.h>
+#endif
 #include <sys/signal.h>
 
 /*
 #include <sys/signal.h>
 
 /*
index 910449e..3ed876c 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwgets.c   3.12 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwgets.c   3.13 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -36,13 +36,30 @@ register struct ww *w;
                wwcurtowin(w);
                while ((c = wwgetc()) < 0)
                        wwiomux();
                wwcurtowin(w);
                while ((c = wwgetc()) < 0)
                        wwiomux();
-               if (c == wwoldtty.ww_sgttyb.sg_erase) {
+#ifndef POSIX_TTY
+               if (c == wwoldtty.ww_sgttyb.sg_erase)
+#else
+               if (c == wwoldtty.ww_termios.c_cc[VERASE])
+#endif
+               {
                        if (p > buf)
                                rub(*--p, w);
                        if (p > buf)
                                rub(*--p, w);
-               } else if (c == wwoldtty.ww_sgttyb.sg_kill) {
+               } else
+#ifndef POSIX_TTY
+               if (c == wwoldtty.ww_sgttyb.sg_kill)
+#else
+               if (c == wwoldtty.ww_termios.c_cc[VKILL])
+#endif
+               {
                        while (p > buf)
                                rub(*--p, w);
                        while (p > buf)
                                rub(*--p, w);
-               } else if (c == wwoldtty.ww_ltchars.t_werasc) {
+               } else
+#ifndef POSIX_TTY
+               if (c == wwoldtty.ww_ltchars.t_werasc)
+#else
+               if (c == wwoldtty.ww_termios.c_cc[VWERASE])
+#endif
+               {
                        while (--p >= buf && (*p == ' ' || *p == '\t'))
                                rub(*p, w);
                        while (p >= buf && *p != ' ' && *p != '\t')
                        while (--p >= buf && (*p == ' ' || *p == '\t'))
                                rub(*p, w);
                        while (p >= buf && *p != ' ' && *p != '\t')
index fb1394d..d7202fd 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwinit.c   3.36 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwinit.c   3.37 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -46,6 +46,7 @@ wwinit()
        if (wwgettty(0, &wwoldtty) < 0)
                return -1;
        wwwintty = wwoldtty;
        if (wwgettty(0, &wwoldtty) < 0)
                return -1;
        wwwintty = wwoldtty;
+#ifndef POSIX_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;
@@ -66,6 +67,19 @@ wwinit()
        wwnewtty.ww_ltchars.t_lnextc = -1;
        wwnewtty.ww_lmode = wwoldtty.ww_lmode | LLITOUT;
        wwnewtty.ww_ldisc = wwoldtty.ww_ldisc;
        wwnewtty.ww_ltchars.t_lnextc = -1;
        wwnewtty.ww_lmode = wwoldtty.ww_lmode | LLITOUT;
        wwnewtty.ww_ldisc = wwoldtty.ww_ldisc;
+#else
+       wwwintty.ww_termios.c_oflag &= ~OXTABS;
+       wwnewtty.ww_termios = wwoldtty.ww_termios;
+       wwnewtty.ww_termios.c_iflag &=
+               ~(ISTRIP | INLCR | IGNCR | ICRNL | IXON | IXOFF | IMAXBEL);
+       wwnewtty.ww_termios.c_iflag |= INPCK;
+       wwnewtty.ww_termios.c_oflag = 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++)
+               wwnewtty.ww_termios.c_cc[i] = _POSIX_VDISABLE;
+#endif
        wwnewtty.ww_fflags = wwoldtty.ww_fflags | FASYNC;
        if (wwsettty(0, &wwnewtty, &wwoldtty) < 0)
                goto bad;
        wwnewtty.ww_fflags = wwoldtty.ww_fflags | FASYNC;
        if (wwsettty(0, &wwnewtty, &wwoldtty) < 0)
                goto bad;
@@ -78,7 +92,15 @@ wwinit()
                wwerrno = WWE_BADTERM;
                goto bad;
        }
                wwerrno = WWE_BADTERM;
                goto bad;
        }
+#ifndef POSIX_TTY
        wwbaud = wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed];
        wwbaud = wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed];
+#else
+#ifdef CBAUD
+       wwbaud = wwbaudmap[wwoldtty.ww_termios.c_cflag & CBAUD];
+#else
+       wwbaud = wwoldtty.ww_termios.c_ospeed;
+#endif
+#endif
 
        if (xxinit() < 0)
                goto bad;
 
        if (xxinit() < 0)
                goto bad;
index 8bc8224..60d7b9b 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwiomux.c  3.22 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwiomux.c  3.23 (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
+#include <sys/ioctl.h>
+#endif
 #include <fcntl.h>
 
 /*
 #include <fcntl.h>
 
 /*
index 3dc383d..a733b65 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwpty.c    3.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwpty.c    3.16 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
+#ifdef POSIX_TTY
+#include <sys/ioctl.h>
+#endif
 
 wwgetpty(w)
 register struct ww *w;
 
 wwgetpty(w)
 register struct ww *w;
index c85db8c..9872a1c 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwsize.c   3.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwsize.c   3.7 (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.
index e7b218e..794e948 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwtty.c    3.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwtty.c    3.14 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -25,6 +25,7 @@ static char sccsid[] = "@(#)wwtty.c   3.13 (Berkeley) %G%";
 wwgettty(d, t)
 register struct ww_tty *t;
 {
 wwgettty(d, t)
 register struct ww_tty *t;
 {
+#ifndef POSIX_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)
@@ -35,6 +36,10 @@ register struct ww_tty *t;
                goto bad;
        if (ioctl(d, TIOCGETD, (char *)&t->ww_ldisc) < 0)
                goto bad;
                goto bad;
        if (ioctl(d, TIOCGETD, (char *)&t->ww_ldisc) < 0)
                goto bad;
+#else
+       if (tcgetattr(d, &t->ww_termios) < 0)
+               goto bad;
+#endif
        if ((t->ww_fflags = fcntl(d, F_GETFL, 0)) < 0)
                goto bad;
        return 0;
        if ((t->ww_fflags = fcntl(d, F_GETFL, 0)) < 0)
                goto bad;
        return 0;
@@ -51,7 +56,12 @@ bad:
 wwsettty(d, t, o)
 register struct ww_tty *t, *o;
 {
 wwsettty(d, t, o)
 register struct ww_tty *t, *o;
 {
-       if (ioctl(d, TIOCSETP, (char *)&t->ww_sgttyb) < 0)
+#ifndef POSIX_TTY
+       /* for buggy tty driver that doesn't wait for output to drain */
+       int i;
+       while (ioctl(d, TIOCOUTQ, &i) >= 0 && i > 0)
+               usleep(100000);
+       if (ioctl(d, TIOCSETN, (char *)&t->ww_sgttyb) < 0)
                goto bad;
        if (ioctl(d, TIOCSETC, (char *)&t->ww_tchars) < 0)
                goto bad;
                goto bad;
        if (ioctl(d, TIOCSETC, (char *)&t->ww_tchars) < 0)
                goto bad;
@@ -62,6 +72,10 @@ register struct ww_tty *t, *o;
        if ((o == 0 || t->ww_ldisc != o->ww_ldisc) &&
            ioctl(d, TIOCSETD, (char *)&t->ww_ldisc) < 0)
                goto bad;
        if ((o == 0 || t->ww_ldisc != o->ww_ldisc) &&
            ioctl(d, TIOCSETD, (char *)&t->ww_ldisc) < 0)
                goto bad;
+#else
+       if (tcsetattr(d, TCSADRAIN, &t->ww_termios) < 0)
+               goto bad;
+#endif
        if (fcntl(d, F_SETFL, t->ww_fflags) < 0)
                goto bad;
        return 0;
        if (fcntl(d, F_SETFL, t->ww_fflags) < 0)
                goto bad;
        return 0;