OSDN Git Service

static variable i and j was removed, again
authorKoji Arai <jca02266@gmail.com>
Thu, 5 Jun 2008 14:01:10 +0000 (23:01 +0900)
committerKoji Arai <jca02266@gmail.com>
Thu, 5 Jun 2008 14:01:10 +0000 (23:01 +0900)
ar.h
decode.c
extract.c
prototypes.h

diff --git a/ar.h b/ar.h
index 7fc23a3..b9a5e64 100644 (file)
--- a/ar.h
+++ b/ar.h
@@ -17,10 +17,6 @@ struct lzh_istream {
 
     unsigned short bitbuf, subbitbuf;
     int bitcount;
 
     unsigned short bitbuf, subbitbuf;
     int bitcount;
-
-    /* slide */
-    unsigned int slide_off;
-    int slide_len;
 };
 
 struct lzh_ostream {
 };
 
 struct lzh_ostream {
index 7c99ce8..a452029 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);
 decode_start(struct lzh_istream *rp)
 {
     huf_decode_start(rp, opts.method);
-    rp->slide_len = rp->slide_off = 0;
 }
 
 void
 }
 
 void
-decode(struct lzh_istream *rp, uint count, char *buf)
+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
         /* The calling function must keep the number of
            bytes to be processed.  This function decodes
            either 'count' bytes or 'DICSIZ' bytes, whichever
@@ -25,9 +25,9 @@ decode(struct lzh_istream *rp, uint count, char *buf)
     uint r, c;
 
     r = 0;
     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;
     }
         if (++r == count)
             return;
     }
@@ -39,11 +39,11 @@ decode(struct lzh_istream *rp, uint count, char *buf)
                 return;
         }
         else {
                 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(rp) - 1) & (MAXDICSIZ - 1);
+            while (--*slide_len >= 0) {
+                buf[r] = buf[*slide_off];
+                *slide_off = (*slide_off+1) & (MAXDICSIZ - 1);
                 if (++r == count)
                     return;
             }
                 if (++r == count)
                     return;
             }
index e4565b5..22943b5 100644 (file)
--- a/extract.c
+++ b/extract.c
@@ -9,7 +9,6 @@ void
 extract(struct lzh_istream *rp, int to_file, struct lzh_header *h)
 {
     int n;
 extract(struct lzh_istream *rp, int to_file, struct lzh_header *h)
 {
     int n;
-    char buf[MAXDICSIZ];
     FILE *outfile = NULL;
     unsigned int crc;
 
     FILE *outfile = NULL;
     unsigned int crc;
 
@@ -55,15 +54,22 @@ extract(struct lzh_istream *rp, int to_file, struct lzh_header *h)
         skip(rp->fp, h);
     }
     else {
         skip(rp->fp, h);
     }
     else {
+        char buf[MAXDICSIZ];
+        unsigned int slide_off = 0;
+        int slide_len = 0;
+
         crc = INIT_CRC;
         if (opts.method->dicbit != 0)
             decode_start(rp);
         while (h->origsize != 0) {
             n = (uint) ((h->origsize > MAXDICSIZ) ? MAXDICSIZ : h->origsize);
             if (opts.method->dicbit != 0)
         crc = INIT_CRC;
         if (opts.method->dicbit != 0)
             decode_start(rp);
         while (h->origsize != 0) {
             n = (uint) ((h->origsize > MAXDICSIZ) ? MAXDICSIZ : h->origsize);
             if (opts.method->dicbit != 0)
-                decode(rp, n, buf);
-            else if (fread(buf, 1, n, rp->fp) != n)
-                error("Can't read");
+                decode(rp, n, buf, &slide_off, &slide_len);
+            else {
+                /* no compress */
+                if (fread(buf, 1, n, rp->fp) != n)
+                    error("Can't read");
+            }
             fwrite_crc(buf, n, outfile, &crc);
             if (outfile != stdout && opts.quiet < 1) {
                 putc('.', stdout);
             fwrite_crc(buf, n, outfile, &crc);
             if (outfile != stdout && opts.quiet < 1) {
                 putc('.', stdout);
index 624f76b..a5cb8f8 100644 (file)
@@ -25,7 +25,7 @@ void init_putbits P_((struct lzh_ostream *wp));
 void encode P_((struct lzh_ostream *wp, FILE *rfp));
 /* decode.c */
 void decode_start P_((struct lzh_istream *rp));
 void encode P_((struct lzh_ostream *wp, FILE *rfp));
 /* decode.c */
 void decode_start P_((struct lzh_istream *rp));
-void decode P_((struct lzh_istream *rp, uint count, char *buf));
+void decode P_((struct lzh_istream *rp, uint count, char *buf, unsigned int *slide_off, int *slide_len));
 /* maketree.c */
 int make_tree P_((int nparm, ushort freqparm[], uchar lenparm[], ushort codeparm[]));
 /* maketbl.c */
 /* maketree.c */
 int make_tree P_((int nparm, ushort freqparm[], uchar lenparm[], ushort codeparm[]));
 /* maketbl.c */