From: Edward Wang Date: Sun, 3 Jun 1990 06:15:20 +0000 (-0800) Subject: first try at POSIX tty X-Git-Tag: BSD-4_3_Reno-Snapshot-Development~2393 X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/commitdiff_plain/bbbb7b14574556dc01284f32b4d31dae4e222931 first try at POSIX tty 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 --- diff --git a/usr/src/usr.bin/window/main.c b/usr/src/usr.bin/window/main.c index 0b3f534af9..23ab712d58 100644 --- a/usr/src/usr.bin/window/main.c +++ b/usr/src/usr.bin/window/main.c @@ -16,7 +16,7 @@ */ #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" @@ -99,12 +99,28 @@ char **argv; (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; } +#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); diff --git a/usr/src/usr.bin/window/ttgeneric.c b/usr/src/usr.bin/window/ttgeneric.c index 091edcaf59..745e61c119 100644 --- a/usr/src/usr.bin/window/ttgeneric.c +++ b/usr/src/usr.bin/window/ttgeneric.c @@ -16,7 +16,7 @@ */ #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" @@ -374,7 +374,15 @@ tt_generic() { 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 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_IM->ts_n == 0) + if (gen_IM && gen_IM->ts_n == 0) { + free((char *) gen_IM); gen_IM = 0; - if (gen_EI->ts_n == 0) + } + if (gen_EI && gen_EI->ts_n == 0) { + free((char *) gen_EI); gen_EI = 0; - if (gen_IC->ts_n == 0) + } + if (gen_IC && gen_IC->ts_n == 0) { + free((char *) gen_IC); gen_IC = 0; + } if (gen_IM) tt.tt_inschar = gen_inschar; else if (gen_IC) diff --git a/usr/src/usr.bin/window/ttinit.c b/usr/src/usr.bin/window/ttinit.c index a79b5afbaf..9b321a38ff 100644 --- a/usr/src/usr.bin/window/ttinit.c +++ b/usr/src/usr.bin/window/ttinit.c @@ -16,11 +16,14 @@ */ #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" +#ifdef POSIX_TTY +#include +#endif int tt_h19(); int tt_h29(); diff --git a/usr/src/usr.bin/window/win.c b/usr/src/usr.bin/window/win.c index 4babc67203..5b0afc9a8a 100644 --- a/usr/src/usr.bin/window/win.c +++ b/usr/src/usr.bin/window/win.c @@ -16,11 +16,14 @@ */ #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" +#ifdef POSIX_TTY +#include +#endif /* * Higher level routines for dealing with windows. diff --git a/usr/src/usr.bin/window/ww.h b/usr/src/usr.bin/window/ww.h index 53ff14aaf4..ca55b5bd3a 100644 --- a/usr/src/usr.bin/window/ww.h +++ b/usr/src/usr.bin/window/ww.h @@ -14,10 +14,14 @@ * 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 +#else +#include +#endif #include #include @@ -94,11 +98,15 @@ struct ww { /* 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; +#else + struct termios ww_termios; +#endif int ww_fflags; }; diff --git a/usr/src/usr.bin/window/wwenviron.c b/usr/src/usr.bin/window/wwenviron.c index ace782f02f..4c7f4ec7dc 100644 --- a/usr/src/usr.bin/window/wwenviron.c +++ b/usr/src/usr.bin/window/wwenviron.c @@ -16,10 +16,13 @@ */ #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" +#ifdef POSIX_TTY +#include +#endif #include /* diff --git a/usr/src/usr.bin/window/wwgets.c b/usr/src/usr.bin/window/wwgets.c index 910449e9a2..3ed876cb8f 100644 --- a/usr/src/usr.bin/window/wwgets.c +++ b/usr/src/usr.bin/window/wwgets.c @@ -16,7 +16,7 @@ */ #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" @@ -36,13 +36,30 @@ register struct ww *w; 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); - } 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); - } 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') diff --git a/usr/src/usr.bin/window/wwinit.c b/usr/src/usr.bin/window/wwinit.c index fb1394d418..d7202fd3a6 100644 --- a/usr/src/usr.bin/window/wwinit.c +++ b/usr/src/usr.bin/window/wwinit.c @@ -16,7 +16,7 @@ */ #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" @@ -46,6 +46,7 @@ wwinit() 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; @@ -66,6 +67,19 @@ wwinit() 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; @@ -78,7 +92,15 @@ wwinit() wwerrno = WWE_BADTERM; goto bad; } +#ifndef POSIX_TTY 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; diff --git a/usr/src/usr.bin/window/wwiomux.c b/usr/src/usr.bin/window/wwiomux.c index 8bc8224b40..60d7b9bd29 100644 --- a/usr/src/usr.bin/window/wwiomux.c +++ b/usr/src/usr.bin/window/wwiomux.c @@ -16,12 +16,15 @@ */ #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 #include +#ifdef POSIX_TTY +#include +#endif #include /* diff --git a/usr/src/usr.bin/window/wwpty.c b/usr/src/usr.bin/window/wwpty.c index 3dc383d17c..a733b650f5 100644 --- a/usr/src/usr.bin/window/wwpty.c +++ b/usr/src/usr.bin/window/wwpty.c @@ -16,10 +16,13 @@ */ #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" +#ifdef POSIX_TTY +#include +#endif wwgetpty(w) register struct ww *w; diff --git a/usr/src/usr.bin/window/wwsize.c b/usr/src/usr.bin/window/wwsize.c index c85db8c7af..9872a1c9aa 100644 --- a/usr/src/usr.bin/window/wwsize.c +++ b/usr/src/usr.bin/window/wwsize.c @@ -16,10 +16,13 @@ */ #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" +#ifdef POSIX_TTY +#include +#endif /* * Resize a window. Should be unattached. diff --git a/usr/src/usr.bin/window/wwtty.c b/usr/src/usr.bin/window/wwtty.c index e7b218e978..794e948d67 100644 --- a/usr/src/usr.bin/window/wwtty.c +++ b/usr/src/usr.bin/window/wwtty.c @@ -16,7 +16,7 @@ */ #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" @@ -25,6 +25,7 @@ static char sccsid[] = "@(#)wwtty.c 3.13 (Berkeley) %G%"; 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) @@ -35,6 +36,10 @@ register struct ww_tty *t; 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; @@ -51,7 +56,12 @@ bad: 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; @@ -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; +#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;