OSDN Git Service

use the struct heap_t for freq[]
[lha/olha.git] / decode.c
index f0d0a2a..a452029 100644 (file)
--- a/decode.c
+++ b/decode.c
@@ -3,19 +3,17 @@
 ***********************************************************/
 #include "ar.h"
 
-static int j;                   /* remaining bytes to copy */
-
 extern struct lha_opts opts;
 
 void
-decode_start(void)
+decode_start(struct lzh_istream *rp)
 {
-    huf_decode_start(opts.method);
-    j = 0;
+    huf_decode_start(rp, opts.method);
 }
 
 void
-decode(uint count, uchar buffer[])
+decode(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
@@ -24,29 +22,28 @@ decode(uint count, uchar buffer[])
            Call decode_start() once for each new file
            before calling this function. */
 {
-    static uint i;
     uint r, c;
 
     r = 0;
-    while (--j >= 0) {
-        buffer[r] = buffer[i];
-        i = (i + 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();
+        c = decode_c(rp);
         if (c <= UCHAR_MAX) {
-            buffer[r] = c;
+            buf[r] = c;
             if (++r == count)
                 return;
         }
         else {
-            j = c - (UCHAR_MAX + 1 - THRESHOLD);
-            i = (r - decode_p() - 1) & (MAXDICSIZ - 1);
-            while (--j >= 0) {
-                buffer[r] = buffer[i];
-                i = (i + 1) & (MAXDICSIZ - 1);
+            *slide_len = c - (UCHAR_MAX + 1 - THRESHOLD);
+            *slide_off = (r - decode_p(rp) - 1) & (MAXDICSIZ - 1);
+            while (--*slide_len >= 0) {
+                buf[r] = buf[*slide_off];
+                *slide_off = (*slide_off+1) & (MAXDICSIZ - 1);
                 if (++r == count)
                     return;
             }