compress control characters as well
authorEdward Wang <edward@ucbvax.Berkeley.EDU>
Sat, 16 Sep 1989 08:49:04 +0000 (00:49 -0800)
committerEdward Wang <edward@ucbvax.Berkeley.EDU>
Sat, 16 Sep 1989 08:49:04 +0000 (00:49 -0800)
SCCS-vsn: usr.bin/window/ttoutput.c 3.7
SCCS-vsn: usr.bin/window/ttinit.c 3.22
SCCS-vsn: usr.bin/window/tt.h 3.25
SCCS-vsn: usr.bin/window/Makefile 5.6
SCCS-vsn: usr.bin/window/xx.c 3.4
SCCS-vsn: usr.bin/window/ttzapple.c 3.8
SCCS-vsn: usr.bin/window/xxflush.c 3.4
SCCS-vsn: usr.bin/window/compress.c 3.3

usr/src/usr.bin/window/Makefile
usr/src/usr.bin/window/compress.c
usr/src/usr.bin/window/tt.h
usr/src/usr.bin/window/ttinit.c
usr/src/usr.bin/window/ttoutput.c
usr/src/usr.bin/window/ttzapple.c
usr/src/usr.bin/window/xx.c
usr/src/usr.bin/window/xxflush.c

index 88284ce..f221148 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.5 (Berkeley) %G%
+#      @(#)Makefile    5.6 (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 xxcompress.c xxflush.c
+       wwwrite.c xx.c xxflush.c compress.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 xxcompress.o xxflush.o
+       wwwrite.o xx.o xxflush.o compress.o
 MAN=   window.0
 
 all: window
 MAN=   window.0
 
 all: window
index 7721e05..02b2c85 100644 (file)
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)compress.c 3.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)compress.c 3.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
-#include "xx.h"
 #include "tt.h"
 
 #include "tt.h"
 
+       /* special */
+#include <stdio.h>
+int cc_trace = 0;
+FILE *cc_trace_fp;
+
        /* tunable parameters */
 
        /* tunable parameters */
 
-int xc_reverse = 1;
-int xc_sort = 0;
-int xc_chop = 0;
+int cc_reverse = 1;
+int cc_sort = 0;
+int cc_chop = 0;
 
 
-int xc_token_max = 8;          /* <= TOKEN_MAX */
-int xc_token_min = 2;          /* > tt.tt_put_token_cost */
-int xc_npass0 = 1;
-int xc_npass1 = 1;
+int cc_token_max = 8;          /* <= TOKEN_MAX */
+int cc_token_min = 2;          /* > tt.tt_put_token_cost */
+int cc_npass0 = 1;
+int cc_npass1 = 1;
 
 
-int xc_bufsize = 1024 * 3;     /* XXX, or 80 * 24 * 2 */
+int cc_bufsize = 1024 * 3;     /* XXX, or 80 * 24 * 2 */
 
 
-int xc_ntoken = 8192;
+int cc_ntoken = 8192;
 
 
-#define xc_weight XXX
-#ifndef xc_weight
-int xc_weight = 0;
+#define cc_weight XXX
+#ifndef cc_weight
+int cc_weight = 0;
 #endif
 
 #define TOKEN_MAX 16
 
 #endif
 
 #define TOKEN_MAX 16
 
-struct xc {
+struct cc {
        char string[TOKEN_MAX];
        char length;
        char flag;
        char string[TOKEN_MAX];
        char length;
        char flag;
-#ifndef xc_weight
+#ifndef cc_weight
        short weight;
 #endif
        long time;              /* time last seen */
        short weight;
 #endif
        long time;              /* time last seen */
@@ -57,31 +61,31 @@ struct xc {
        short ccount;           /* count in compression */
        short places;           /* places in the buffer */
        short code;             /* token code */
        short ccount;           /* count in compression */
        short places;           /* places in the buffer */
        short code;             /* token code */
-       struct xc *qforw, *qback;
-       struct xc *hforw, **hback;
+       struct cc *qforw, *qback;
+       struct cc *hforw, **hback;
 };
 
 };
 
-short xc_thresholds[TOKEN_MAX + 1];
-#define thresh(length) (xc_thresholds[length])
+short cc_thresholds[TOKEN_MAX + 1];
+#define thresh(length) (cc_thresholds[length])
 #define threshp(code, count, length) \
 #define threshp(code, count, length) \
-       ((code) >= 0 || (short) (count) >= xc_thresholds[length])
+       ((code) >= 0 || (short) (count) >= cc_thresholds[length])
 
 
-#ifndef xc_weight
-short xc_wthresholds[TOKEN_MAX + 1];
-#define wthresh(length) (xc_wthresholds[length])
-#define wthreshp(weight, length) ((short) (weight) >= xc_wthresholds[length])
+#ifndef cc_weight
+short cc_wthresholds[TOKEN_MAX + 1];
+#define wthresh(length) (cc_wthresholds[length])
+#define wthreshp(weight, length) ((short) (weight) >= cc_wthresholds[length])
 #else
 #define wthreshp(weight, length) (0)
 #endif
 
 #else
 #define wthreshp(weight, length) (0)
 #endif
 
-#ifndef xc_weight
-short xc_wlimits[TOKEN_MAX + 1];
-#define wlimit(length) (xc_wlimits[length])
+#ifndef cc_weight
+short cc_wlimits[TOKEN_MAX + 1];
+#define wlimit(length) (cc_wlimits[length])
 #endif
 
 #define put_token_score(length) ((length) - tt.tt_put_token_cost)
 
 #endif
 
 #define put_token_score(length) ((length) - tt.tt_put_token_cost)
 
-int xc_score_adjustments[TOKEN_MAX + 1][8]; /* XXX, 8 > max of xc_thresholds */
+int cc_score_adjustments[TOKEN_MAX + 1][8]; /* XXX, 8 > max of cc_thresholds */
 #define score_adjust(score, p) \
        do { \
                int length = (p)->length; \
 #define score_adjust(score, p) \
        do { \
                int length = (p)->length; \
@@ -90,86 +94,86 @@ int xc_score_adjustments[TOKEN_MAX + 1][8]; /* XXX, 8 > max of xc_thresholds */
                    wthreshp((p)->weight, length)) /* XXX */ \
                        (score) -= length - tt.tt_put_token_cost; \
                else \
                    wthreshp((p)->weight, length)) /* XXX */ \
                        (score) -= length - tt.tt_put_token_cost; \
                else \
-                       (score) += xc_score_adjustments[length][ccount]; \
+                       (score) += cc_score_adjustments[length][ccount]; \
        } while (0)
 
        } while (0)
 
-int xc_initial_scores[TOKEN_MAX + 1][8]; /* XXX, 8 > max of xc_thresholds */
+int cc_initial_scores[TOKEN_MAX + 1][8]; /* XXX, 8 > max of cc_thresholds */
 
 
-struct xc xc_q0a, xc_q0b, xc_q1a, xc_q1b;
+struct cc cc_q0a, cc_q0b, cc_q1a, cc_q1b;
 
 
-#define qinsert(x1, x2) \
+#define qinsert(p1, p2) \
        do { \
        do { \
-               register struct xc *forw = (x1)->qforw; \
-               register struct xc *back = (x1)->qback; \
+               register struct cc *forw = (p1)->qforw; \
+               register struct cc *back = (p1)->qback; \
                back->qforw = forw; \
                forw->qback = back; \
                back->qforw = forw; \
                forw->qback = back; \
-               forw = (x2)->qforw; \
-               (x1)->qforw = forw; \
-               forw->qback = (x1); \
-               (x2)->qforw = (x1); \
-               (x1)->qback = (x2); \
+               forw = (p2)->qforw; \
+               (p1)->qforw = forw; \
+               forw->qback = (p1); \
+               (p2)->qforw = (p1); \
+               (p1)->qback = (p2); \
        } while (0)
 
        } while (0)
 
-#define qinsertq(q, x) \
+#define qinsertq(q, p) \
        ((q)->qforw == (q) ? 0 : \
        ((q)->qforw == (q) ? 0 : \
-        ((q)->qback->qforw = (x)->qforw, \
-         (x)->qforw->qback = (q)->qback, \
-         (q)->qforw->qback = (x), \
-         (x)->qforw = (q)->qforw, \
+        ((q)->qback->qforw = (p)->qforw, \
+         (p)->qforw->qback = (q)->qback, \
+         (q)->qforw->qback = (p), \
+         (p)->qforw = (q)->qforw, \
          (q)->qforw = (q), \
          (q)->qback = (q)))
 
 #define H              (14)
 #define HSIZE          (1 << H)
          (q)->qforw = (q), \
          (q)->qback = (q)))
 
 #define H              (14)
 #define HSIZE          (1 << H)
-#define hash(h, c)     ((((h) >> H - 8 | (h) << 8) ^ (unsigned char)(c)) & \
-                               HSIZE - 1)
-
-struct xc **xc_output;                 /* the output array */
-short *xc_places[TOKEN_MAX + 1];
-short *xc_hashcodes;                   /* for computing hashcodes */
-struct xc **xc_htab;                   /* the hash table */
-struct xc **xc_tokens;                 /* holds all the active tokens */
-struct xc_undo {
-       struct xc **pos;
-       struct xc *val;
-} *xc_undo;
-
-long xc_time, xc_time0;
-
-xcinit()
+#define hash(h, c)     ((((h) >> H - 8 | (h) << 8) ^ (c)) & HSIZE - 1)
+
+char *cc_buffer;
+struct cc **cc_output;                 /* the output array */
+short *cc_places[TOKEN_MAX + 1];
+short *cc_hashcodes;                   /* for computing hashcodes */
+struct cc **cc_htab;                   /* the hash table */
+struct cc **cc_tokens;                 /* holds all the active tokens */
+struct cc_undo {
+       struct cc **pos;
+       struct cc *val;
+} *cc_undo;
+
+long cc_time, cc_time0;
+
+char *cc_tt_ob, *cc_tt_obe;
+
+ccinit()
 {
        register i, j;
 {
        register i, j;
-       register struct xc *p;
+       register struct cc *p;
 
 
-       if (tt.tt_token_max > xc_token_max)
-               tt.tt_token_max = xc_token_max;
-       if (tt.tt_token_min < xc_token_min)
-               tt.tt_token_min = xc_token_min;
+       if (tt.tt_token_max > cc_token_max)
+               tt.tt_token_max = cc_token_max;
+       if (tt.tt_token_min < cc_token_min)
+               tt.tt_token_min = cc_token_min;
        if (tt.tt_token_min > tt.tt_token_max) {
                tt.tt_ntoken = 0;
                return 0;
        }
        if (tt.tt_token_min > tt.tt_token_max) {
                tt.tt_ntoken = 0;
                return 0;
        }
-       if (tt.tt_ntoken > xc_ntoken / 2)       /* not likely */
-               tt.tt_ntoken = xc_ntoken / 2;
-       if (xxbufsize > xc_bufsize)
-               xxbufsize = xc_bufsize;         /* XXX */
+       if (tt.tt_ntoken > cc_ntoken / 2)       /* not likely */
+               tt.tt_ntoken = cc_ntoken / 2;
 #define C(x) (sizeof (x) / sizeof *(x))
 #define C(x) (sizeof (x) / sizeof *(x))
-       for (i = 0; i < C(xc_thresholds); i++) {
+       for (i = 0; i < C(cc_thresholds); i++) {
                int h = i - tt.tt_put_token_cost;
                if (h > 0)
                int h = i - tt.tt_put_token_cost;
                if (h > 0)
-                       xc_thresholds[i] =
+                       cc_thresholds[i] =
                                (tt.tt_set_token_cost + 1 + h - 1) / h + 1;
                else
                                (tt.tt_set_token_cost + 1 + h - 1) / h + 1;
                else
-                       xc_thresholds[i] = 0;
+                       cc_thresholds[i] = 0;
        }
        }
-       for (i = 0; i < C(xc_score_adjustments); i++) {
-               int t = xc_thresholds[i];
-               for (j = 0; j < C(*xc_score_adjustments); j++) {
+       for (i = 0; i < C(cc_score_adjustments); i++) {
+               int t = cc_thresholds[i];
+               for (j = 0; j < C(*cc_score_adjustments); j++) {
                        if (j >= t)
                        if (j >= t)
-                               xc_score_adjustments[i][j] =
+                               cc_score_adjustments[i][j] =
                                        - (i - tt.tt_put_token_cost);
                        else if (j < t - 1)
                                        - (i - tt.tt_put_token_cost);
                        else if (j < t - 1)
-                               xc_score_adjustments[i][j] = 0;
+                               cc_score_adjustments[i][j] = 0;
                        else
                                /*
                                 * cost now is
                        else
                                /*
                                 * cost now is
@@ -179,139 +183,169 @@ xcinit()
                                 *              ccount * put-token-cost b
                                 * the score adjustment is (b - a)
                                 */
                                 *              ccount * put-token-cost b
                                 * the score adjustment is (b - a)
                                 */
-                               xc_score_adjustments[i][j] =
+                               cc_score_adjustments[i][j] =
                                        tt.tt_set_token_cost + i +
                                                j * tt.tt_put_token_cost -
                                                        i * (j + 1);
                        if (j >= t)
                                        tt.tt_set_token_cost + i +
                                                j * tt.tt_put_token_cost -
                                                        i * (j + 1);
                        if (j >= t)
-                               xc_initial_scores[i][j] = 0;
+                               cc_initial_scores[i][j] = 0;
                        else
                                /*
                                 * - (set-token-cost +
                                 *      (length - put-token-cost) -
                                 *      (length - put-token-cost) * ccount)
                                 */
                        else
                                /*
                                 * - (set-token-cost +
                                 *      (length - put-token-cost) -
                                 *      (length - put-token-cost) * ccount)
                                 */
-                               xc_initial_scores[i][j] =
+                               cc_initial_scores[i][j] =
                                        - (tt.tt_set_token_cost +
                                           (i - tt.tt_put_token_cost) -
                                           (i - tt.tt_put_token_cost) * j);
                }
        }
                                        - (tt.tt_set_token_cost +
                                           (i - tt.tt_put_token_cost) -
                                           (i - tt.tt_put_token_cost) * j);
                }
        }
-#ifndef xc_weight
-       for (i = 1; i < C(xc_wthresholds); i++) {
-               xc_wthresholds[i] =
+#ifndef cc_weight
+       for (i = 1; i < C(cc_wthresholds); i++) {
+               cc_wthresholds[i] =
                        ((tt.tt_set_token_cost + tt.tt_put_token_cost) / i +
                                i / 5 + 1) *
                        ((tt.tt_set_token_cost + tt.tt_put_token_cost) / i +
                                i / 5 + 1) *
-                               xc_weight + 1;
-               xc_wlimits[i] = xc_wthresholds[i] + xc_weight;
+                               cc_weight + 1;
+               cc_wlimits[i] = cc_wthresholds[i] + cc_weight;
        }
 #endif
 #undef C
        }
 #endif
 #undef C
-       if ((xc_output = (struct xc **)
-            malloc((unsigned) xxbufsize * sizeof *xc_output)) == 0)
+       if ((cc_output = (struct cc **)
+            malloc((unsigned) cc_bufsize * sizeof *cc_output)) == 0)
                goto nomem;
                goto nomem;
-       if ((xc_hashcodes = (short *)
-            malloc((unsigned) xxbufsize * sizeof *xc_hashcodes)) == 0)
+       if ((cc_hashcodes = (short *)
+            malloc((unsigned) cc_bufsize * sizeof *cc_hashcodes)) == 0)
                goto nomem;
                goto nomem;
-       if ((xc_htab = (struct xc **) malloc(HSIZE * sizeof *xc_htab)) == 0)
+       if ((cc_htab = (struct cc **) malloc(HSIZE * sizeof *cc_htab)) == 0)
                goto nomem;
                goto nomem;
-       if ((xc_tokens = (struct xc **)
+       if ((cc_tokens = (struct cc **)
             malloc((unsigned)
             malloc((unsigned)
-                   (xc_ntoken + tt.tt_token_max - tt.tt_token_min + 1) *
-                   sizeof *xc_tokens)) == 0)
+                   (cc_ntoken + tt.tt_token_max - tt.tt_token_min + 1) *
+                   sizeof *cc_tokens)) == 0)
                goto nomem;
                goto nomem;
-       if ((xc_undo = (struct xc_undo *)
-            malloc((unsigned) xxbufsize * sizeof *xc_undo)) == 0)
+       if ((cc_undo = (struct cc_undo *)
+            malloc((unsigned) cc_bufsize * sizeof *cc_undo)) == 0)
                goto nomem;
        for (i = tt.tt_token_min; i <= tt.tt_token_max; i++)
                goto nomem;
        for (i = tt.tt_token_min; i <= tt.tt_token_max; i++)
-               if ((xc_places[i] = (short *)
-                    malloc((unsigned) xxbufsize * sizeof **xc_places)) == 0)
+               if ((cc_places[i] = (short *)
+                    malloc((unsigned) cc_bufsize * sizeof **cc_places)) == 0)
                        goto nomem;
                        goto nomem;
-       xc_q0a.qforw = xc_q0a.qback = &xc_q0a;
-       xc_q0b.qforw = xc_q0b.qback = &xc_q0b;
-       xc_q1a.qforw = xc_q1a.qback = &xc_q1a;
-       xc_q1b.qforw = xc_q1b.qback = &xc_q1b;
-       if ((p = (struct xc *) malloc((unsigned) xc_ntoken * sizeof *p)) == 0)
+       cc_q0a.qforw = cc_q0a.qback = &cc_q0a;
+       cc_q0b.qforw = cc_q0b.qback = &cc_q0b;
+       cc_q1a.qforw = cc_q1a.qback = &cc_q1a;
+       cc_q1b.qforw = cc_q1b.qback = &cc_q1b;
+       if ((p = (struct cc *) malloc((unsigned) cc_ntoken * sizeof *p)) == 0)
                goto nomem;
        for (i = 0; i < tt.tt_ntoken; i++) {
                p->code = i;
                p->time = -1;
                goto nomem;
        for (i = 0; i < tt.tt_ntoken; i++) {
                p->code = i;
                p->time = -1;
-               p->qback = xc_q0a.qback;
-               p->qforw = &xc_q0a;
+               p->qback = cc_q0a.qback;
+               p->qforw = &cc_q0a;
                p->qback->qforw = p;
                p->qback->qforw = p;
-               xc_q0a.qback = p;
+               cc_q0a.qback = p;
                p++;
        }
                p++;
        }
-       for (; i < xc_ntoken; i++) {
+       for (; i < cc_ntoken; i++) {
                p->code = -1;
                p->time = -1;
                p->code = -1;
                p->time = -1;
-               p->qback = xc_q1a.qback;
-               p->qforw = &xc_q1a;
+               p->qback = cc_q1a.qback;
+               p->qforw = &cc_q1a;
                p->qback->qforw = p;
                p->qback->qforw = p;
-               xc_q1a.qback = p;
+               cc_q1a.qback = p;
                p++;
        }
                p++;
        }
+       cc_tt_ob = tt_ob;
+       cc_tt_obe = tt_obe;
+       if ((cc_buffer = malloc((unsigned) cc_bufsize)) == 0)
+               goto nomem;
        return 0;
 nomem:
        wwerrno = WWE_NOMEM;
        return -1;
 }
 
        return 0;
 nomem:
        wwerrno = WWE_NOMEM;
        return -1;
 }
 
-xcstart()
+ccstart()
 {
 {
-       register struct xc *p;
-
-       bzero((char *) xc_htab, HSIZE * sizeof *xc_htab);
-       for (p = xc_q0a.qforw; p != &xc_q0a; p = p->qforw)
+       register struct cc *p;
+       int ccflush();
+
+       (*tt.tt_flush)();
+       tt_obp = tt_ob = cc_buffer;
+       tt_obe = tt_ob + cc_bufsize;
+       tt.tt_flush = ccflush;
+       bzero((char *) cc_htab, HSIZE * sizeof *cc_htab);
+       for (p = cc_q0a.qforw; p != &cc_q0a; p = p->qforw)
                p->hback = 0;
                p->hback = 0;
-       for (p = xc_q1a.qforw; p != &xc_q1a; p = p->qforw)
+       for (p = cc_q1a.qforw; p != &cc_q1a; p = p->qforw)
                p->hback = 0;
                p->hback = 0;
+       if (cc_trace)
+               cc_trace_fp = fopen("window-trace", "a");
 }
 
 }
 
-xcscan(buffer, bufsize)
-       char *buffer;
+ccend()
 {
 {
+       int ttflush();
+
+       (*tt.tt_flush)();
+       tt_obp = tt_ob = cc_tt_ob;
+       tt_obe = cc_tt_obe;
+       tt.tt_flush = ttflush;
+       if (cc_trace_fp != NULL) {
+               (void) fclose(cc_trace_fp);
+               cc_trace_fp = NULL;
+       }
+}
+
+ccflush()
+{
+       int bufsize = tt_obp - tt_ob;
        int n;
        int n;
+       int ttflush();
 
 
-       if (bufsize <= tt.tt_token_min)         /* one more for char_sep */
+       if (tt_ob != cc_buffer)
+               abort();
+       if (cc_trace_fp != NULL) {
+               (void) fwrite(tt_ob, 1, bufsize, cc_trace_fp);
+               putc(-1, cc_trace_fp);
+       }
+       if (bufsize < tt.tt_token_min) {
+               ttflush();
                return;
                return;
-       xc_time0 = xc_time;
-       xc_time += bufsize;
-#ifdef STATS
-       if (verbose >= 0)
-               time_begin();
-#endif
-       n = xc_sweep_phase(buffer, bufsize, xc_tokens);
-#ifdef STATS
-       if (verbose >= 0) {
-               time_end();
-               time_begin();
        }
        }
-#endif
-       xc_compress_phase(xc_output, bufsize, xc_tokens, n);
-#ifdef STATS
-       if (verbose >= 0)
-               time_end();
-#endif
+       tt_obp = tt_ob = cc_tt_ob;
+       tt_obe = cc_tt_obe;
+       tt.tt_flush = ttflush;
+       cc_time0 = cc_time;
+       cc_time += bufsize;
+       n = cc_sweep_phase(cc_buffer, bufsize, cc_tokens);
+       cc_compress_phase(cc_output, bufsize, cc_tokens, n);
+       cc_output_phase(cc_buffer, cc_output, bufsize);
+       ttflush();
+       tt_obp = tt_ob = cc_buffer;
+       tt_obe = cc_buffer + cc_bufsize;
+       tt.tt_flush = ccflush;
 }
 
 }
 
-xc_sweep_phase(buffer, bufsize, tokens)
+cc_sweep_phase(buffer, bufsize, tokens)
        char *buffer;
        char *buffer;
-       struct xc **tokens;
+       struct cc **tokens;
 {
 {
-       register struct xc **pp = tokens;
+       register struct cc **pp = tokens;
        register i, n;
 #ifdef STATS
        int nn, ii;
 #endif
 
 #ifdef STATS
        register i, n;
 #ifdef STATS
        int nn, ii;
 #endif
 
 #ifdef STATS
+       if (verbose >= 0)
+               time_begin();
        if (verbose > 0)
                printf("Sweep:");
 #endif
        if (verbose > 0)
                printf("Sweep:");
 #endif
-       xc_sweep0(buffer, bufsize, tt.tt_token_min - 1);
+       cc_sweep0(buffer, bufsize, tt.tt_token_min - 1);
 #ifdef STATS
 #ifdef STATS
-       xc_ntoken_stat = 0;
+       ntoken_stat = 0;
        nn = 0;
        ii = 0;
 #endif
        nn = 0;
        ii = 0;
 #endif
@@ -327,7 +361,7 @@ xc_sweep_phase(buffer, bufsize, tokens)
                        (void) fflush(stdout);
                }
 #endif
                        (void) fflush(stdout);
                }
 #endif
-               n = xc_sweep(buffer, bufsize, pp, i);
+               n = cc_sweep(buffer, bufsize, pp, i);
                pp += n;
 #ifdef STATS
                if (verbose > 0) {
                pp += n;
 #ifdef STATS
                if (verbose > 0) {
@@ -339,97 +373,85 @@ xc_sweep_phase(buffer, bufsize, tokens)
                }
 #endif
        }
                }
 #endif
        }
-       qinsertq(&xc_q1b, &xc_q1a);
+       qinsertq(&cc_q1b, &cc_q1a);
 #ifdef STATS
        if (verbose > 0)
                printf("\n       %d tokens, %d candidates\n",
 #ifdef STATS
        if (verbose > 0)
                printf("\n       %d tokens, %d candidates\n",
-                       xc_ntoken_stat, nn);
+                       ntoken_stat, nn);
+       if (verbose >= 0)
+               time_end();
 #endif
        return pp - tokens;
 }
 
 #endif
        return pp - tokens;
 }
 
-xc_sweep0(buffer, n, length)
+cc_sweep0(buffer, n, length)
        char *buffer;
        char *buffer;
-       register n;
-       register length;
 {
 {
+       register char *p;
+       register short *hc;
        register i;
        register i;
-       register char *p = buffer;
-       register short *hc = xc_hashcodes;
-       register h;
+       register short c;
+       register short pc = tt.tt_padc;
 
 
-       if (--length == 0)
-               do {
-#ifdef char_sep
-                       if ((*hc++ = *p++) == char_sep)
-                               hc[-1] = -1;
-#else
-                       *hc++ = *p++;
-#endif
-               } while (--n);
-       else
-               for (n -= length; --n >= 0;) {
-#ifdef char_sep
-                       if (*p == char_sep) {
-                               *hc++ = -1;
-                               p++;
-                               continue;
-                       }
-#endif
-                       h = *p++;
-                       for (i = length; --i >= 0;) {
-#ifdef char_sep
-                               if (*p == char_sep) {
-                                       h = -1;
-                                       p += i + 1;
-                                       break;
-                               }
-#endif
-                               h = hash(h, *p++);
-                       }
-                       *hc++ = h;
-                       p -= length;
+       /* n and length are at least 1 */
+       p = buffer++;
+       hc = cc_hashcodes;
+       i = n;
+       do {
+               if ((*hc++ = *p++) == pc)
+                       hc[-1] = -1;
+       } while (--i);
+       while (--length) {
+               p = buffer++;
+               hc = cc_hashcodes;
+               for (i = n--; --i;) {
+                       if ((c = *p++) == pc || *hc < 0)
+                               c = -1;
+                       else
+                               c = hash(*hc, c);
+                       *hc++ = c;
                }
                }
+       }
 }
 
 }
 
-xc_sweep(buffer, bufsize, tokens, length)
+cc_sweep(buffer, bufsize, tokens, length)
        char *buffer;
        char *buffer;
-       struct xc **tokens;
+       struct cc **tokens;
        register length;
 {
        register length;
 {
-       register struct xc *p;
+       register struct cc *p;
        register char *cp;
        register i;
        short *hc;
        register char *cp;
        register i;
        short *hc;
-       short *places = xc_places[length];
-       struct xc **pp = tokens;
+       short *places = cc_places[length];
+       struct cc **pp = tokens;
        short threshold = thresh(length);
        short threshold = thresh(length);
-#ifndef xc_weight
+#ifndef cc_weight
        short wthreshold = wthresh(length);
        short limit = wlimit(length);
 #endif
        int time;
        short wthreshold = wthresh(length);
        short limit = wlimit(length);
 #endif
        int time;
+       short pc = tt.tt_padc;
 
        i = length - 1;
        bufsize -= i;
        cp = buffer + i;
 
        i = length - 1;
        bufsize -= i;
        cp = buffer + i;
-       hc = xc_hashcodes;
-       time = xc_time0;
+       hc = cc_hashcodes;
+       time = cc_time0;
        for (i = 0; i < bufsize; i++, time++) {
        for (i = 0; i < bufsize; i++, time++) {
-               struct xc **h;
+               struct cc **h;
 
                {
                        register short *hc1 = hc;
 
                {
                        register short *hc1 = hc;
-#ifdef char_sep
-                       if (*hc1 < 0 || *cp == char_sep) {
+                       register short c = *cp++;
+                       register short hh;
+                       if ((hh = *hc1) < 0 || c == pc) {
                                *hc1++ = -1;
                                hc = hc1;
                                *hc1++ = -1;
                                hc = hc1;
-                               cp++;
                                continue;
                        }
                                continue;
                        }
-#endif
-                       h = xc_htab + (*hc1 = hash(*hc1, *cp++));
-                       hc = hc1 + 1;
+                       h = cc_htab + (*hc1++ = hash(hh, c));
+                       hc = hc1;
                }
                for (p = *h; p != 0; p = p->hforw)
                        if (p->length == (char) length) {
                }
                for (p = *h; p != 0; p = p->hforw)
                        if (p->length == (char) length) {
@@ -444,9 +466,9 @@ xc_sweep(buffer, bufsize, tokens, length)
                        fail:;
                        }
                if (p == 0) {
                        fail:;
                        }
                if (p == 0) {
-                       p = xc_q1a.qback;
-                       if (p == &xc_q1a ||
-                           p->time >= xc_time0 && p->length == (char) length)
+                       p = cc_q1a.qback;
+                       if (p == &cc_q1a ||
+                           p->time >= cc_time0 && p->length == (char) length)
                                continue;
                        if (p->hback != 0)
                                if ((*p->hback = p->hforw) != 0)
                                continue;
                        if (p->hback != 0)
                                if ((*p->hback = p->hforw) != 0)
@@ -460,8 +482,8 @@ xc_sweep(buffer, bufsize, tokens, length)
                                while (--n);
                        }
                        p->length = length;
                                while (--n);
                        }
                        p->length = length;
-#ifndef xc_weight
-                       p->weight = xc_weight;
+#ifndef cc_weight
+                       p->weight = cc_weight;
 #endif
                        p->time = time;
                        p->bcount = 1;
 #endif
                        p->time = time;
                        p->bcount = 1;
@@ -471,17 +493,17 @@ xc_sweep(buffer, bufsize, tokens, length)
                                p->hforw->hback = &p->hforw;
                        *h = p;
                        p->hback = h;
                                p->hforw->hback = &p->hforw;
                        *h = p;
                        p->hback = h;
-                       qinsert(p, &xc_q1a);
+                       qinsert(p, &cc_q1a);
                        places[i] = -1;
                        p->places = i;
 #ifdef STATS
                        places[i] = -1;
                        p->places = i;
 #ifdef STATS
-                       xc_ntoken_stat++;
+                       ntoken_stat++;
 #endif
 #endif
-               } else if (p->time < xc_time0) {
-#ifndef xc_weight
+               } else if (p->time < cc_time0) {
+#ifndef cc_weight
                        if ((p->weight += p->time - time) < 0)
                        if ((p->weight += p->time - time) < 0)
-                               p->weight = xc_weight;
-                       else if ((p->weight += xc_weight) > limit)
+                               p->weight = cc_weight;
+                       else if ((p->weight += cc_weight) > limit)
                                p->weight = limit;
 #endif
                        p->time = time;
                                p->weight = limit;
 #endif
                        p->time = time;
@@ -491,21 +513,21 @@ xc_sweep(buffer, bufsize, tokens, length)
                                p->flag = 1;
                                *pp++ = p;
                        } else
                                p->flag = 1;
                                *pp++ = p;
                        } else
-#ifndef xc_weight
+#ifndef cc_weight
                        if (p->weight >= wthreshold) {
                                p->flag = 1;
                                *pp++ = p;
                        if (p->weight >= wthreshold) {
                                p->flag = 1;
                                *pp++ = p;
-                               qinsert(p, &xc_q1b);
+                               qinsert(p, &cc_q1b);
                        } else
 #endif
                        {
                                p->flag = 0;
                        } else
 #endif
                        {
                                p->flag = 0;
-                               qinsert(p, &xc_q1a);
+                               qinsert(p, &cc_q1a);
                        }
                        places[i] = -1;
                        p->places = i;
 #ifdef STATS
                        }
                        places[i] = -1;
                        p->places = i;
 #ifdef STATS
-                       xc_ntoken_stat++;
+                       ntoken_stat++;
 #endif
                } else if (p->time + length > time) {
                        /*
 #endif
                } else if (p->time + length > time) {
                        /*
@@ -513,23 +535,23 @@ xc_sweep(buffer, bufsize, tokens, length)
                         * don't update time, but do adjust weight to offset
                         * the difference
                         */
                         * don't update time, but do adjust weight to offset
                         * the difference
                         */
-#ifndef xc_weight
-                       if (xc_weight != 0) {   /* XXX */
+#ifndef cc_weight
+                       if (cc_weight != 0) {   /* XXX */
                                p->weight += time - p->time;
                                if (!p->flag && p->weight >= wthreshold) {
                                        p->flag = 1;
                                        *pp++ = p;
                                p->weight += time - p->time;
                                if (!p->flag && p->weight >= wthreshold) {
                                        p->flag = 1;
                                        *pp++ = p;
-                                       qinsert(p, &xc_q1b);
+                                       qinsert(p, &cc_q1b);
                                }
                        }
 #endif
                        places[i] = p->places;
                        p->places = i;
                } else {
                                }
                        }
 #endif
                        places[i] = p->places;
                        p->places = i;
                } else {
-#ifndef xc_weight
+#ifndef cc_weight
                        if ((p->weight += p->time - time) < 0)
                        if ((p->weight += p->time - time) < 0)
-                               p->weight = xc_weight;
-                       else if ((p->weight += xc_weight) > limit)
+                               p->weight = cc_weight;
+                       else if ((p->weight += cc_weight) > limit)
                                p->weight = limit;
 #endif
                        p->time = time;
                                p->weight = limit;
 #endif
                        p->time = time;
@@ -537,13 +559,13 @@ xc_sweep(buffer, bufsize, tokens, length)
                        if (!p->flag &&
                            /* code must be < 0 if flag false here */
                            (p->bcount >= threshold
                        if (!p->flag &&
                            /* code must be < 0 if flag false here */
                            (p->bcount >= threshold
-#ifndef xc_weight
+#ifndef cc_weight
                             || p->weight >= wthreshold
 #endif
                             )) {
                                p->flag = 1;
                                *pp++ = p;
                             || p->weight >= wthreshold
 #endif
                             )) {
                                p->flag = 1;
                                *pp++ = p;
-                               qinsert(p, &xc_q1b);
+                               qinsert(p, &cc_q1b);
                        }
                        places[i] = p->places;
                        p->places = i;
                        }
                        places[i] = p->places;
                        p->places = i;
@@ -551,15 +573,15 @@ xc_sweep(buffer, bufsize, tokens, length)
        }
        if ((i = pp - tokens) > 0) {
                *pp = 0;
        }
        if ((i = pp - tokens) > 0) {
                *pp = 0;
-               if (xc_reverse)
-                       xc_sweep_reverse(tokens, places);
-               if (xc_sort && i > 1) {
-                       int xc_token_compare();
+               if (cc_reverse)
+                       cc_sweep_reverse(tokens, places);
+               if (cc_sort && i > 1) {
+                       int cc_token_compare();
                        qsort((char *) tokens, i, sizeof *tokens,
                        qsort((char *) tokens, i, sizeof *tokens,
-                             xc_token_compare);
+                             cc_token_compare);
                }
                }
-               if (xc_chop) {
-                       if ((i = i * xc_chop / 100) == 0)
+               if (cc_chop) {
+                       if ((i = i * cc_chop / 100) == 0)
                                i = 1;
                        tokens[i] = 0;
                }
                                i = 1;
                        tokens[i] = 0;
                }
@@ -568,11 +590,11 @@ xc_sweep(buffer, bufsize, tokens, length)
        return i;
 }
 
        return i;
 }
 
-xc_sweep_reverse(pp, places)
-       register struct xc **pp;
+cc_sweep_reverse(pp, places)
+       register struct cc **pp;
        register short *places;
 {
        register short *places;
 {
-       register struct xc *p;
+       register struct cc *p;
        register short front, back, t;
 
        while ((p = *pp++) != 0) {
        register short front, back, t;
 
        while ((p = *pp++) != 0) {
@@ -588,28 +610,33 @@ xc_sweep_reverse(pp, places)
        }
 }
 
        }
 }
 
-xc_compress_phase(output, bufsize, tokens, ntoken)
-       struct xc **output;
-       struct xc **tokens;
+cc_compress_phase(output, bufsize, tokens, ntoken)
+       struct cc **output;
+       struct cc **tokens;
 {
        register i;
 
        bzero((char *) output, bufsize * sizeof *output);
 {
        register i;
 
        bzero((char *) output, bufsize * sizeof *output);
-       for (i = 0; i < xc_npass0; i++)
-               xc_compress_phase1(output, tokens, ntoken, 0);
-       for (i = 0; i < xc_npass1; i++)
-               xc_compress_phase1(output, tokens, ntoken, 1);
-       xc_compress_cleanup(output, bufsize);
+       for (i = 0; i < cc_npass0; i++)
+               cc_compress_phase1(output, tokens, ntoken, 0);
+       for (i = 0; i < cc_npass1; i++)
+               cc_compress_phase1(output, tokens, ntoken, 1);
+       cc_compress_cleanup(output, bufsize);
 }
 
 }
 
-xc_compress_phase1(output, tokens, ntoken, flag)
-       register struct xc **output;
-       struct xc **tokens;
+cc_compress_phase1(output, tokens, ntoken, flag)
+       register struct cc **output;
+       struct cc **tokens;
 {
        register int i = 0;
 {
        register int i = 0;
-       register struct xc **pp;
+       register struct cc **pp;
+#ifdef STATS
+       int nt = 0, cc = 0, nc = 0;
+#endif
 
 #ifdef STATS
 
 #ifdef STATS
+       if (verbose >= 0)
+               time_begin();
        if (verbose > 0)
                printf("Compress:");
 #endif
        if (verbose > 0)
                printf("Compress:");
 #endif
@@ -617,9 +644,9 @@ xc_compress_phase1(output, tokens, ntoken, flag)
        while (pp < tokens + ntoken) {
 #ifdef STATS
                if (verbose > 0) {
        while (pp < tokens + ntoken) {
 #ifdef STATS
                if (verbose > 0) {
-                       xc_ntoken_stat = 0;
-                       xc_ccount_stat = 0;
-                       xc_ncover_stat = 0;
+                       ntoken_stat = 0;
+                       ccount_stat = 0;
+                       ncover_stat = 0;
                        if (i > 2) {
                                printf("\n         ");
                                i = 0;
                        if (i > 2) {
                                printf("\n         ");
                                i = 0;
@@ -629,28 +656,34 @@ xc_compress_phase1(output, tokens, ntoken, flag)
                        (void) fflush(stdout);
                }
 #endif
                        (void) fflush(stdout);
                }
 #endif
-               pp += xc_compress(output, pp, flag);
+               pp += cc_compress(output, pp, flag);
 #ifdef STATS
 #ifdef STATS
-               if (verbose > 0)
-                       printf(" %dt %du %dc)", xc_ntoken_stat, xc_ccount_stat,
-                              xc_ncover_stat);
+               if (verbose > 0) {
+                       printf(" %dt %du %dc)", ntoken_stat, ccount_stat,
+                              ncover_stat);
+                       nt += ntoken_stat;
+                       cc += ccount_stat;
+                       nc += ncover_stat;
+               }
 #endif
        }
 #ifdef STATS
        if (verbose > 0)
 #endif
        }
 #ifdef STATS
        if (verbose > 0)
-               printf("\n");
+               printf("\n   total: (%dt %du %dc)\n", nt, cc, nc);
+       if (verbose >= 0)
+               time_end();
 #endif
 }
 
 #endif
 }
 
-xc_compress_cleanup(output, bufsize)
-       register struct xc **output;
+cc_compress_cleanup(output, bufsize)
+       register struct cc **output;
 {
 {
-       register struct xc **end;
+       register struct cc **end;
 
        /* the previous output phase may have been interrupted */
 
        /* the previous output phase may have been interrupted */
-       qinsertq(&xc_q0b, &xc_q0a);
+       qinsertq(&cc_q0b, &cc_q0a);
        for (end = output + bufsize; output < end;) {
        for (end = output + bufsize; output < end;) {
-               register struct xc *p;
+               register struct cc *p;
                register length;
                if ((p = *output) == 0) {
                        output++;
                register length;
                if ((p = *output) == 0) {
                        output++;
@@ -659,12 +692,12 @@ xc_compress_cleanup(output, bufsize)
                length = p->length;
                if (!p->flag) {
                } else if (p->code >= 0) {
                length = p->length;
                if (!p->flag) {
                } else if (p->code >= 0) {
-                       qinsert(p, &xc_q0b);
+                       qinsert(p, &cc_q0b);
                        p->flag = 0;
                } else if (p->ccount == 0) {
                        *output = 0;
                } else if (p->ccount >= thresh(length)
                        p->flag = 0;
                } else if (p->ccount == 0) {
                        *output = 0;
                } else if (p->ccount >= thresh(length)
-#ifndef xc_weight
+#ifndef cc_weight
                           || wthreshp(p->weight, length)
 #endif
                           ) {
                           || wthreshp(p->weight, length)
 #endif
                           ) {
@@ -677,25 +710,25 @@ xc_compress_cleanup(output, bufsize)
        }
 }
 
        }
 }
 
-xc_compress(output, tokens, flag)
-       struct xc **output;
-       struct xc **tokens;
+cc_compress(output, tokens, flag)
+       struct cc **output;
+       struct cc **tokens;
        char flag;
 {
        char flag;
 {
-       struct xc **pp = tokens;
-       register struct xc *p = *pp++;
+       struct cc **pp = tokens;
+       register struct cc *p = *pp++;
        int length = p->length;
        int threshold = thresh(length);
        int length = p->length;
        int threshold = thresh(length);
-#ifndef xc_weight
+#ifndef cc_weight
        short wthreshold = wthresh(length);
 #endif
        short wthreshold = wthresh(length);
 #endif
-       short *places = xc_places[length];
-       int *initial_scores = xc_initial_scores[length];
+       short *places = cc_places[length];
+       int *initial_scores = cc_initial_scores[length];
        int initial_score0 = put_token_score(length);
 
        do {
                int score;
        int initial_score0 = put_token_score(length);
 
        do {
                int score;
-               register struct xc_undo *undop;
+               register struct cc_undo *undop;
                int ccount;
 #ifdef STATS
                int ncover;
                int ccount;
 #ifdef STATS
                int ncover;
@@ -707,7 +740,7 @@ xc_compress(output, tokens, flag)
                        continue;
                if (p->code >= 0 || ccount >= threshold)
                        score = 0;
                        continue;
                if (p->code >= 0 || ccount >= threshold)
                        score = 0;
-#ifndef xc_weight
+#ifndef cc_weight
                else if (p->weight >= wthreshold)
                        /* allow one fewer match than normal */
                        /* XXX, should adjust for ccount */
                else if (p->weight >= wthreshold)
                        /* allow one fewer match than normal */
                        /* XXX, should adjust for ccount */
@@ -715,17 +748,17 @@ xc_compress(output, tokens, flag)
 #endif
                else
                        score = initial_scores[ccount];
 #endif
                else
                        score = initial_scores[ccount];
-               undop = xc_undo;
+               undop = cc_undo;
 #ifdef STATS
                ncover = 0;
 #endif
                for (i = p->places; i >= 0; i = places[i]) {
 #ifdef STATS
                ncover = 0;
 #endif
                for (i = p->places; i >= 0; i = places[i]) {
-                       register struct xc **jp;
-                       register struct xc *x;
-                       register struct xc **ip = output + i;
+                       register struct cc **jp;
+                       register struct cc *x;
+                       register struct cc **ip = output + i;
                        register score0 = initial_score0;
                        register score0 = initial_score0;
-                       struct xc **iip = ip + length;
-                       struct xc_undo *undop1 = undop;
+                       struct cc **iip = ip + length;
+                       struct cc_undo *undop1 = undop;
 
                        if ((x = *(jp = ip)) != 0)
                                goto z;
 
                        if ((x = *(jp = ip)) != 0)
                                goto z;
@@ -772,15 +805,15 @@ xc_compress(output, tokens, flag)
                }
                if (score > 0) {
 #ifdef STATS
                }
                if (score > 0) {
 #ifdef STATS
-                       xc_ccount_stat += ccount - p->ccount;
-                       xc_ntoken_stat++;
-                       xc_ncover_stat += ncover;
+                       ccount_stat += ccount - p->ccount;
+                       ntoken_stat++;
+                       ncover_stat += ncover;
 #endif
                        p->ccount = ccount;
                } else {
 #endif
                        p->ccount = ccount;
                } else {
-                       register struct xc_undo *u = xc_undo;
+                       register struct cc_undo *u = cc_undo;
                        while (--undop >= u) {
                        while (--undop >= u) {
-                               register struct xc *x;
+                               register struct cc *x;
                                if (*undop->pos = x = undop->val)
                                        x->ccount++;
                        }
                                if (*undop->pos = x = undop->val)
                                        x->ccount++;
                        }
@@ -789,53 +822,49 @@ xc_compress(output, tokens, flag)
        return pp - tokens;
 }
 
        return pp - tokens;
 }
 
-xcwrite(s, n, x)
-       register char *s;
-       register n;
+cc_output_phase(buffer, output, bufsize)
+       register char *buffer;
+       register struct cc **output;
+       register bufsize;
 {
        register i;
 {
        register i;
-       register struct xc *p, *p1;
-       register struct xc **output = xc_output + x;
+       register struct cc *p, *p1;
 
 
-       if (n < tt.tt_token_min) {
-               (*tt.tt_write)(s, n);
-               return;
-       }
-       for (i = 0; i < n;) {
+       for (i = 0; i < bufsize;) {
                if ((p = output[i]) == 0) {
                if ((p = output[i]) == 0) {
-                       (*tt.tt_putc)(s[i]);
+                       ttputc(buffer[i]);
                        i++;
                } else if (p->code >= 0) {
                        if (--p->ccount == 0)
                        i++;
                } else if (p->code >= 0) {
                        if (--p->ccount == 0)
-                               qinsert(p, &xc_q0a);
+                               qinsert(p, &cc_q0a);
                        (*tt.tt_put_token)(p->code, p->string, p->length);
                        wwntokuse++;
                        wwntoksave += put_token_score(p->length);
                        i += p->length;
                        (*tt.tt_put_token)(p->code, p->string, p->length);
                        wwntokuse++;
                        wwntoksave += put_token_score(p->length);
                        i += p->length;
-               } else if ((p1 = xc_q0a.qback) != &xc_q0a) {
+               } else if ((p1 = cc_q0a.qback) != &cc_q0a) {
                        p->code = p1->code;
                        p1->code = -1;
                        p->code = p1->code;
                        p1->code = -1;
-                       qinsert(p1, &xc_q1a);
+                       qinsert(p1, &cc_q1a);
                        if (--p->ccount == 0)
                        if (--p->ccount == 0)
-                               qinsert(p, &xc_q0a);
+                               qinsert(p, &cc_q0a);
                        else
                        else
-                               qinsert(p, &xc_q0b);
+                               qinsert(p, &cc_q0b);
                        (*tt.tt_set_token)(p->code, p->string, p->length);
                        wwntokdef++;
                        wwntoksave -= tt.tt_set_token_cost;
                        i += p->length;
                } else {
                        p->ccount--;
                        (*tt.tt_set_token)(p->code, p->string, p->length);
                        wwntokdef++;
                        wwntoksave -= tt.tt_set_token_cost;
                        i += p->length;
                } else {
                        p->ccount--;
-                       (*tt.tt_write)(p->string, p->length);
+                       ttwrite(p->string, p->length);
                        wwntokbad++;
                        i += p->length;
                }
        }
                        wwntokbad++;
                        i += p->length;
                }
        }
-       wwntokc += n;
+       wwntokc += bufsize;
 }
 
 }
 
-xc_token_compare(p1, p2)
-       struct xc **p1, **p2;
+cc_token_compare(p1, p2)
+       struct cc **p1, **p2;
 {
        return (*p2)->bcount - (*p1)->bcount;
 }
 {
        return (*p2)->bcount - (*p1)->bcount;
 }
index 261c12f..a23ac97 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.24 (Berkeley) %G%
+ *     @(#)tt.h        3.25 (Berkeley) %G%
  */
 
 /*
  */
 
 /*
@@ -59,6 +59,7 @@ 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) */
+       short tt_padc;                  /* the pad character */
        int tt_ntoken;                  /* number of compression tokens */
        int tt_token_min;               /* minimun token size */
        int tt_token_max;               /* maximum token size */
        int tt_ntoken;                  /* number of compression tokens */
        int tt_token_min;               /* minimun token size */
        int tt_token_max;               /* maximum token size */
@@ -67,9 +68,18 @@ struct tt {
 
                /* the frame characters */
        short *tt_frame;
 
                /* the frame characters */
        short *tt_frame;
+
+               /* the output routine */
+       int (*tt_flush)();
 };
 struct tt tt;
 
 };
 struct tt tt;
 
+/*
+ * tt_padc is used by the compression routine.
+ * It is a short to allow the driver to indicate that there is no padding.
+ */
+#define TT_PADC_NONE 0x100
+
 /*
  * List of terminal drivers.
  */
 /*
  * List of terminal drivers.
  */
@@ -104,11 +114,11 @@ int tttputc();
  * These variables have different meanings from the ww_ob* variables.
  * But I'm too lazy to think up different names.
  */
  * These variables have different meanings from the ww_ob* variables.
  * But I'm too lazy to think up different names.
  */
-char tt_ob[512];
+char *tt_ob;
 char *tt_obp;
 char *tt_obe;
 #define ttputc(c)      (tt_obp < tt_obe ? (*tt_obp++ = (c)) \
 char *tt_obp;
 char *tt_obe;
 #define ttputc(c)      (tt_obp < tt_obe ? (*tt_obp++ = (c)) \
-                               : (ttflush(), *tt_obp++ = (c)))
+                               : ((*tt.tt_flush)(), *tt_obp++ = (c)))
 
 /*
  * Convenience macros for the drivers
 
 /*
  * Convenience macros for the drivers
index 8921e62..196d29b 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ttinit.c   3.21 (Berkeley) %G%";
+static char sccsid[] = "@(#)ttinit.c   3.22 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -47,18 +47,25 @@ struct tt_tab tt_tab[] = {
 
 ttinit()
 {
 
 ttinit()
 {
+       int i;
        register struct tt_tab *tp;
        register char *p, *q;
        register char *t;
        struct winsize winsize;
        register struct tt_tab *tp;
        register char *p, *q;
        register char *t;
        struct winsize winsize;
+       int ttflush();
 
        tt_strp = tt_strings;
 
        /*
         * Set output buffer size to about 1 second of output time.
         */
 
        tt_strp = tt_strings;
 
        /*
         * Set output buffer size to about 1 second of output time.
         */
+       i = MIN(wwbaud/10, 512);
+       if ((tt_ob = malloc((unsigned) i)) == 0) {
+               wwerrno = WWE_NOMEM;
+               return -1;
+       }
        tt_obp = tt_ob;
        tt_obp = tt_ob;
-       tt_obe = tt_ob + MIN(wwbaud/10, sizeof tt_ob);
+       tt_obe = tt_ob + i;
 
        /*
         * Use the standard name of the terminal (i.e. the second
 
        /*
         * Use the standard name of the terminal (i.e. the second
@@ -94,5 +101,6 @@ ttinit()
                tt.tt_nrow = winsize.ws_row;
                tt.tt_ncol = winsize.ws_col;
        }
                tt.tt_nrow = winsize.ws_row;
                tt.tt_ncol = winsize.ws_col;
        }
+       tt.tt_flush = ttflush;
        return 0;
 }
        return 0;
 }
index d400c8e..077283f 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ttoutput.c 3.6 (Berkeley) %G%";
+static char sccsid[] = "@(#)ttoutput.c 3.7 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -74,20 +74,20 @@ ttwrite(s, n)
                break;
        case 2:
                if (tt_obe - tt_obp < 2)
                break;
        case 2:
                if (tt_obe - tt_obp < 2)
-                       ttflush();
+                       (*tt.tt_flush)();
                *tt_obp++ = *s++;
                *tt_obp++ = *s;
                break;
        case 3:
                if (tt_obe - tt_obp < 3)
                *tt_obp++ = *s++;
                *tt_obp++ = *s;
                break;
        case 3:
                if (tt_obe - tt_obp < 3)
-                       ttflush();
+                       (*tt.tt_flush)();
                *tt_obp++ = *s++;
                *tt_obp++ = *s++;
                *tt_obp++ = *s;
                break;
        case 4:
                if (tt_obe - tt_obp < 4)
                *tt_obp++ = *s++;
                *tt_obp++ = *s++;
                *tt_obp++ = *s;
                break;
        case 4:
                if (tt_obe - tt_obp < 4)
-                       ttflush();
+                       (*tt.tt_flush)();
                *tt_obp++ = *s++;
                *tt_obp++ = *s++;
                *tt_obp++ = *s++;
                *tt_obp++ = *s++;
                *tt_obp++ = *s++;
                *tt_obp++ = *s++;
@@ -95,7 +95,7 @@ ttwrite(s, n)
                break;
        case 5:
                if (tt_obe - tt_obp < 5)
                break;
        case 5:
                if (tt_obe - tt_obp < 5)
-                       ttflush();
+                       (*tt.tt_flush)();
                *tt_obp++ = *s++;
                *tt_obp++ = *s++;
                *tt_obp++ = *s++;
                *tt_obp++ = *s++;
                *tt_obp++ = *s++;
                *tt_obp++ = *s++;
@@ -107,7 +107,7 @@ ttwrite(s, n)
                        register m;
 
                        while ((m = tt_obe - tt_obp) == 0)
                        register m;
 
                        while ((m = tt_obe - tt_obp) == 0)
-                               ttflush();
+                               (*tt.tt_flush)();
                        if ((m = tt_obe - tt_obp) > n)
                                m = n;
                        bcopy(s, tt_obp, m);
                        if ((m = tt_obe - tt_obp) > n)
                                m = n;
                        bcopy(s, tt_obp, m);
index f0523b4..34c5fcf 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)ttzapple.c 3.7 (Berkeley) %G%";
+static char sccsid[] = "@(#)ttzapple.c 3.8 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -100,6 +100,7 @@ zz_move(row, col)
        register x;
 
        if (tt.tt_row == row) {
        register x;
 
        if (tt.tt_row == row) {
+same_row:
                if ((x = col - tt.tt_col) == 0)
                        return;
                if (col == 0) {
                if ((x = col - tt.tt_col) == 0)
                        return;
                if (col == 0) {
@@ -158,8 +159,12 @@ home:
                        goto out;
                }
                if (row == tt.tt_row + 1) {
                        goto out;
                }
                if (row == tt.tt_row + 1) {
-                       ttctrl('m');
+                       /*
+                        * Do newline first to match the sequence
+                        * for scroll down and return
+                        */
                        ttctrl('j');
                        ttctrl('j');
+                       ttctrl('m');
                        goto out;
                }
                if (row == NROW - 1) {
                        goto out;
                }
                if (row == NROW - 1) {
@@ -168,6 +173,15 @@ ll:
                        goto out;
                }
        }
                        goto out;
                }
        }
+       /* favor local motion for better compression */
+       if (row == tt.tt_row + 1) {
+               ttctrl('j');
+               goto same_row;
+       }
+       if (row == tt.tt_row - 1) {
+               ttctrl('k');
+               goto same_row;
+       }
        ttesc('=');
        ttputc(' ' + row);
        ttputc(' ' + col);
        ttesc('=');
        ttputc(' ' + row);
        ttputc(' ' + col);
@@ -278,9 +292,6 @@ zz_set_token(t, s, n)
        s[n - 1] |= 0x80;
        ttwrite(s, n);
        s[n - 1] &= ~0x80;
        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++;
 }
 
 /*ARGSUSED*/
 }
 
 /*ARGSUSED*/
@@ -297,9 +308,6 @@ zz_put_token(t, s, n)
                tt.tt_col += 3;
        }
        ttputc(t + 0x81);
                tt.tt_col += 3;
        }
        ttputc(t + 0x81);
-       tt.tt_col += n;
-       if (tt.tt_col == NCOL)
-               tt.tt_col = 0, tt.tt_row++;
 }
 
 tt_zapple()
 }
 
 tt_zapple()
@@ -326,6 +334,7 @@ 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_padc = TT_PADC_NONE;
        tt.tt_ntoken = 127;
        tt.tt_set_token = zz_set_token;
        tt.tt_put_token = zz_put_token;
        tt.tt_ntoken = 127;
        tt.tt_set_token = zz_set_token;
        tt.tt_put_token = zz_put_token;
index c6a3c61..3d45f2f 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)xx.c       3.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)xx.c       3.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -28,8 +28,8 @@ xxinit()
        if (ttinit() < 0)
                return -1;
        xxbufsize = tt.tt_nrow * tt.tt_ncol * 2;
        if (ttinit() < 0)
                return -1;
        xxbufsize = tt.tt_nrow * tt.tt_ncol * 2;
-       /* xcinit may choose to change xxbufsize */
-       if (tt.tt_ntoken > 0 && xcinit() < 0)
+       /* ccinit may choose to change xxbufsize */
+       if (tt.tt_ntoken > 0 && ccinit() < 0)
                return -1;
        xxbuf = malloc((unsigned) xxbufsize * sizeof *xxbuf);
        if (xxbuf == 0) {
                return -1;
        xxbuf = malloc((unsigned) xxbufsize * sizeof *xxbuf);
        if (xxbuf == 0) {
@@ -45,7 +45,7 @@ xxstart()
 {
        (*tt.tt_start)();
        if (tt.tt_ntoken > 0)
 {
        (*tt.tt_start)();
        if (tt.tt_ntoken > 0)
-               xcstart();
+               ccstart();
        xxreset();                      /* might be a restart */
 }
 
        xxreset();                      /* might be a restart */
 }
 
@@ -59,8 +59,10 @@ xxend()
        if (tt.tt_scroll_down)
                (*tt.tt_scroll_down)(1);
        (*tt.tt_move)(tt.tt_nrow - 1, 0);
        if (tt.tt_scroll_down)
                (*tt.tt_scroll_down)(1);
        (*tt.tt_move)(tt.tt_nrow - 1, 0);
+       if (tt.tt_ntoken > 0)
+               ccend();
        (*tt.tt_end)();
        (*tt.tt_end)();
-       ttflush();
+       (*tt.tt_flush)();
 }
 
 struct xx *
 }
 
 struct xx *
index 9b5af4b..f89dbd0 100644 (file)
@@ -16,7 +16,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)xxflush.c  3.3 (Berkeley) %G%";
+static char sccsid[] = "@(#)xxflush.c  3.4 (Berkeley) %G%";
 #endif /* not lint */
 
 #include "ww.h"
 #endif /* not lint */
 
 #include "ww.h"
@@ -28,8 +28,6 @@ xxflush(intr)
 {
        register struct xx *xp, *xq;
 
 {
        register struct xx *xp, *xq;
 
-       if (tt.tt_ntoken > 0)
-               xcscan(xxbuf, xxbufp - xxbuf);  /* XXX, starting point */
        for (xp = xx_head; xp != 0 && !(intr && wwinterrupt()); xp = xq) {
                switch (xp->cmd) {
                case xc_move:
        for (xp = xx_head; xp != 0 && !(intr && wwinterrupt()); xp = xq) {
                switch (xp->cmd) {
                case xc_move:
@@ -66,10 +64,7 @@ xxflush(intr)
                case xc_write:
                        (*tt.tt_move)(xp->arg0, xp->arg1);
                        tt.tt_nmodes = xp->arg3;
                case xc_write:
                        (*tt.tt_move)(xp->arg0, xp->arg1);
                        tt.tt_nmodes = xp->arg3;
-                       if (tt.tt_ntoken > 0)
-                               xcwrite(xp->buf, xp->arg2, xp->buf - xxbuf);
-                       else
-                               (*tt.tt_write)(xp->buf, xp->arg2);
+                       (*tt.tt_write)(xp->buf, xp->arg2);
                        break;
                }
                xq = xp->link;
                        break;
                }
                xq = xp->link;
@@ -79,7 +74,7 @@ xxflush(intr)
                xx_tail = 0;
                xxbufp = xxbuf;
        }
                xx_tail = 0;
                xxbufp = xxbuf;
        }
-       ttflush();
+       (*tt.tt_flush)();
 }
 
 xxflush_scroll(xp)
 }
 
 xxflush_scroll(xp)