OSDN Git Service

io.c:fllbuf() was refined
[lha/olha.git] / decode.c
index 7c99ce8..d9c77d7 100644 (file)
--- a/decode.c
+++ b/decode.c
@@ -9,11 +9,11 @@ void
 decode_start(struct lzh_istream *rp)
 {
     huf_decode_start(rp, opts.method);
-    rp->slide_len = rp->slide_off = 0;
 }
 
 void
-decode(struct lzh_istream *rp, uint count, char *buf)
+decode(struct huf_t *huf, struct lzh_istream *rp, uint count,
+       char *buf, unsigned int *slide_off, int *slide_len)
         /* The calling function must keep the number of
            bytes to be processed.  This function decodes
            either 'count' bytes or 'DICSIZ' bytes, whichever
@@ -25,25 +25,25 @@ decode(struct lzh_istream *rp, uint count, char *buf)
     uint r, c;
 
     r = 0;
-    while (--rp->slide_len >= 0) {
-        buf[r] = buf[rp->slide_off];
-        rp->slide_off = (rp->slide_off+1) & (MAXDICSIZ - 1);
+    while (--*slide_len >= 0) {
+        buf[r] = buf[*slide_off];
+        *slide_off = (*slide_off+1) & (MAXDICSIZ - 1);
         if (++r == count)
             return;
     }
     for (;;) {
-        c = decode_c(rp);
+        c = decode_c(huf, rp);
         if (c <= UCHAR_MAX) {
             buf[r] = c;
             if (++r == count)
                 return;
         }
         else {
-            rp->slide_len = c - (UCHAR_MAX + 1 - THRESHOLD);
-            rp->slide_off = (r - decode_p(rp) - 1) & (MAXDICSIZ - 1);
-            while (--rp->slide_len >= 0) {
-                buf[r] = buf[rp->slide_off];
-                rp->slide_off = (rp->slide_off+1) & (MAXDICSIZ - 1);
+            *slide_len = c - (UCHAR_MAX + 1 - THRESHOLD);
+            *slide_off = (r - decode_p(huf, rp) - 1) & (MAXDICSIZ - 1);
+            while (--*slide_len >= 0) {
+                buf[r] = buf[*slide_off];
+                *slide_off = (*slide_off+1) & (MAXDICSIZ - 1);
                 if (++r == count)
                     return;
             }