data compression and some other stuff
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Thu, 3 Aug 1989 10:13:19 +0000 (02:13 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Thu, 3 Aug 1989 10:13:19 +0000 (02:13 -0800)
SCCS-vsn: usr.bin/window/main.c 3.37
SCCS-vsn: usr.bin/window/lcmd2.c 3.18
SCCS-vsn: usr.bin/window/ttgeneric.c 3.39
SCCS-vsn: usr.bin/window/tth19.c 3.21
SCCS-vsn: usr.bin/window/wwsuspend.c 3.10
SCCS-vsn: usr.bin/window/wwflush.c 3.10
SCCS-vsn: usr.bin/window/wwredraw.c 3.11
SCCS-vsn: usr.bin/window/tt.h 3.22
SCCS-vsn: usr.bin/window/wwend.c 3.13
SCCS-vsn: usr.bin/window/ww.h 3.54
SCCS-vsn: usr.bin/window/wwupdate.c 3.25
SCCS-vsn: usr.bin/window/wwwrite.c 3.29
SCCS-vsn: usr.bin/window/wwinit.c 3.34
SCCS-vsn: usr.bin/window/Makefile 5.5
SCCS-vsn: usr.bin/window/mloop.c 3.14
SCCS-vsn: usr.bin/window/ttzapple.c 3.3

16 files changed:
usr/src/usr.bin/window/Makefile
usr/src/usr.bin/window/lcmd2.c
usr/src/usr.bin/window/main.c
usr/src/usr.bin/window/mloop.c
usr/src/usr.bin/window/tt.h
usr/src/usr.bin/window/ttgeneric.c
usr/src/usr.bin/window/tth19.c
usr/src/usr.bin/window/ttzapple.c
usr/src/usr.bin/window/ww.h
usr/src/usr.bin/window/wwend.c
usr/src/usr.bin/window/wwflush.c
usr/src/usr.bin/window/wwinit.c
usr/src/usr.bin/window/wwredraw.c
usr/src/usr.bin/window/wwsuspend.c
usr/src/usr.bin/window/wwupdate.c
usr/src/usr.bin/window/wwwrite.c

index 66e327c..88284ce 100644 (file)
@@ -14,7 +14,7 @@
 # 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.
 #
-#      @(#)Makefile    5.4 (Berkeley) %G%
+#      @(#)Makefile    5.5 (Berkeley) %G%
 #
 CFLAGS=        -O -R
 LIBC=  /lib/libc.a
 #
 CFLAGS=        -O -R
 LIBC=  /lib/libc.a
@@ -30,7 +30,7 @@ SRCS= char.c cmd.c cmd1.c cmd2.c cmd3.c cmd4.c cmd5.c cmd6.c cmd7.c \
        wwiomux.c wwlabel.c wwmisc.c wwmove.c wwopen.c wwprintf.c wwpty.c \
        wwputc.c wwputs.c wwredraw.c wwredrawwin.c wwrint.c wwscroll.c \
        wwsize.c wwspawn.c wwsuspend.c wwtty.c wwunframe.c wwupdate.c \
        wwiomux.c wwlabel.c wwmisc.c wwmove.c wwopen.c wwprintf.c wwpty.c \
        wwputc.c wwputs.c wwredraw.c wwredrawwin.c wwrint.c wwscroll.c \
        wwsize.c wwspawn.c wwsuspend.c wwtty.c wwunframe.c wwupdate.c \
-       wwwrite.c xx.c
+       wwwrite.c xx.c xxcompress.c xxflush.c
 OBJS=  char.o cmd.o cmd1.o cmd2.o cmd3.o cmd4.o cmd5.o cmd6.o cmd7.o \
        context.o error.o lcmd.o lcmd1.o lcmd2.o main.o mloop.o parser1.o \
        parser2.o parser3.o parser4.o parser5.o scanner.o startup.o string.o \
 OBJS=  char.o cmd.o cmd1.o cmd2.o cmd3.o cmd4.o cmd5.o cmd6.o cmd7.o \
        context.o error.o lcmd.o lcmd1.o lcmd2.o main.o mloop.o parser1.o \
        parser2.o parser3.o parser4.o parser5.o scanner.o startup.o string.o \
@@ -43,7 +43,7 @@ OBJS= char.o cmd.o cmd1.o cmd2.o cmd3.o cmd4.o cmd5.o cmd6.o cmd7.o \
        wwiomux.o wwlabel.o wwmisc.o wwmove.o wwopen.o wwprintf.o wwpty.o \
        wwputc.o wwputs.o wwredraw.o wwredrawwin.o wwrint.o wwscroll.o \
        wwsize.o wwspawn.o wwsuspend.o wwtty.o wwunframe.o wwupdate.o \
        wwiomux.o wwlabel.o wwmisc.o wwmove.o wwopen.o wwprintf.o wwpty.o \
        wwputc.o wwputs.o wwredraw.o wwredrawwin.o wwrint.o wwscroll.o \
        wwsize.o wwspawn.o wwsuspend.o wwtty.o wwunframe.o wwupdate.o \
-       wwwrite.o xx.o
+       wwwrite.o xx.o xxcompress.o xxflush.o
 MAN=   window.0
 
 all: window
 MAN=   window.0
 
 all: window
@@ -65,7 +65,7 @@ install: ${MAN}
        install -c -o bin -g bin -m 444 ${MAN} ${DESTDIR}/usr/man/cat1
 
 lint: ${SRCS}
        install -c -o bin -g bin -m 444 ${MAN} ${DESTDIR}/usr/man/cat1
 
 lint: ${SRCS}
-       lint ${CFLAGS} ${SRCS}
+       lint ${CFLAGS} -z ${SRCS}
 
 tags: ${SRCS}
        ctags ${SRCS}
 
 tags: ${SRCS}
        ctags ${SRCS}
index 9f1df38..e5c3ea0 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)lcmd2.c    3.17 (Berkeley) %G%";
+static char sccsid[] = "@(#)lcmd2.c    3.18 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "defs.h"
 #endif /* not lint */
 
 #include "defs.h"
@@ -42,10 +42,14 @@ struct value *v, *a;
                wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc);
        wwprintf(w, "token\tuse\tsaving\ttotal\tbaud\n");
        wwprintf(w, "%d\t%d\t%d\t%d\t%d/%d\n",
                wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc);
        wwprintf(w, "token\tuse\tsaving\ttotal\tbaud\n");
        wwprintf(w, "%d\t%d\t%d\t%d\t%d/%d\n",
-               wwzc0, wwzc1, wwzcsave, wwzctotal,
-               wwzctotal - wwzcsave ?
-                       wwbaud * wwzctotal / (wwzctotal - wwzcsave) : wwbaud,
-               wwnwrc ? wwbaud * (wwnwrc + wwzcsave) / wwnwrc : wwbaud);
+               wwntokdef, wwntokuse, wwntoksave, wwntokc,
+               wwntokc - wwntoksave ?
+                       (int) ((float) wwbaud * wwntokc /
+                                       (wwntokc - wwntoksave)) :
+                       wwbaud,
+               wwnwrc ? (int) ((float) wwbaud * (wwnwrc + wwntoksave) /
+                                       wwnwrc) :
+                       wwbaud);
        wwprintf(w, "wwwrite\tattempt\tchar\n");
        wwprintf(w, "%d\t%d\t%d\n",
                wwnwwr, wwnwwra, wwnwwrc);
        wwprintf(w, "wwwrite\tattempt\tchar\n");
        wwprintf(w, "%d\t%d\t%d\n",
                wwnwwr, wwnwwra, wwnwwrc);
index a6cde96..13e5453 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     3.36 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     3.37 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "defs.h"
 #endif /* not lint */
 
 #include "defs.h"
@@ -109,7 +109,7 @@ char **argv;
 
        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) {
-               (void) wwflush();
+               wwflush();
                (void) fprintf(stderr, "%s.\r\n", wwerror());
                goto bad;
        }
                (void) fprintf(stderr, "%s.\r\n", wwerror());
                goto bad;
        }
@@ -119,13 +119,13 @@ char **argv;
        cmdwin->ww_unctrl = 1;
        if ((framewin = wwopen(WWO_GLASS|WWO_FRAME, wwnrow, wwncol, 0, 0, 0))
            == 0) {
        cmdwin->ww_unctrl = 1;
        if ((framewin = wwopen(WWO_GLASS|WWO_FRAME, wwnrow, wwncol, 0, 0, 0))
            == 0) {
-               (void) wwflush();
+               wwflush();
                (void) fprintf(stderr, "%s.\r\n", wwerror());
                goto bad;
        }
        wwadd(framewin, &wwhead);
        if ((boxwin = wwopen(WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) == 0) {
                (void) fprintf(stderr, "%s.\r\n", wwerror());
                goto bad;
        }
        wwadd(framewin, &wwhead);
        if ((boxwin = wwopen(WWO_GLASS, wwnrow, wwncol, 0, 0, 0)) == 0) {
-               (void) wwflush();
+               wwflush();
                (void) fprintf(stderr, "%s.\r\n", wwerror());
                goto bad;
        }
                (void) fprintf(stderr, "%s.\r\n", wwerror());
                goto bad;
        }
@@ -133,7 +133,6 @@ char **argv;
 
        wwupdate();
        wwflush();
 
        wwupdate();
        wwflush();
-       (void) signal(SIGCHLD, wwchild);
        setvars();
 
        setterse(tflag);
        setvars();
 
        setterse(tflag);
index d64962a..c671ba2 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)mloop.c    3.13 (Berkeley) %G%";
+static char sccsid[] = "@(#)mloop.c    3.14 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "defs.h"
 #endif /* not lint */
 
 #include "defs.h"
@@ -24,7 +24,6 @@ static char sccsid[] = "@(#)mloop.c   3.13 (Berkeley) %G%";
 
 mloop()
 {
 
 mloop()
 {
-       kill(getpid(), SIGIO);  /* catch typeahead before ASYNC was set */
        while (!quit) {
                if (incmd) {
                        docmd();
        while (!quit) {
                if (incmd) {
                        docmd();
index 0cae050..4b87c0a 100644 (file)
@@ -14,7 +14,7 @@
  * 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.
  *
- *     @(#)tt.h        3.21 (Berkeley) %G%
+ *     @(#)tt.h        3.22 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -22,7 +22,7 @@
  */
 struct tt {
                /* startup and cleanup */
  */
 struct tt {
                /* startup and cleanup */
-       int (*tt_init)();
+       int (*tt_start)();
        int (*tt_end)();
 
                /* terminal functions */
        int (*tt_end)();
 
                /* terminal functions */
@@ -41,6 +41,8 @@ struct tt {
        int (*tt_setscroll)();          /* set scrolling region */
        int (*tt_setinsert)();          /* set insert mode */
        int (*tt_setmodes)();           /* set display modes */
        int (*tt_setscroll)();          /* set scrolling region */
        int (*tt_setinsert)();          /* set insert mode */
        int (*tt_setmodes)();           /* set display modes */
+       int (*tt_set_token)();          /* define a token */
+       int (*tt_put_token)();          /* refer to a defined token */
 
                /* internal variables */
        char tt_modes;                  /* the current display modes */
 
                /* internal variables */
        char tt_modes;                  /* the current display modes */
@@ -58,6 +60,11 @@ struct tt {
        char tt_availmodes;             /* the display modes supported */
        char tt_wrap;                   /* has auto wrap around */
        char tt_retain;                 /* can retain below (db flag) */
        char tt_availmodes;             /* the display modes supported */
        char tt_wrap;                   /* has auto wrap around */
        char tt_retain;                 /* can retain below (db flag) */
+       int tt_ntoken;                  /* number of compression tokens */
+       int tt_token_min;               /* minimun token size */
+       int tt_token_max;               /* maximum token size */
+       int tt_set_token_cost;          /* cost in addition to string */
+       int tt_put_token_cost;          /* constant cost */
 
                /* the frame characters */
        short *tt_frame;
 
                /* the frame characters */
        short *tt_frame;
index 390f06d..0256ee6 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ttgeneric.c        3.38 (Berkeley) %G%";
+static char sccsid[] = "@(#)ttgeneric.c        3.39 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -278,7 +278,7 @@ out:
        tt.tt_row = row;
 }
 
        tt.tt_row = row;
 }
 
-gen_init()
+gen_start()
 {
        if (gen_VS)
                ttxputs(gen_VS);
 {
        if (gen_VS)
                ttxputs(gen_VS);
@@ -500,7 +500,7 @@ tt_generic()
        tt.tt_retain = gen_DB;
        tt.tt_ncol = gen_CO;
        tt.tt_nrow = gen_LI;
        tt.tt_retain = gen_DB;
        tt.tt_ncol = gen_CO;
        tt.tt_nrow = gen_LI;
-       tt.tt_init = gen_init;
+       tt.tt_start = gen_start;
        tt.tt_end = gen_end;
        tt.tt_write = gen_write;
        tt.tt_putc = gen_putc;
        tt.tt_end = gen_end;
        tt.tt_write = gen_write;
        tt.tt_putc = gen_putc;
index 57bcde6..2d32dd3 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)tth19.c    3.20 (Berkeley) %G%";
+static char sccsid[] = "@(#)tth19.c    3.21 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -189,7 +189,7 @@ out:
        tt.tt_row = row;
 }
 
        tt.tt_row = row;
 }
 
-h19_init()
+h19_start()
 {
        if (gen_VS)
                ttxputs(gen_VS);
 {
        if (gen_VS)
                ttxputs(gen_VS);
@@ -260,7 +260,7 @@ tt_h19()
        gen_VS = ttxgetstr("vs");
        gen_VE = ttxgetstr("ve");
 
        gen_VS = ttxgetstr("vs");
        gen_VE = ttxgetstr("ve");
 
-       tt.tt_init = h19_init;
+       tt.tt_start = h19_start;
        tt.tt_end = h19_end;
 
        tt.tt_insline = h19_insline;
        tt.tt_end = h19_end;
 
        tt.tt_insline = h19_insline;
index 10d6858..e14feba 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ttzapple.c 3.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)ttzapple.c 3.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -34,8 +34,9 @@ zz|zapple|unorthodox apple:\
        :sf=^[f:SF=^\%+ F:sr=^[r:SR=^\%+ R:cs=^]%+ %+ ?:
 */
 
        :sf=^[f:SF=^\%+ F:sr=^[r:SR=^\%+ R:cs=^]%+ %+ ?:
 */
 
-#define NCOL   80
-#define NROW   24
+#define NCOL           80
+#define NROW           24
+#define TOKEN_MAX      32
 
 #define pc(c)  ttputc(c)
 #define esc()  pc(ctrl('['))
 
 #define pc(c)  ttputc(c)
 #define esc()  pc(ctrl('['))
@@ -44,43 +45,6 @@ zz|zapple|unorthodox apple:\
 
 extern short gen_frame[];
 
 
 extern short gen_frame[];
 
-/*
- * stuff for token compression
- */
-
-#define N      4
-#define NTOKEN 128
-#define NCTOKEN        (NTOKEN * 4)
-#define H      11
-#define HSIZE  (1 << H)
-struct ctoken {
-       short index;
-       short hash;
-       unsigned long time;
-       unsigned long count;
-       char string[N];
-       struct ctoken *forw;
-       struct ctoken *back;
-};
-
-static struct ctoken q1, q2;
-static struct ctoken *htab[HSIZE];
-static struct ctoken *line[NCOL];
-static struct ctoken tokens[NTOKEN * 4];
-static unsigned long tick;
-
-#define zc_eval(t)     ((int) ((t)->count * 400 + (t)->time - tick))
-#define zc_hash(h, c)  ((((h) << 1 | (h) >> H - 1) ^ (c)) & HSIZE - 1)
-#define zc_unhash(h, c)        (((h) ^ (c) << N - 1 ^ (c) >> H - N + 1) & (HSIZE - 1))
-#define zc_copy(f, t)  bcopy(f, t, N)
-#define zc_equal(f, t) (bcmp(f, t, N) == 0)
-/*
-#define zc_copy(f, t)  ((t)[0] = (f)[0], (t)[1] = (f)[1], \
-                               (t)[2] = (f)[2], (t)[3] = (f)[3])
-#define zc_equal(f, t) ((t)[0] == (f)[0] && (t)[1] == (f)[1] && \
-                               (t)[2] == (f)[2] && (t)[3] == (f)[3])
-*/
-
 zz_setmodes(new)
 {
        if (new & WWM_REV) {
 zz_setmodes(new)
 {
        if (new & WWM_REV) {
@@ -136,10 +100,7 @@ zz_write(p, n)
 {
        if (tt.tt_nmodes != tt.tt_modes)
                zz_setmodes(tt.tt_nmodes);
 {
        if (tt.tt_nmodes != tt.tt_modes)
                zz_setmodes(tt.tt_nmodes);
-       if (n < N)
-               ttwrite(p, n);
-       else
-               zc_write(p, n);
+       ttwrite(p, n);
        tt.tt_col += n;
        if (tt.tt_col == NCOL)
                tt.tt_col = 0, tt.tt_row++;
        tt.tt_col += n;
        if (tt.tt_col == NCOL)
                tt.tt_col = 0, tt.tt_row++;
@@ -148,19 +109,31 @@ zz_write(p, n)
 zz_move(row, col)
        register row, col;
 {
 zz_move(row, col)
        register row, col;
 {
+       register x;
+
        if (tt.tt_row == row) {
        if (tt.tt_row == row) {
-               if (tt.tt_col == col)
+               if ((x = col - tt.tt_col) == 0)
                        return;
                if (col == 0) {
                        pc('\r');
                        goto out;
                }
                        return;
                if (col == 0) {
                        pc('\r');
                        goto out;
                }
-               if (tt.tt_col == col - 1) {
+               switch (x) {
+               case 2:
+                       pc(ctrl('f'));
+               case 1:
                        pc(ctrl('f'));
                        goto out;
                        pc(ctrl('f'));
                        goto out;
-               }
-               if (tt.tt_col == col + 1) {
+               case -2:
                        pc('\b');
                        pc('\b');
+               case -1:
+                       pc('\b');
+                       goto out;
+               }
+               if (col & 7 == 0 && x > 0 && x <= 16) {
+                       pc('\t');
+                       if (x > 8)
+                               pc('\t');
                        goto out;
                }
                esc1();
                        goto out;
                }
                esc1();
@@ -169,13 +142,17 @@ zz_move(row, col)
                goto out;
        }
        if (tt.tt_col == col) {
                goto out;
        }
        if (tt.tt_col == col) {
-               if (tt.tt_row == row + 1) {
-                       pc(ctrl('k'));
-                       goto out;
-               }
-               if (tt.tt_row == row - 1) {
+               switch (row - tt.tt_row) {
+               case 2:
+                       pc('\n');
+               case 1:
                        pc('\n');
                        goto out;
                        pc('\n');
                        goto out;
+               case -2:
+                       pc(ctrl('k'));
+               case -1:
+                       pc(ctrl('k'));
+                       goto out;
                }
                if (col == 0) {
                        if (row == 0)
                }
                if (col == 0) {
                        if (row == 0)
@@ -195,6 +172,11 @@ home:
                        pc('0');
                        goto out;
                }
                        pc('0');
                        goto out;
                }
+               if (row == tt.tt_row + 1) {
+                       pc('\r');
+                       pc('\n');
+                       goto out;
+               }
                if (row == NROW - 1) {
 ll:
                        esc();
                if (row == NROW - 1) {
 ll:
                        esc();
@@ -211,15 +193,14 @@ out:
        tt.tt_row = row;
 }
 
        tt.tt_row = row;
 }
 
-zz_init()
+zz_start()
 {
        zz_setmodes(0);
        zz_setscroll(0, NROW - 1);
        zz_clear();
        esc1();
 {
        zz_setmodes(0);
        zz_setscroll(0, NROW - 1);
        zz_clear();
        esc1();
-       pc(N + ' ');
+       pc(TOKEN_MAX + ' ');
        pc('T');
        pc('T');
-       zc_init();
 }
 
 zz_end()
 }
 
 zz_end()
@@ -227,7 +208,6 @@ zz_end()
        esc1();
        pc(' ');
        pc('T');
        esc1();
        pc(' ');
        pc('T');
-       pc(0);
 }
 
 zz_clreol()
 }
 
 zz_clreol()
@@ -279,7 +259,7 @@ zz_scroll_down(n)
                esc1();
                pc(n + ' ');
                pc('F');
                esc1();
                pc(n + ' ');
                pc('F');
-       } else if (tt.tt_row == tt.tt_scroll_bot)
+       } else if (tt.tt_row == NROW - 1)
                pc('\n');
        else {
                esc();
                pc('\n');
        else {
                esc();
@@ -309,149 +289,51 @@ zz_setscroll(top, bot)
        tt.tt_scroll_bot = bot;
 }
 
        tt.tt_scroll_bot = bot;
 }
 
-zc_write(s, n)
+int zz_debug = 0;
+
+zz_set_token(t, s, n)
        char *s;
        char *s;
-       register n;
 {
 {
-       register char *p;
-       register h;
-       register i;
-       register struct ctoken *tp;
-
-       p = s;
-       for (i = N - 2, h = zc_hash(0, *p++); --i >= 0; h = zc_hash(h, *p++))
-               ;
-       for (i = 0;;) {
-               tick++;
-               h = zc_hash(h, *p++);
-               if ((tp = htab[h]) == 0) {
-                       tp = q2.back;
-                       if (tp->hash >= 0)
-                               htab[tp->hash] = 0;
-                       zc_copy(p - N, tp->string);
-                       tp->hash = h;
-                       tp->count = 0;
-                       htab[h] = tp;
-               } else if (!zc_equal(tp->string, p - N)) {
-                       if (tp->index == 0 && zc_eval(tp) < 0) {
-                               zc_copy(p - N, tp->string);
-                               tp->count = 0;
-                       } else {
-                               line[i] = 0;
-                               goto cont;
-                       }
-               }
-               tp->time = tick;
-               tp->count++;
-               if (tp->index == 0)
-                       zc_head(tp, &q2);
-               else
-                       zc_head(tp, &q1);
-               line[i] = tp;
-       cont:
-               if (++i > n - N)
-                       break;
-               h = zc_unhash(h, p[- N]);
-       }
-       while (i < n)
-               line[i++] = 0;
-       for (i = 0; i < n;) {
-               register struct ctoken *tp;
-
-               if ((tp = line[i]) == 0) {
-                       pc(s[i]);
-                       i++;
-               } else if (tp->index > 0) {
-                       zc_head(tp, &q1);
-                       pc(tp->index - 1 | 0x80);
-                       wwzc1++;
-                       wwzcsave += N - 1;
-                       i += N;
-               } else if (tp->index < 0) {
-                       tp->index = - tp->index;
-                       zc_head(tp, &q1);
-                       pc(ctrl('^'));
-                       pc(tp->index - 1);
-                       ttwrite(tp->string, N);
-                       wwzc0++;
-                       wwzcsave -= 2;
-                       i += N;
-               } else if (tp->count > 1 && zc_eval(tp) > zc_eval(q1.back)) {
-                       tp->index = abs(q1.back->index);
-                       q1.back->index = 0;
-                       zc_head(q1.back, &q2);
-                       zc_head(tp, &q1);
-                       pc(ctrl('^'));
-                       pc(tp->index - 1);
-                       ttwrite(tp->string, N);
-                       wwzc0++;
-                       wwzcsave -= 2;
-                       i += N;
-               } else {
-                       pc(s[i]);
-                       i++;
-               }
+       if (tt.tt_nmodes != tt.tt_modes)
+               zz_setmodes(tt.tt_nmodes);
+       if (zz_debug) {
+               char buf[100];
+               zz_setmodes(WWM_REV);
+               (void) sprintf(buf, "%02x=", t);
+               ttputs(buf);
+               tt.tt_col += 3;
        }
        }
-       wwzctotal += n;
-}
-
-zc_head(tp, q)
-       register struct ctoken *tp, *q;
-{
-
-       tp->back->forw = tp->forw;
-       tp->forw->back = tp->back;
-       q->forw->back = tp;
-       tp->forw = q->forw;
-       q->forw = tp;
-       tp->back = q;
-}
-
-zc_init()
-{
-       register struct ctoken *tp;
-
-       for (tp = tokens; tp < tokens + sizeof tokens / sizeof *tokens; tp++)
-               if (tp->index > 0)
-                       tp->index = - tp->index;
+       pc(ctrl('^'));
+       pc(t);
+       s[n - 1] |= 0x80;
+       ttwrite(s, n);
+       s[n - 1] &= ~0x80;
+       tt.tt_col += n;
+       if (tt.tt_col == NCOL)
+               tt.tt_col = 0, tt.tt_row++;
 }
 
 }
 
-zc_start()
+/*ARGSUSED*/
+zz_put_token(t, s, n)
+       char *s;
 {
 {
-       register struct ctoken *tp;
-       register i;
-
-       tick = 0;
-       bzero((char *)htab, sizeof htab);
-       q1.forw = &q1;
-       q1.back = &q1;
-       for (i = 0, tp = tokens; i < NTOKEN; i++, tp++) {
-               tp->index = i + 1;
-               tp->hash = -1;
-               tp->count = 0;
-               tp->time = 0;
-               q1.forw->back = tp;
-               tp->forw = q1.forw;
-               q1.forw = tp;
-               tp->back = &q1;
-       }
-       q2.forw = &q2;
-       q2.back = &q2;
-       for (; i < sizeof tokens / sizeof *tokens; i++, tp++) {
-               tp->index = 0;
-               tp->hash = -1;
-               tp->count = 0;
-               tp->time = 0;
-               q2.forw->back = tp;
-               tp->forw = q2.forw;
-               q2.forw = tp;
-               tp->back = &q2;
+       if (tt.tt_nmodes != tt.tt_modes)
+               zz_setmodes(tt.tt_nmodes);
+       if (zz_debug) {
+               char buf[100];
+               zz_setmodes(WWM_REV);
+               (void) sprintf(buf, "%02x>", t);
+               ttputs(buf);
+               tt.tt_col += 3;
        }
        }
+       pc(t | 0x80);
+       tt.tt_col += n;
+       if (tt.tt_col == NCOL)
+               tt.tt_col = 0, tt.tt_row++;
 }
 
 tt_zapple()
 {
 }
 
 tt_zapple()
 {
-       zc_start();
        tt.tt_inschar = zz_inschar;
        tt.tt_delchar = zz_delchar;
        tt.tt_insline = zz_insline;
        tt.tt_inschar = zz_inschar;
        tt.tt_delchar = zz_delchar;
        tt.tt_insline = zz_insline;
@@ -464,9 +346,9 @@ tt_zapple()
        tt.tt_availmodes = WWM_REV;
        tt.tt_wrap = 1;
        tt.tt_retain = 0;
        tt.tt_availmodes = WWM_REV;
        tt.tt_wrap = 1;
        tt.tt_retain = 0;
-       tt.tt_ncol = 80;
-       tt.tt_nrow = 24;
-       tt.tt_init = zz_init;
+       tt.tt_ncol = NCOL;
+       tt.tt_nrow = NROW;
+       tt.tt_start = zz_start;
        tt.tt_end = zz_end;
        tt.tt_write = zz_write;
        tt.tt_putc = zz_putc;
        tt.tt_end = zz_end;
        tt.tt_write = zz_write;
        tt.tt_putc = zz_putc;
@@ -474,5 +356,12 @@ tt_zapple()
        tt.tt_clear = zz_clear;
        tt.tt_setmodes = zz_setmodes;
        tt.tt_frame = gen_frame;
        tt.tt_clear = zz_clear;
        tt.tt_setmodes = zz_setmodes;
        tt.tt_frame = gen_frame;
+       tt.tt_ntoken = 128;
+       tt.tt_set_token = zz_set_token;
+       tt.tt_put_token = zz_put_token;
+       tt.tt_token_min = 1;
+       tt.tt_token_max = TOKEN_MAX;
+       tt.tt_set_token_cost = 2;
+       tt.tt_put_token_cost = 1;
        return 0;
 }
        return 0;
 }
index eed74f6..cf17724 100644 (file)
@@ -14,7 +14,7 @@
  * 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.53 (Berkeley) %G%
+ *     @(#)ww.h        3.54 (Berkeley) %G%
  */
 
 #include <sgtty.h>
  */
 
 #include <sgtty.h>
@@ -207,7 +207,7 @@ int wwerrno;                        /* error number */
        /* statistics */
 int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc;
 int wwnwwr, wwnwwra, wwnwwrc;
        /* statistics */
 int wwnflush, wwnwr, wwnwre, wwnwrz, wwnwrc;
 int wwnwwr, wwnwwra, wwnwwrc;
-int wwzc0, wwzc1, wwzcsave, wwzctotal;
+int wwntokdef, wwntokuse, wwntoksave, wwntokc;
 int wwnupdate, wwnupdline, wwnupdmiss;
 int wwnupdscan, wwnupdclreol, wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline;
 int wwnread, wwnreade, wwnreadz, wwnreadc;
 int wwnupdate, wwnupdline, wwnupdmiss;
 int wwnupdscan, wwnupdclreol, wwnupdclreos, wwnupdclreosmiss, wwnupdclreosline;
 int wwnread, wwnreade, wwnreadz, wwnreadc;
index 39eb87e..5c2780c 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwend.c    3.12 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwend.c    3.13 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -24,18 +24,6 @@ static char sccsid[] = "@(#)wwend.c  3.12 (Berkeley) %G%";
 
 wwend()
 {
 
 wwend()
 {
-       wwupdate();
-       if (tt.tt_scroll_top != 0 || tt.tt_scroll_bot != tt.tt_nrow - 1)
-               /* tt.tt_setscroll is known to be defined */
-               (*tt.tt_setscroll)(0, tt.tt_nrow - 1);
-       if (tt.tt_insert)
-               (*tt.tt_setinsert)(0);
-       if (tt.tt_modes)
-               (*tt.tt_setmodes)(0);
-       if (tt.tt_scroll_down)
-               (*tt.tt_scroll_down)(1);
-       (*tt.tt_move)(tt.tt_nrow - 1, 0);
-       (*tt.tt_end)();
-       ttflush();
+       xxend();
        (void) wwsettty(0, &wwoldtty, &wwnewtty);
 }
        (void) wwsettty(0, &wwoldtty, &wwnewtty);
 }
index 56f8163..c2bd530 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwflush.c  3.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwflush.c  3.10 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -24,10 +24,16 @@ static char sccsid[] = "@(#)wwflush.c       3.9 (Berkeley) %G%";
 
 wwflush()
 {
 
 wwflush()
 {
-       if (wwcursorrow < 0 || wwcursorrow >= wwnrow
-           || wwcursorcol < 0 || wwcursorcol >= wwncol)
-               (*tt.tt_move)(0, 0);
-       else
-               (*tt.tt_move)(wwcursorrow, wwcursorcol);
-       ttflush();
+       register row, col;
+
+       if ((row = wwcursorrow) < 0)
+               row = 0;
+       else if (row >= wwnrow)
+               row = wwnrow - 1;
+       if ((col = wwcursorcol) < 0)
+               col = 0;
+       else if (col >= wwncol)
+               col = wwncol - 1;
+       xxmove(row, col);
+       xxflush(1);
 }
 }
index 9edadc8..a7ad7b7 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwinit.c   3.33 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwinit.c   3.34 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -36,8 +36,12 @@ wwinit()
        wwhead.ww_back = &wwhead;
 
        s = sigblock(sigmask(SIGIO));
        wwhead.ww_back = &wwhead;
 
        s = sigblock(sigmask(SIGIO));
-       if (signal(SIGIO, wwrint) == BADSIG)
+       if (signal(SIGIO, wwrint) == BADSIG ||
+           signal(SIGCHLD, wwchild) == BADSIG ||
+           signal(SIGPIPE, SIG_IGN) == BADSIG) {
+               wwerrno = WWE_SYS;
                return -1;
                return -1;
+       }
 
        if (wwgettty(0, &wwoldtty) < 0)
                return -1;
 
        if (wwgettty(0, &wwoldtty) < 0)
                return -1;
@@ -76,15 +80,12 @@ wwinit()
        }
        wwbaud = wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed];
 
        }
        wwbaud = wwbaudmap[wwoldtty.ww_sgttyb.sg_ospeed];
 
-       if (ttinit() < 0)
+       if (xxinit() < 0)
                goto bad;
        wwnrow = tt.tt_nrow;
        wwncol = tt.tt_ncol;
        wwavailmodes = tt.tt_availmodes;
        wwwrap = tt.tt_wrap;
                goto bad;
        wwnrow = tt.tt_nrow;
        wwncol = tt.tt_ncol;
        wwavailmodes = tt.tt_availmodes;
        wwwrap = tt.tt_wrap;
-       if (xxinit() < 0)
-               return -1;
-       (*tt.tt_init)();
 
        if (wwavailmodes & WWM_REV)
                wwcursormodes = WWM_REV | wwavailmodes & WWM_BLK;
 
        if (wwavailmodes & WWM_REV)
                wwcursormodes = WWM_REV | wwavailmodes & WWM_BLK;
@@ -179,8 +180,10 @@ wwinit()
         */
        (void) setenv("TERM", WWT_TERM, 1);
 
         */
        (void) setenv("TERM", WWT_TERM, 1);
 
-       (void) signal(SIGPIPE, SIG_IGN);
        (void) sigsetmask(s);
        (void) sigsetmask(s);
+       /* catch typeahead before ASYNC was set */
+       (void) kill(getpid(), SIGIO);
+       xxstart();
        return 0;
 bad:
        /*
        return 0;
 bad:
        /*
index 19bccbe..b4cbbb7 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwredraw.c 3.10 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwredraw.c 3.11 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -27,8 +27,7 @@ wwredraw()
        register i, j;
        register union ww_char *os;
 
        register i, j;
        register union ww_char *os;
 
-       xxreset();
-       (*tt.tt_clear)();
+       xxclear();
        for (i = 0; i < wwnrow; i++) {
                wwtouched[i] = WWU_TOUCHED;
                os = wwos[i];
        for (i = 0; i < wwnrow; i++) {
                wwtouched[i] = WWU_TOUCHED;
                os = wwos[i];
index 9649120..854f1d7 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwsuspend.c        3.9 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwsuspend.c        3.10 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -33,7 +33,7 @@ wwsuspend()
        (void) kill(0, SIGTSTP);
        (void) signal(SIGTSTP, SIG_IGN);
        (void) wwsettty(0, &wwnewtty, &wwoldtty);
        (void) kill(0, SIGTSTP);
        (void) signal(SIGTSTP, SIG_IGN);
        (void) wwsettty(0, &wwnewtty, &wwoldtty);
-       (*tt.tt_init)();
-       wwredraw();
+       xxstart();
+       wwredraw();             /* XXX, clears the screen twice */
        (void) signal(SIGTSTP, oldsig);
 }
        (void) signal(SIGTSTP, oldsig);
 }
index eba3632..2b37e1d 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwupdate.c 3.24 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwupdate.c 3.25 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -31,7 +31,6 @@ wwupdate1(top, bot)
        char check_clreos = 0;
        int scan_top, scan_bot;
 
        char check_clreos = 0;
        int scan_top, scan_bot;
 
-       xxflush();
        wwnupdate++;
        {
                register char *t1 = wwtouched + top, *t2 = wwtouched + bot;
        wwnupdate++;
        {
                register char *t1 = wwtouched + top, *t2 = wwtouched + bot;
@@ -137,7 +136,7 @@ wwupdate1(top, bot)
                }
                if (tt.tt_clreos == 0) {
                        if (gain > simple_gain && gain > 4) {
                }
                if (tt.tt_clreos == 0) {
                        if (gain > simple_gain && gain > 4) {
-                               (*tt.tt_clear)();
+                               xxclear();
                                i = top = scan_top;
                                bot = scan_bot;
                                j = 0;
                                i = top = scan_top;
                                bot = scan_bot;
                                j = 0;
@@ -146,8 +145,7 @@ wwupdate1(top, bot)
                } else
                        if (best_gain > simple_gain && best_gain > 4) {
                                i = best_row;
                } else
                        if (best_gain > simple_gain && best_gain > 4) {
                                i = best_row;
-                               (*tt.tt_move)(i, j = wwupd[i].best_col);
-                               (*tt.tt_clreos)();
+                               xxclreos(i, j = wwupd[i].best_col);
                                bot = scan_bot;
                                didit = 1;
                        }
                                bot = scan_bot;
                                didit = 1;
                        }
@@ -180,8 +178,7 @@ simple:
                didit = 0;
                if (tt.tt_clreol != 0 && upd->best_gain > 4) {
                        wwnupdclreol++;
                didit = 0;
                if (tt.tt_clreol != 0 && upd->best_gain > 4) {
                        wwnupdclreol++;
-                       (*tt.tt_move)(i, j = upd->best_col);
-                       (*tt.tt_clreol)();
+                       xxclreol(i, j = upd->best_col);
                        for (os = &wwos[i][j], j = wwncol - j; --j >= 0;)
                                os++->c_w = ' ';
                        didit = 1;
                        for (os = &wwos[i][j], j = wwncol - j; --j >= 0;)
                                os++->c_w = ' ';
                        didit = 1;
@@ -222,55 +219,42 @@ simple:
                                }
                                j++;
                        }
                                }
                                j++;
                        }
-                       tt.tt_nmodes = m;
                        if (wwwrap
                            && i == wwnrow - 1 && q - buf + c == wwncol) {
                                if (tt.tt_setinsert) {
                                        if (q - buf != 1) {
                        if (wwwrap
                            && i == wwnrow - 1 && q - buf + c == wwncol) {
                                if (tt.tt_setinsert) {
                                        if (q - buf != 1) {
-                                               (*tt.tt_move)(i, c);
-                                               (*tt.tt_write)(buf + 1,
-                                                       q - buf - 1);
-                                               (*tt.tt_move)(i, c);
-                                               tt.tt_ninsert = 1;
-                                               (*tt.tt_write)(buf, 1);
-                                               tt.tt_ninsert = 0;
+                                               xxwrite(i, c, buf + 1,
+                                                       q - buf - 1, m);
+                                               xxinschar(i, c, *buf |
+                                                       m << WWC_MSHIFT);
                                        } else {
                                        } else {
-                                               (*tt.tt_move)(i, c - 1);
-                                               (*tt.tt_write)(buf, 1);
-                                               tt.tt_nmodes = ns[-2].c_m;
-                                               (*tt.tt_move)(i, c - 1);
-                                               tt.tt_ninsert = 1;
-                                               (*tt.tt_write)(&ns[-2].c_c, 1);
-                                               tt.tt_ninsert = 0;
+                                               xxwrite(i, c - 1, buf, 1, m);
+                                               xxinschar(i, c - 1,
+                                                       ns[-2].c_w);
                                        }
                                } else if (tt.tt_inschar) {
                                        if (q - buf != 1) {
                                        }
                                } else if (tt.tt_inschar) {
                                        if (q - buf != 1) {
-                                               (*tt.tt_move)(i, c);
-                                               (*tt.tt_write)(buf + 1,
-                                                       q - buf - 1);
-                                               (*tt.tt_move)(i, c);
-                                               (*tt.tt_inschar)(1);
-                                               (*tt.tt_write)(buf, 1);
+                                               xxwrite(i, c, buf + 1,
+                                                       q - buf - 1, m);
+                                               xxinschar(i, c, *buf |
+                                                       m << WWC_MSHIFT);
+                                               xxwrite(i, c, buf, 1, m);
                                        } else {
                                        } else {
-                                               (*tt.tt_move)(i, c - 1);
-                                               (*tt.tt_write)(buf, 1);
-                                               tt.tt_nmodes = ns[-2].c_m;
-                                               (*tt.tt_move)(i, c - 1);
-                                               (*tt.tt_inschar)(1);
-                                               (*tt.tt_write)(&ns[-2].c_c, 1);
+                                               xxwrite(i, c - 1, buf, 1, m);
+                                               xxinschar(i, c - 1,
+                                                       ns[-2].c_w);
+                                               xxwrite(i, c - 1, &ns[-2].c_c,
+                                                       1, ns[-2].c_m);
                                        }
                                } else {
                                        }
                                } else {
-                                       if (q - buf > 1) {
-                                               (*tt.tt_move)(i, c);
-                                               (*tt.tt_write)(buf, q-buf-1);
-                                       }
+                                       if (q - buf > 1)
+                                               xxwrite(i, c, buf,
+                                                       q - buf - 1, m);
                                        os[-1] = lastc;
                                        *touched = WWU_TOUCHED;
                                }
                                        os[-1] = lastc;
                                        *touched = WWU_TOUCHED;
                                }
-                       } else {
-                               (*tt.tt_move)(i, c);
-                               (*tt.tt_write)(buf, q - buf);
-                       }
+                       } else
+                               xxwrite(i, c, buf, q - buf, m);
                        didit = 1;
                }
                if (!didit)
                        didit = 1;
                }
                if (!didit)
index cc577e0..50b68af 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)wwwrite.c  3.28 (Berkeley) %G%";
+static char sccsid[] = "@(#)wwwrite.c  3.29 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -227,10 +227,17 @@ int n;
                        case 'O':
                                w->ww_insert = 0;
                                break;
                        case 'O':
                                w->ww_insert = 0;
                                break;
+                       case 'X':
+                               wwupdate();
+                               break;
                        case 'Y':
                                UPDATE();
                                w->ww_wstate = 2;
                                break;
                        case 'Y':
                                UPDATE();
                                w->ww_wstate = 2;
                                break;
+                       case 'Z':
+                               wwupdate();
+                               xxflush(0);
+                               break;
                        case 's':
                                w->ww_wstate = 4;
                                break;
                        case 's':
                                w->ww_wstate = 4;
                                break;