new io scheme
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Tue, 17 Jan 1984 07:26:32 +0000 (23:26 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Tue, 17 Jan 1984 07:26:32 +0000 (23:26 -0800)
SCCS-vsn: usr.bin/window/wwinit.c 3.14
SCCS-vsn: usr.bin/window/wwopen.c 3.15
SCCS-vsn: usr.bin/window/ww.h 3.25
SCCS-vsn: usr.bin/window/cmd.c 3.20
SCCS-vsn: usr.bin/window/cmd1.c 3.20
SCCS-vsn: usr.bin/window/wwgets.c 3.3
SCCS-vsn: usr.bin/window/cmd2.c 3.22
SCCS-vsn: usr.bin/window/defs.h 3.8
SCCS-vsn: usr.bin/window/cmd4.c 3.7
SCCS-vsn: usr.bin/window/cmd5.c 3.9
SCCS-vsn: usr.bin/window/:ww 1.7
SCCS-vsn: usr.bin/window/cmd6.c 3.7
SCCS-vsn: usr.bin/window/wwpty.c 3.6
SCCS-vsn: usr.bin/window/mloop.c 3.2
SCCS-vsn: usr.bin/window/wwiomux.c 3.7
SCCS-vsn: usr.bin/window/win.c 3.2

16 files changed:
usr/src/usr.bin/window/:ww
usr/src/usr.bin/window/cmd.c
usr/src/usr.bin/window/cmd1.c
usr/src/usr.bin/window/cmd2.c
usr/src/usr.bin/window/cmd4.c
usr/src/usr.bin/window/cmd5.c
usr/src/usr.bin/window/cmd6.c
usr/src/usr.bin/window/defs.h
usr/src/usr.bin/window/mloop.c
usr/src/usr.bin/window/win.c
usr/src/usr.bin/window/ww.h
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/wwopen.c
usr/src/usr.bin/window/wwpty.c

index 902e859..7bc504c 100644 (file)
@@ -8,5 +8,6 @@
 +/"i.t"16t"i.b"16t"i.l"16t"i.r"nDDDD
 +/"cur.r"16t"cur.c"nDD
 +/"win"16t"buf"16t"fmap"16t"nvis"npppp
 +/"i.t"16t"i.b"16t"i.l"16t"i.r"nDDDD
 +/"cur.r"16t"cur.c"nDD
 +/"win"16t"buf"16t"fmap"16t"nvis"npppp
-+/"pty"16t"pid"16t"ttyname"nDD11C
-+/t
++/"pty"16t"pid"16t"ttyname"nDD11C+
++/"ob"16t"obe"16t"obp"16t"obc"n3pD
++/"stopped"nb
index 91009b4..be1fe37 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd.c       3.19 83/12/09";
+static char *sccsid = "@(#)cmd.c       3.20 84/01/16";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -14,7 +14,7 @@ docmd()
        if (selwin != 0)
                wwcursor(selwin, 1);
        for (;;) {
        if (selwin != 0)
                wwcursor(selwin, 1);
        for (;;) {
-               while ((c = bgetc()) >= 0) {
+               while ((c = wwgetc()) >= 0) {
                        if (!terse)
                                (void) wwputs("\r\n", cmdwin);
                        switch (c) {
                        if (!terse)
                                (void) wwputs("\r\n", cmdwin);
                        switch (c) {
@@ -186,8 +186,8 @@ docmd()
                        (void) wwputs("Command: ", cmdwin);
                        wwcurtowin(cmdwin);
                }
                        (void) wwputs("Command: ", cmdwin);
                        wwcurtowin(cmdwin);
                }
-               while (bpeekc() < 0)
-                       bread();
+               while (wwpeekc() < 0)
+                       wwiomux();
        }
        if (!quit) {
                if (!terse) {
        }
        if (!quit) {
                if (!terse) {
@@ -207,8 +207,8 @@ getwin()
        if (!terse)
                (void) wwputs("Which window? ", cmdwin);
        wwcurtowin(cmdwin);
        if (!terse)
                (void) wwputs("Which window? ", cmdwin);
        wwcurtowin(cmdwin);
-       while ((c = bgetc()) < 0)
-               bread();
+       while ((c = wwgetc()) < 0)
+               wwiomux();
        if (debug && c == 'c')
                w = cmdwin;
        else if (debug && c == 'f')
        if (debug && c == 'c')
                w = cmdwin;
        else if (debug && c == 'f')
index 5beb4e7..2e22b06 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd1.c      3.19 84/01/13";
+static char *sccsid = "@(#)cmd1.c      3.20 84/01/16";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -19,8 +19,8 @@ c_window()
        for (;;) {
                wwbox(boxwin, row - 1, col - 1, 3, 3);
                wwsetcursor(row, col);
        for (;;) {
                wwbox(boxwin, row - 1, col - 1, 3, 3);
                wwsetcursor(row, col);
-               while (bpeekc() < 0)
-                       bread();
+               while (wwpeekc() < 0)
+                       wwiomux();
                switch (getpos(&row, &col, row > 1, 0,
                        wwnrow - 1, wwncol - 1)) {
                case 3:
                switch (getpos(&row, &col, row > 1, 0,
                        wwnrow - 1, wwncol - 1)) {
                case 3:
@@ -46,8 +46,8 @@ c_window()
                        xrow - row + 3, xcol - col + 3);
                wwsetcursor(xrow, xcol);
                wwflush();
                        xrow - row + 3, xcol - col + 3);
                wwsetcursor(xrow, xcol);
                wwflush();
-               while (bpeekc() < 0)
-                       bread();
+               while (wwpeekc() < 0)
+                       wwiomux();
                switch (getpos(&xrow, &xcol, row, col, wwnrow - 1, wwncol - 1))
                {
                case 3:
                switch (getpos(&xrow, &xcol, row, col, wwnrow - 1, wwncol - 1))
                {
                case 3:
@@ -82,7 +82,7 @@ int maxrow, maxcol;
        char c;
        int oldrow = *row, oldcol = *col;
 
        char c;
        int oldrow = *row, oldcol = *col;
 
-       while ((c = bgetc()) >= 0) {
+       while ((c = wwgetc()) >= 0) {
                switch (c) {
                case '0': case '1': case '2': case '3': case '4':
                case '5': case '6': case '7': case '8': case '9':
                switch (c) {
                case '0': case '1': case '2': case '3': case '4':
                case '5': case '6': case '7': case '8': case '9':
index fe28a61..d1ea784 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd2.c      3.21 84/01/13";
+static char *sccsid = "@(#)cmd2.c      3.22 84/01/16";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -157,16 +157,22 @@ c_stat()
 {
        register struct ww *w;
 
 {
        register struct ww *w;
 
-       if ((w = openiwin(6, "IO Statics")) == 0) {
+       if ((w = openiwin(8, "IO Statistics")) == 0) {
                error("Can't open statistics window: %s.", wwerror());
                return;
        }
                error("Can't open statistics window: %s.", wwerror());
                return;
        }
-       (void) wwprintf(w, "nread\tnreadz\tnreade\tnreadc\tnwrite\tnwritec\n");
-       (void) wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\n",
-               nread, nreadz, nreade, nreadc, wwnwrite, wwnwritec);
-       (void) wwprintf(w, "nupdate\tnupdlin\tnupdmis\tnmajlin\tnmajmis\n");
-       (void) wwprintf(w, "%d\t%d\t%d\t%d\t%d\n",
+       (void) wwprintf(w, "nwrite\tnwritec\tnupdate\tnupdlin\tnupdmis\tnmajlin\tnmajmis\n");
+       (void) wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
+               wwnwrite, wwnwritec,
                wwnupdate, wwnupdline, wwnupdmiss, wwnmajline, wwnmajmiss);
                wwnupdate, wwnupdline, wwnupdmiss, wwnmajline, wwnmajmiss);
+       (void) wwprintf(w, "nsel\tnselz\tnsele\tnread\tnreadz\tnreade\tnreadc\n");
+       (void) wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\t%d\n",
+               wwnselect, wwnselectz, wwnselecte,
+               wwnread, wwnreadz, wwnreade, wwnreadc);
+       (void) wwprintf(w, "nwread\tnwreadz\tnwreade\tnwreadd\tnwreadc\tnwreadp\n");
+       (void) wwprintf(w, "%d\t%d\t%d\t%d\t%d\t%d\n",
+               wwnwread, wwnwreadz, wwnwreade,
+               wwnwreadd, wwnwreadc, wwnwreadp);
        waitnl(w);
        closeiwin(w);
 }
        waitnl(w);
        closeiwin(w);
 }
@@ -208,9 +214,9 @@ c_quit()
                wwadd(cmdwin, &wwhead);
        (void) wwputs("Really quit [yn]? ", cmdwin);
        wwcurtowin(cmdwin);
                wwadd(cmdwin, &wwhead);
        (void) wwputs("Really quit [yn]? ", cmdwin);
        wwcurtowin(cmdwin);
-       while (bpeekc() < 0)
-               bread();
-       if (bgetc() == 'y') {
+       while (wwpeekc() < 0)
+               wwiomux();
+       if (wwgetc() == 'y') {
                (void) wwputs("Yes", cmdwin);
                quit++;
        } else
                (void) wwputs("Yes", cmdwin);
                quit++;
        } else
index 3ad5282..fe84f29 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd4.c      3.6 83/12/02";
+static char *sccsid = "@(#)cmd4.c      3.7 84/01/16";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -21,7 +21,7 @@ c_show()
                front(w, 0);
                wwsetcursor(w->ww_w.t - 1, w->ww_w.l + 1);
                for (;;) {
                front(w, 0);
                wwsetcursor(w->ww_w.t - 1, w->ww_w.l + 1);
                for (;;) {
-                       switch (bgetc()) {
+                       switch (wwgetc()) {
                        case '\r':
                        case '\n':
                                break;
                        case '\r':
                        case '\n':
                                break;
@@ -29,7 +29,7 @@ c_show()
                                setselwin(w);
                                goto out;
                        case -1:
                                setselwin(w);
                                goto out;
                        case -1:
-                               bread();
+                               wwiomux();
                                continue;
                        default:
                                wwbell();
                                continue;
                        default:
                                wwbell();
@@ -62,7 +62,7 @@ c_colon()
        if (terse)
                wwadd(cmdwin, &wwhead);
        (void) wwputc(':', cmdwin);
        if (terse)
                wwadd(cmdwin, &wwhead);
        (void) wwputc(':', cmdwin);
-       bgets(buf, wwncol - 3, cmdwin);
+       wwgets(buf, wwncol - 3, cmdwin);
        (void) wwputs("\r\n", cmdwin);
        if (terse)
                wwdelete(cmdwin);
        (void) wwputs("\r\n", cmdwin);
        if (terse)
                wwdelete(cmdwin);
index 7da6482..40a49e9 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd5.c      3.8 83/11/29";
+static char *sccsid = "@(#)cmd5.c      3.9 84/01/16";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -26,8 +26,8 @@ register struct ww *w;
                getminmax(col, w->ww_w.nc, 0, wwncol,
                        &curcol, &mincol, &maxcol);
                wwsetcursor(currow, curcol);
                getminmax(col, w->ww_w.nc, 0, wwncol,
                        &curcol, &mincol, &maxcol);
                wwsetcursor(currow, curcol);
-               while (bpeekc() < 0)
-                       bread();
+               while (wwpeekc() < 0)
+                       wwiomux();
                switch (getpos(&row, &col, minrow, mincol, maxrow, maxcol)) {
                case 3:
                        wwunbox(boxwin);
                switch (getpos(&row, &col, minrow, mincol, maxrow, maxcol)) {
                case 3:
                        wwunbox(boxwin);
index 024565c..d6a933a 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)cmd6.c      3.6 84/01/13";
+static char *sccsid = "@(#)cmd6.c      3.7 84/01/16";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -16,11 +16,11 @@ c_debug()
        if (!terse)
                (void) wwputs("[m(smap) n(ns) o(os) s(string) v(nvis) w(win)]? ", cmdwin);
        wwcurtowin(cmdwin);
        if (!terse)
                (void) wwputs("[m(smap) n(ns) o(os) s(string) v(nvis) w(win)]? ", cmdwin);
        wwcurtowin(cmdwin);
-       while (bpeekc() < 0)
-               bread();
+       while (wwpeekc() < 0)
+               wwiomux();
        if (!terse)
                (void) wwputs("\r\n", cmdwin);
        if (!terse)
                (void) wwputs("\r\n", cmdwin);
-       switch (bgetc()) {
+       switch (wwgetc()) {
        case 'm':
                wwdumpsmap();
                break;
        case 'm':
                wwdumpsmap();
                break;
index f976385..3358dca 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- *     @(#)defs.h      3.7 83/11/30    
+ *     @(#)defs.h      3.8 84/01/16    
  */
 
 #include "ww.h"
  */
 
 #include "ww.h"
 
 #define NWINDOW 9
 
 
 #define NWINDOW 9
 
-int nread;
-int nreade;
-int nreadz;
-int nreadc;
 #ifndef O_4_1A
 struct timeval starttime;
 #endif
 
 #ifndef O_4_1A
 struct timeval starttime;
 #endif
 
-       /* things for handling input */
-char ibuf[512];
-char *ibufp;
-int ibufc;
-#define bgetc()                (ibufc ? ibufc--, *ibufp++&0x7f : -1)
-#define bpeekc()       (ibufc ? *ibufp&0x7f : -1)
-#define bungetc(c)     (ibufp > ibuf ? ibufc++, *--ibufp = (c) : -1)
-
 struct ww *window[NWINDOW];    /* the windows */
 struct ww *selwin;             /* the selected window */
 struct ww *lastselwin;         /* the last selected window */
 struct ww *window[NWINDOW];    /* the windows */
 struct ww *selwin;             /* the selected window */
 struct ww *lastselwin;         /* the last selected window */
index 7ec24b0..8a7864d 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)mloop.c     3.1 83/09/02";
+static char *sccsid = "@(#)mloop.c     3.2 84/01/16";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -19,49 +19,29 @@ mloop()
                        docmd();
                        continue;
                }
                        docmd();
                        continue;
                }
-               /*
-                * Loop until we get some keyboard input.
-                */
-               while (ibufc == 0) {
+               while (wwibc == 0) {
                        wwcurtowin(selwin);
                        wwcurtowin(selwin);
-                       wwupdate();
-                       wwflush();
-                       while (imask = 1, wwforce(&imask) < 0)
-                               ;
-                       if ((imask & 1) == 0)
-                               continue;
-                       /* NOTE: ibufc == 0 */
-                       ibufp = ibuf;
-                       /* may block */
-                       if ((ibufc = read(0, ibuf, sizeof ibuf)) < 0) {
-                               ibufc = 0;
-                               nreade++;
-                       } else if (ibufc == 0)
-                               nreadz++;
-                       else
-                               nreadc += ibufc;
-                       nread++;
+                       wwiomux();
                }
                /*
                 * Weird loop.  Copy the buffer to the pty
                 * and stopping on the escape character
                 * in a hopefully efficient way.
                }
                /*
                 * Weird loop.  Copy the buffer to the pty
                 * and stopping on the escape character
                 * in a hopefully efficient way.
-                * Probably a good thing to make ibufc == 1 a special
+                * Probably a good thing to make wwibc == 1 a special
                 * case.
                 */
                 * case.
                 */
-               for (p = ibufp, n = ibufc;;) {
+               for (p = wwibp, n = wwibc;;) {
                        if (--n < 0) {
                        if (--n < 0) {
-                               (void) write(selwin->ww_pty, ibufp, ibufc);
-                               ibufp = ibuf;
-                               ibufc = 0;
+                               (void) write(selwin->ww_pty, wwibp, wwibc);
+                               wwibc = 0;
                                break;
                        }
                        if (*p++ == escapec) {
                                break;
                        }
                        if (*p++ == escapec) {
-                               if ((n = p - ibufp) > 1)
+                               if ((n = p - wwibp) > 1)
                                        (void) write(selwin->ww_pty,
                                        (void) write(selwin->ww_pty,
-                                               ibufp, n - 1);
-                               ibufp = p;
-                               ibufc -= n;
+                                               wwibp, n - 1);
+                               wwibp = p;
+                               wwibc -= n;
                                incmd = 1;
                                break;
                        }
                                incmd = 1;
                                break;
                        }
index ffef6d4..45b9703 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)win.c       3.1 84/01/13";
+static char *sccsid = "@(#)win.c       3.2 84/01/16";
 #endif
 
 #include "defs.h"
 #endif
 
 #include "defs.h"
@@ -138,7 +138,7 @@ char *prompt;
        (void) wwprintf(w, "\033Y%c%c\033p%s\033q ",
                w->ww_w.nr - 1 + ' ', ' ', prompt);     /* print on last line */
        wwcurtowin(w);
        (void) wwprintf(w, "\033Y%c%c\033p%s\033q ",
                w->ww_w.nr - 1 + ' ', ' ', prompt);     /* print on last line */
        wwcurtowin(w);
-       while (bpeekc() < 0)
-               bread();
-       return bgetc();
+       while (wwpeekc() < 0)
+               wwiomux();
+       return wwgetc();
 }
 }
index 28c83de..84fcfd4 100644 (file)
@@ -1,11 +1,11 @@
 /*
 /*
- *     @(#)ww.h        3.24 84/01/11   
+ *     @(#)ww.h        3.25 84/01/16   
  */
 
 #include <stdio.h>
 #include <sgtty.h>
 
  */
 
 #include <stdio.h>
 #include <sgtty.h>
 
-#define NWW    30
+#define NWW    30              /* maximum number of windows */
 
        /* a rectangle */
 struct ww_dim {
 
        /* a rectangle */
 struct ww_dim {
@@ -51,6 +51,11 @@ struct ww {
        int ww_pty;             /* file descriptor of pty */
        int ww_pid;             /* pid of process, if WWS_HASPROC true */
        char ww_ttyname[11];    /* "/dev/ttyp?" */
        int ww_pty;             /* file descriptor of pty */
        int ww_pid;             /* pid of process, if WWS_HASPROC true */
        char ww_ttyname[11];    /* "/dev/ttyp?" */
+       char *ww_ob;            /* output buffer */
+       char *ww_obe;           /* end of ww_ob */
+       char *ww_obp;           /* current position in ww_ob */
+       int ww_obc;             /* character count */
+       char ww_stopped;        /* flow control */
 
                /* things for the user, they really don't belong here */
        char ww_center :1;      /* center the label */
 
                /* things for the user, they really don't belong here */
        char ww_center :1;      /* center the label */
@@ -132,10 +137,12 @@ union ww_char {
 #define WWU_TOUCHED    0x01            /* touched */
 #define WWU_MAJOR      0x02            /* major change */
 
 #define WWU_TOUCHED    0x01            /* touched */
 #define WWU_MAJOR      0x02            /* major change */
 
+       /* the window structures */
 struct ww wwhead;
 struct ww *wwindex[NWW + 1];           /* last location is for wwnobody */
 struct ww wwnobody;
 
 struct ww wwhead;
 struct ww *wwindex[NWW + 1];           /* last location is for wwnobody */
 struct ww wwnobody;
 
+       /* tty things */
 struct ww_tty wwoldtty;                /* the old (saved) terminal settings */
 struct ww_tty wwnewtty;                /* the new (current) terminal settings */
 struct ww_tty wwwintty;                /* the terminal settings for windows */
 struct ww_tty wwoldtty;                /* the old (saved) terminal settings */
 struct ww_tty wwnewtty;                /* the new (current) terminal settings */
 struct ww_tty wwwintty;                /* the terminal settings for windows */
@@ -143,6 +150,7 @@ char *wwterm;                       /* the terminal name */
 char wwtermcap[1024];          /* place for the termcap */
 char wwkeys[512];              /* termcap fields for the function keys */
 
 char wwtermcap[1024];          /* place for the termcap */
 char wwkeys[512];              /* termcap fields for the function keys */
 
+       /* generally useful variables */
 int wwnrow, wwncol;            /* the screen size */
 char wwavailmodes;             /* actually supported modes */
 char wwcursormodes;            /* the modes for the fake cursor */
 int wwnrow, wwncol;            /* the screen size */
 char wwavailmodes;             /* actually supported modes */
 char wwcursormodes;            /* the modes for the fake cursor */
@@ -160,6 +168,9 @@ int wwerrno;                        /* error number */
        /* statistics */
 int wwnwrite, wwnwritec;
 int wwnupdate, wwnupdline, wwnupdmiss, wwnmajline, wwnmajmiss;
        /* statistics */
 int wwnwrite, wwnwritec;
 int wwnupdate, wwnupdline, wwnupdmiss, wwnmajline, wwnmajmiss;
+int wwnread, wwnreade, wwnreadz, wwnreadc;
+int wwnwread, wwnwreade, wwnwreadz, wwnwreadd, wwnwreadc, wwnwreadp;
+int wwnselect, wwnselecte, wwnselectz;
 
        /* quicky macros */
 #define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c))
 
        /* quicky macros */
 #define wwsetcursor(r,c) (wwcursorrow = (r), wwcursorcol = (c))
@@ -169,6 +180,15 @@ int wwnupdate, wwnupdline, wwnupdmiss, wwnmajline, wwnmajmiss;
 #define wwclreol(w,r,c)        wwclreol1((w), (r), (c), 0)
 #define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0)
 
 #define wwclreol(w,r,c)        wwclreol1((w), (r), (c), 0)
 #define wwredrawwin(w) wwredrawwin1((w), (w)->ww_i.t, (w)->ww_i.b, 0)
 
+       /* things for handling input */
+char *wwib;            /* input (keyboard) buffer */
+char *wwibe;           /* wwib + sizeof buffer */
+char *wwibp;           /* current position in buffer */
+int wwibc;             /* character count */
+#define wwgetc()       (wwibc ? wwibc--, *wwibp++&0x7f : -1)
+#define wwpeekc()      (wwibc ? *wwibp&0x7f : -1)
+#define wwungetc(c)    (wwibp > wwib ? wwibc++, *--wwibp = (c) : -1)
+
        /* the window virtual terminal */
 #define WWT_TERM       "TERM=window"
 #define WWT_TERMCAP    "WW|window|window package:\
        /* the window virtual terminal */
 #define WWT_TERM       "TERM=window"
 #define WWT_TERMCAP    "WW|window|window package:\
index 8478f8a..d7ada1a 100644 (file)
@@ -1,43 +1,10 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwgets.c    3.2 83/08/26";
+static char *sccsid = "@(#)wwgets.c    3.3 84/01/16";
 #endif
 
 #endif
 
-#include "defs.h"
+#include "ww.h"
 
 
-char *ibufp = ibuf;
-
-bread()
-{
-       register n;
-       register char *p;
-       int imask;
-
-       while (ibufc == 0) {
-               wwupdate();
-               wwflush();
-               while (imask = 1, wwforce(&imask) < 0)
-                       ;
-               if ((imask & 1) == 0)
-                       continue;
-               if (ibufc == 0) {
-                       p = ibufp = ibuf;
-                       n = sizeof ibuf;
-               } else {
-                       p = ibufp + ibufc;
-                       n = (ibuf + sizeof ibuf) - p;
-               }
-               if ((n = read(0, p, n)) > 0) {
-                       ibufc += n;
-                       nreadc += n;
-               } else if (n == 0)
-                       nreadz++;
-               else
-                       nreade++;
-               nread++;
-       }
-}
-
-bgets(buf, n, w)
+wwgets(buf, n, w)
 char *buf;
 int n;
 register struct ww *w;
 char *buf;
 int n;
 register struct ww *w;
@@ -47,8 +14,8 @@ register struct ww *w;
 
        for (;;) {
                wwcurtowin(w);
 
        for (;;) {
                wwcurtowin(w);
-               while ((c = bgetc()) < 0)
-                       bread();
+               while ((c = wwgetc()) < 0)
+                       wwiomux();
                if (c == wwoldtty.ww_sgttyb.sg_erase) {
                        if (p > buf)
                                rub(*--p, w);
                if (c == wwoldtty.ww_sgttyb.sg_erase) {
                        if (p > buf)
                                rub(*--p, w);
@@ -75,6 +42,7 @@ register struct ww *w;
        *p = 0;
 }
 
        *p = 0;
 }
 
+static
 rub(c, w)
 struct ww *w;
 {
 rub(c, w)
 struct ww *w;
 {
index 785b3d9..8543cb0 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwinit.c    3.13 83/12/17";
+static char *sccsid = "@(#)wwinit.c    3.14 84/01/16";
 #endif
 
 #include "ww.h"
 #endif
 
 #include "ww.h"
@@ -58,6 +58,12 @@ wwinit()
        else if (wwavailmodes & WWM_UL)
                wwcursormodes = WWM_UL;
 
        else if (wwavailmodes & WWM_UL)
                wwcursormodes = WWM_UL;
 
+       if ((wwib = malloc((unsigned) 512)) == 0)
+               goto bad;
+       wwibe = wwib + 512;
+       wwibp = wwib;
+       wwibc = 0;
+
        if ((wwsmap = wwalloc(0, 0, wwnrow, wwncol, sizeof (char))) == 0)
                goto bad;
        for (i = 0; i < wwnrow; i++)
        if ((wwsmap = wwalloc(0, 0, wwnrow, wwncol, sizeof (char))) == 0)
                goto bad;
        for (i = 0; i < wwnrow; i++)
index 93ecf4f..f4959b4 100644 (file)
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwiomux.c   3.6 84/01/13";
+static char *sccsid = "@(#)wwiomux.c   3.7 84/01/16";
 #endif
 
 #include "ww.h"
 #endif
 
 #include "ww.h"
+#include <sys/time.h>
 
 
-wwforce(imask)
-register int *imask;
+/*
+ * Multiple window IO handler.
+ */
+wwiomux()
 {
 {
-       register struct ww **w;
-       char buf[512];
-       register int n;
+       register struct ww *w;
+       int imask;
+       char dont_block;
+       register char *p;
+       register n;
+       char c;
+       static struct timeval tv = { 0, 0 };
 
 
-       for (w = wwindex; w < &wwindex[NWW]; w++)
-               if (*w && (*w)->ww_pty >= 0)
-                       *imask |= 1 << (*w)->ww_pty;
-       if (*imask == 0)
-               return -1;
-       (void) fflush(stdout);
-       n = select(wwdtablesize, imask, (int *)0, (int *)0,
-               (struct timeval *)0);
-       if (n <= 0)
-               return -1;
-       for (w = wwindex; w < &wwindex[NWW]; w++)
-               if (*w && (*w)->ww_pty >= 0 && *imask & 1 << (*w)->ww_pty) {
-                       n = read((*w)->ww_pty, buf, sizeof buf);
-                       if (n < 0) {
-                               (void) close((*w)->ww_pty);
-                               (*w)->ww_pty = -1;
-                       } else if (n > 0)
-                               (void) wwwrite(*w, buf, n);
+loop:
+       imask = 1;
+       dont_block = 0;
+       for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) {
+               if (w->ww_pty < 0)
+                       continue;
+               if (w->ww_obp + w->ww_obc < w->ww_obe)
+                       imask |= 1 << w->ww_pty;
+               if (w->ww_obc != 0 && !w->ww_stopped)
+                       dont_block = 1;
+       }
+       if (!dont_block) {
+               wwupdate();
+               wwflush();
+       }
+       wwnselect++;
+       n = select(wwdtablesize, &imask, (int *)0, (int *)0,
+               dont_block ? &tv : (struct timeval *)0);
+       if (n < 0)
+               wwnselecte++;
+       else if (imask & 1) {
+               if (wwibc == 0)
+                       p = wwibp = wwib;
+               else
+                       p = wwibp + wwibc;
+               n = wwibe - p;
+               wwnread++;
+               if ((n = read(0, p, n)) > 0) {
+                       wwibc += n;
+                       wwnreadc += n;
+               } else if (n == 0)
+                       wwnreadz++;
+               else
+                       wwnreade++;
+       } else if (imask != 0 || dont_block) {
+               char first_time = 1;
+               if (n == 0)
+                       wwnselectz++;
+               for (w = wwhead.ww_forw; w != &wwhead; w = w->ww_forw) {
+                       if (w->ww_pty < 0)
+                               continue;
+                       if (imask & 1 << w->ww_pty) {
+                               wwnwread++;
+                               p = w->ww_obp + w->ww_obc;
+                               if (p == w->ww_ob)
+                                       w->ww_obp++;
+                               else
+                                       p--;
+                               c = *p;
+                               n = read(w->ww_pty, p, w->ww_obe - p);
+                               if (n < 0) {
+                                       wwnwreade++;
+                                       (void) close(w->ww_pty);
+                                       w->ww_pty = -1;
+                                       continue;
+                               } else if (n == 0) {
+                                       wwnwreadz++;
+                               } else if (*p == TIOCPKT_DATA) {
+                                       wwnwreadd++;
+                                       wwnwreadc += n - 1;
+                                       w->ww_obc += n - 1;
+                               } else {
+                                       wwnwreadp++;
+                                       if (*p & TIOCPKT_STOP)
+                                               w->ww_stopped = 1;
+                                       if (*p & TIOCPKT_START)
+                                               w->ww_stopped = 0;
+                                       if (*p & TIOCPKT_FLUSHWRITE) {
+                                               w->ww_obp = w->ww_ob;
+                                               w->ww_obc = 0;
+                                               w->ww_stopped = 0;
+                                       }
+                               }
+                               *p = c;
+                       }
+                       if (first_time && w->ww_obc != 0 && !w->ww_stopped) {
+                               first_time = 0;
+                               /* XXX */
+                               n = wwwrite(w, w->ww_obp, MIN(w->ww_obc, 50));
+                               if (w->ww_obc -= n)
+                                       w->ww_obp += n;
+                               else
+                                       w->ww_obp = w->ww_ob;
+                       }
                }
                }
-       return 0;
+       }
 }
 }
index bb81230..7ff4446 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwopen.c    3.14 83/12/01";
+static char *sccsid = "@(#)wwopen.c    3.15 84/01/16";
 #endif
 
 #include "ww.h"
 #endif
 
 #include "ww.h"
@@ -59,6 +59,10 @@ wwopen(flags, nrow, ncol, row, col, nline)
                        goto bad;
                if (wwsettty(w->ww_pty, &wwwintty) < 0)
                        goto bad;
                        goto bad;
                if (wwsettty(w->ww_pty, &wwwintty) < 0)
                        goto bad;
+               if ((w->ww_ob = malloc(512)) == 0)
+                       goto bad;
+               w->ww_obe = w->ww_ob + 512;
+               w->ww_obp = w->ww_ob;
        }
 
        w->ww_win = wwalloc(w->ww_w.t, w->ww_w.l,
        }
 
        w->ww_win = wwalloc(w->ww_w.t, w->ww_w.l,
@@ -115,6 +119,8 @@ bad:
                        wwfree((char **)w->ww_buf, w->ww_b.t);
                if (w->ww_nvis != 0)
                        free((char *)(w->ww_nvis + w->ww_w.t));
                        wwfree((char **)w->ww_buf, w->ww_b.t);
                if (w->ww_nvis != 0)
                        free((char *)(w->ww_nvis + w->ww_w.t));
+               if (w->ww_ob != 0)
+                       free(w->ww_ob);
                (void) close(w->ww_pty);
                free((char *)w);
        }
                (void) close(w->ww_pty);
                free((char *)w);
        }
index 386cc5a..4832a77 100644 (file)
@@ -1,5 +1,5 @@
 #ifndef lint
 #ifndef lint
-static char *sccsid = "@(#)wwpty.c     3.5 83/12/08";
+static char *sccsid = "@(#)wwpty.c     3.6 84/01/16";
 #endif
 
 #include "ww.h"
 #endif
 
 #include "ww.h"
@@ -10,6 +10,7 @@ register struct ww *w;
        register char c;
        register int i;
        int tty;
        register char c;
        register int i;
        int tty;
+       int on = 1;
 #define PTY "/dev/XtyXX"
 #define _PT    5
 #define _PQRS  8
 #define PTY "/dev/XtyXX"
 #define _PT    5
 #define _PQRS  8
@@ -33,6 +34,10 @@ register struct ww *w;
                                continue;
                        }
                        (void) close(tty);
                                continue;
                        }
                        (void) close(tty);
+                       if (ioctl(w->ww_pty, (int)TIOCPKT, &on) < 0) {
+                               (void) close(w->ww_pty);
+                               continue;
+                       }
                        return 0;
                }
        }
                        return 0;
                }
        }