shithub: MicroHs

Download patch

ref: 05d304cec8ea2a001ae0aa396a906e6772ea0e95
parent: 815a37febe7bd6d00d12efa4ffd02a42ec3e7e1f
author: Lennart Augustsson <lennart@augustsson.net>
date: Sat Mar 2 21:15:48 EST 2024

Get rid of unused LZW compressor.

--- a/src/runtime/bfile.c
+++ b/src/runtime/bfile.c
@@ -217,166 +217,6 @@
 }
 #endif
 
-/***************** BFILE via simple LZW decompression *******************/
-
-#define DICTSIZE 4096
-#define ASCIISIZE 96            /* ' ' - '~', '\n' */
-
-struct BFILE_lzw {
-  BFILE    mets;
-  BFILE    *bfile;              /* underlying BFILE */
-  int      unget;               /* storage for a single ungetb */
-  char     *table[DICTSIZE];    /* dictionary */
-  int      table_size;          /* next dictionary slot */
-  char     *ptr;                /* pointer into output string */
-  int      old;                 /* previous code word */
-  int      ch;                  /* previous first character */
-  char     buf[DICTSIZE+1];     /* buffer holding output string */
-  int      rdstate;             /* state of 3 bytes to 2 codewords transducer */
-  int      rdres;               /* saved transducer bits */
-};
-
-/* Get a code word.  It's 12 bits, so 2 codewords are spread over 3 bytes.
- * XXX This has 4096 hardcoded.
-*/
-int
-getcode_lzw(struct BFILE_lzw *p)
-{
-  int r;
-
-  if (p->rdstate == 0) {
-    r = getb(p->bfile);
-    if (r < 0)
-      return -1;
-    r |= getb(p->bfile) << 8;
-    p->rdres = r >> 12;         /* save 4 bits */
-    p->rdstate = 1;
-    return r & 0xfff;
-  } else {
-    r = p->rdres;
-    r |= getb(p->bfile) << 4;
-    p->rdstate = 0;
-    return r;
-  }
-}
-
-char *
-str_lzw(const char *s, int c)
-{
-  int l = strlen(s);
-  char *p = MALLOC(l + 1 + 1);
-  if (!p)
-    memerr();
-  strcpy(p, s);
-  p[l] = c;
-  p[l+1] = '\0';
-  return p;
-}
-
-int
-getb_lzw(BFILE *bp)
-{
-  struct BFILE_lzw *p = (struct BFILE_lzw*)bp;
-  CHECKBFILE(bp, getb_lzw);
-  char *s;
-  int c, n, l;
-
-  /* Do we have an ungetb character? */
-  if (p->unget >= 0) {
-    c = p->unget;
-    p->unget = -1;
-    return c;
-  }
-  /* Are we in the middle of emitting a string? */
-  if (p->ptr) {
-    c = *p->ptr++;
-    if (c) {
-      //PRINT("c='%c'\n", c);
-      return c;
-    }
-    p->ptr = 0;
-  }
-  n = getcode_lzw(p);
-  if (n < 0)
-    return -1;
-  if (n >= DICTSIZE)
-    ERR("getcode_lzw 1");
-  s = p->table[n];
-  if (!s) {
-    char *os = p->table[p->old];
-    strcpy(p->buf, os);
-    l = strlen(os);
-    p->buf[l++] = p->ch;
-    p->buf[l] = '\0';
-  } else {
-    strcpy(p->buf, s);
-  }
-  p->ptr = p->buf;
-  p->ch = p->buf[0];
-  if (p->table_size < DICTSIZE) {
-    p->table[p->table_size++] = str_lzw(p->table[p->old], p->ch);
-  }
-  p->old = n;
-  return *p->ptr++;
-}
-
-void
-ungetb_lzw(int c, BFILE *bp)
-{
-  struct BFILE_lzw *p = (struct BFILE_lzw*)bp;
-  CHECKBFILE(bp, getb_lzw);
-  if (p->unget >= 0)
-    ERR("ungetb_lzw");
-  p->unget = c;
-}
-
-void
-closeb_lzw(BFILE *bp)
-{
-  struct BFILE_lzw *p = (struct BFILE_lzw*)bp;
-  CHECKBFILE(bp, getb_lzw);
-  int i;
-
-  for (i = 0; i < DICTSIZE; i++) {
-    if (p->table[i])
-      FREE(p->table[i]);
-  }
-  closeb(p->bfile);
-  FREE(p);
-}
-
-BFILE *
-add_lzw_decompressor(BFILE *file)
-{
-  struct BFILE_lzw *p = MALLOC(sizeof(struct BFILE_lzw));
-  int i;
-  
-  if (!p)
-    memerr();
-  memset(p, 0, sizeof(struct BFILE_lzw));
-  p->mets.getb = getb_lzw;
-  p->mets.ungetb = ungetb_lzw;
-  p->mets.putb = 0;             /* no compressor yet. */
-  p->mets.flushb = 0;
-  p->mets.closeb = closeb_lzw;
-  p->bfile = file;
-  p->unget = -1;
-
-  /* initialize dictionary with printable ASCII */
-  for(i = 0; i < ASCIISIZE-1; i++) {
-    p->table[i] = str_lzw("", i + ' ');
-  }
-  p->table[i++] = str_lzw("", '\n');
-  p->table_size = i;
-
-  /* set up decompressore state */
-  p->old = getcode_lzw(p);
-  strcpy(p->buf, p->table[p->old]);
-  p->ch = p->buf[0];
-  p->ptr = p->buf;
-  
-  return (BFILE *)p;
-}
 
 #if WANT_LZ77
 /***************** BFILE via simple LZ77 decompression *******************/
--- a/src/runtime/eval.c
+++ b/src/runtime/eval.c
@@ -3219,11 +3219,8 @@
     BFILE *bf = openb_buf(combexpr, combexprlen);
     c = getb(bf);
     /* Compressed combinators start with a 'Z' or 'z', otherwise 'v' (for version) */
-    if (c == 'Z') {
-      /* add compressor transducer */
-      bf = add_lzw_decompressor(bf);
-    } else if (c == 'z') {
-      /* add compressor transducer */
+    if (c == 'z') {
+      /* add LZ77 compressor transducer */
       bf = add_lz77_decompressor(bf);
     } else {
       /* put it back, we need it */
--