From 8fa6d94c226ba0c6e3df519508bca32fdf58fdb5 Mon Sep 17 00:00:00 2001 From: Edward Wang Date: Mon, 16 Jan 1984 23:26:32 -0800 Subject: [PATCH] new io scheme 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 --- usr/src/usr.bin/window/:ww | 5 +- usr/src/usr.bin/window/cmd.c | 12 +-- usr/src/usr.bin/window/cmd1.c | 12 +-- usr/src/usr.bin/window/cmd2.c | 26 ++++--- usr/src/usr.bin/window/cmd4.c | 8 +- usr/src/usr.bin/window/cmd5.c | 6 +- usr/src/usr.bin/window/cmd6.c | 8 +- usr/src/usr.bin/window/defs.h | 14 +--- usr/src/usr.bin/window/mloop.c | 42 +++-------- usr/src/usr.bin/window/win.c | 8 +- usr/src/usr.bin/window/ww.h | 24 +++++- usr/src/usr.bin/window/wwgets.c | 44 ++--------- usr/src/usr.bin/window/wwinit.c | 8 +- usr/src/usr.bin/window/wwiomux.c | 123 ++++++++++++++++++++++++------- usr/src/usr.bin/window/wwopen.c | 8 +- usr/src/usr.bin/window/wwpty.c | 7 +- 16 files changed, 204 insertions(+), 151 deletions(-) diff --git a/usr/src/usr.bin/window/:ww b/usr/src/usr.bin/window/:ww index 902e859b89..7bc504c452 100644 --- a/usr/src/usr.bin/window/:ww +++ b/usr/src/usr.bin/window/:ww @@ -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 -+/"pty"16t"pid"16t"ttyname"nDD11C -+/t ++/"pty"16t"pid"16t"ttyname"nDD11C+ ++/"ob"16t"obe"16t"obp"16t"obc"n3pD ++/"stopped"nb diff --git a/usr/src/usr.bin/window/cmd.c b/usr/src/usr.bin/window/cmd.c index 91009b40de..be1fe37fb0 100644 --- a/usr/src/usr.bin/window/cmd.c +++ b/usr/src/usr.bin/window/cmd.c @@ -1,5 +1,5 @@ #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" @@ -14,7 +14,7 @@ docmd() if (selwin != 0) wwcursor(selwin, 1); for (;;) { - while ((c = bgetc()) >= 0) { + while ((c = wwgetc()) >= 0) { if (!terse) (void) wwputs("\r\n", cmdwin); switch (c) { @@ -186,8 +186,8 @@ docmd() (void) wwputs("Command: ", cmdwin); wwcurtowin(cmdwin); } - while (bpeekc() < 0) - bread(); + while (wwpeekc() < 0) + wwiomux(); } if (!quit) { if (!terse) { @@ -207,8 +207,8 @@ getwin() 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') diff --git a/usr/src/usr.bin/window/cmd1.c b/usr/src/usr.bin/window/cmd1.c index 5beb4e7375..2e22b063e4 100644 --- a/usr/src/usr.bin/window/cmd1.c +++ b/usr/src/usr.bin/window/cmd1.c @@ -1,5 +1,5 @@ #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" @@ -19,8 +19,8 @@ c_window() 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: @@ -46,8 +46,8 @@ c_window() 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: @@ -82,7 +82,7 @@ int maxrow, maxcol; 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': diff --git a/usr/src/usr.bin/window/cmd2.c b/usr/src/usr.bin/window/cmd2.c index fe28a6118d..d1ea784012 100644 --- a/usr/src/usr.bin/window/cmd2.c +++ b/usr/src/usr.bin/window/cmd2.c @@ -1,5 +1,5 @@ #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" @@ -157,16 +157,22 @@ c_stat() { 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; } - (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); + (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); } @@ -208,9 +214,9 @@ c_quit() 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 diff --git a/usr/src/usr.bin/window/cmd4.c b/usr/src/usr.bin/window/cmd4.c index 3ad5282873..fe84f290a0 100644 --- a/usr/src/usr.bin/window/cmd4.c +++ b/usr/src/usr.bin/window/cmd4.c @@ -1,5 +1,5 @@ #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" @@ -21,7 +21,7 @@ c_show() front(w, 0); wwsetcursor(w->ww_w.t - 1, w->ww_w.l + 1); for (;;) { - switch (bgetc()) { + switch (wwgetc()) { case '\r': case '\n': break; @@ -29,7 +29,7 @@ c_show() setselwin(w); goto out; case -1: - bread(); + wwiomux(); continue; default: wwbell(); @@ -62,7 +62,7 @@ c_colon() 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); diff --git a/usr/src/usr.bin/window/cmd5.c b/usr/src/usr.bin/window/cmd5.c index 7da64829cc..40a49e9602 100644 --- a/usr/src/usr.bin/window/cmd5.c +++ b/usr/src/usr.bin/window/cmd5.c @@ -1,5 +1,5 @@ #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" @@ -26,8 +26,8 @@ register struct ww *w; 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); diff --git a/usr/src/usr.bin/window/cmd6.c b/usr/src/usr.bin/window/cmd6.c index 024565cb9e..d6a933ac0d 100644 --- a/usr/src/usr.bin/window/cmd6.c +++ b/usr/src/usr.bin/window/cmd6.c @@ -1,5 +1,5 @@ #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" @@ -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); - while (bpeekc() < 0) - bread(); + while (wwpeekc() < 0) + wwiomux(); if (!terse) (void) wwputs("\r\n", cmdwin); - switch (bgetc()) { + switch (wwgetc()) { case 'm': wwdumpsmap(); break; diff --git a/usr/src/usr.bin/window/defs.h b/usr/src/usr.bin/window/defs.h index f976385687..3358dca47b 100644 --- a/usr/src/usr.bin/window/defs.h +++ b/usr/src/usr.bin/window/defs.h @@ -1,5 +1,5 @@ /* - * @(#)defs.h 3.7 83/11/30 + * @(#)defs.h 3.8 84/01/16 */ #include "ww.h" @@ -11,22 +11,10 @@ #define NWINDOW 9 -int nread; -int nreade; -int nreadz; -int nreadc; #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 */ diff --git a/usr/src/usr.bin/window/mloop.c b/usr/src/usr.bin/window/mloop.c index 7ec24b00b8..8a7864d0d0 100644 --- a/usr/src/usr.bin/window/mloop.c +++ b/usr/src/usr.bin/window/mloop.c @@ -1,5 +1,5 @@ #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" @@ -19,49 +19,29 @@ mloop() docmd(); continue; } - /* - * Loop until we get some keyboard input. - */ - while (ibufc == 0) { + while (wwibc == 0) { 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. - * Probably a good thing to make ibufc == 1 a special + * Probably a good thing to make wwibc == 1 a special * case. */ - for (p = ibufp, n = ibufc;;) { + for (p = wwibp, n = wwibc;;) { 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) { - if ((n = p - ibufp) > 1) + if ((n = p - wwibp) > 1) (void) write(selwin->ww_pty, - ibufp, n - 1); - ibufp = p; - ibufc -= n; + wwibp, n - 1); + wwibp = p; + wwibc -= n; incmd = 1; break; } diff --git a/usr/src/usr.bin/window/win.c b/usr/src/usr.bin/window/win.c index ffef6d4ec9..45b9703bd1 100644 --- a/usr/src/usr.bin/window/win.c +++ b/usr/src/usr.bin/window/win.c @@ -1,5 +1,5 @@ #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" @@ -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); - while (bpeekc() < 0) - bread(); - return bgetc(); + while (wwpeekc() < 0) + wwiomux(); + return wwgetc(); } diff --git a/usr/src/usr.bin/window/ww.h b/usr/src/usr.bin/window/ww.h index 28c83de174..84fcfd43cc 100644 --- a/usr/src/usr.bin/window/ww.h +++ b/usr/src/usr.bin/window/ww.h @@ -1,11 +1,11 @@ /* - * @(#)ww.h 3.24 84/01/11 + * @(#)ww.h 3.25 84/01/16 */ #include #include -#define NWW 30 +#define NWW 30 /* maximum number of windows */ /* 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?" */ + 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 */ @@ -132,10 +137,12 @@ union ww_char { #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; + /* 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 */ @@ -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 */ + /* generally useful variables */ 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; +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)) @@ -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) + /* 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:\ diff --git a/usr/src/usr.bin/window/wwgets.c b/usr/src/usr.bin/window/wwgets.c index 8478f8ac69..d7ada1a422 100644 --- a/usr/src/usr.bin/window/wwgets.c +++ b/usr/src/usr.bin/window/wwgets.c @@ -1,43 +1,10 @@ #ifndef lint -static char *sccsid = "@(#)wwgets.c 3.2 83/08/26"; +static char *sccsid = "@(#)wwgets.c 3.3 84/01/16"; #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; @@ -47,8 +14,8 @@ register struct ww *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); @@ -75,6 +42,7 @@ register struct ww *w; *p = 0; } +static rub(c, w) struct ww *w; { diff --git a/usr/src/usr.bin/window/wwinit.c b/usr/src/usr.bin/window/wwinit.c index 785b3d96ae..8543cb0c1f 100644 --- a/usr/src/usr.bin/window/wwinit.c +++ b/usr/src/usr.bin/window/wwinit.c @@ -1,5 +1,5 @@ #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" @@ -58,6 +58,12 @@ wwinit() 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++) diff --git a/usr/src/usr.bin/window/wwiomux.c b/usr/src/usr.bin/window/wwiomux.c index 93ecf4fc9e..f4959b45ee 100644 --- a/usr/src/usr.bin/window/wwiomux.c +++ b/usr/src/usr.bin/window/wwiomux.c @@ -1,34 +1,107 @@ #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" +#include -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; + } } diff --git a/usr/src/usr.bin/window/wwopen.c b/usr/src/usr.bin/window/wwopen.c index bb81230d78..7ff4446962 100644 --- a/usr/src/usr.bin/window/wwopen.c +++ b/usr/src/usr.bin/window/wwopen.c @@ -1,5 +1,5 @@ #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" @@ -59,6 +59,10 @@ wwopen(flags, nrow, ncol, row, col, nline) 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, @@ -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)); + if (w->ww_ob != 0) + free(w->ww_ob); (void) close(w->ww_pty); free((char *)w); } diff --git a/usr/src/usr.bin/window/wwpty.c b/usr/src/usr.bin/window/wwpty.c index 386cc5abcd..4832a779d7 100644 --- a/usr/src/usr.bin/window/wwpty.c +++ b/usr/src/usr.bin/window/wwpty.c @@ -1,5 +1,5 @@ #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" @@ -10,6 +10,7 @@ register struct ww *w; register char c; register int i; int tty; + int on = 1; #define PTY "/dev/XtyXX" #define _PT 5 #define _PQRS 8 @@ -33,6 +34,10 @@ register struct ww *w; continue; } (void) close(tty); + if (ioctl(w->ww_pty, (int)TIOCPKT, &on) < 0) { + (void) close(w->ww_pty); + continue; + } return 0; } } -- 2.20.1