OSDN Git Service

untabify
[lha/olha.git] / encode.c
index e054a20..ec26683 100644 (file)
--- a/encode.c
+++ b/encode.c
@@ -149,7 +149,7 @@ replace_node(node old, node new)
 static void
 split(struct match_t *match, node old)
 {
-    node new, t;
+    node new;
 
     new = avail;
     avail = next[new];
@@ -267,7 +267,7 @@ delete_node(void)
 #if PERCOLATE
     node q, r, s, t, u;
 #else
-    node r, s, t, u;
+    node r, s, t;
 #endif
 
     if (parent[pos] == NIL)
@@ -319,17 +319,18 @@ delete_node(void)
 }
 
 static void
-get_next_match(struct match_t *match)
+get_next_match(struct lzh_ostream *wp, FILE *rfp, struct match_t *match)
 {
     int n;
 
     remainder--;
     if (++pos == DICSIZ * 2) {
         memmove(&text[0], &text[DICSIZ], DICSIZ + MAXMATCH);
-        n = fread_crc(&text[DICSIZ + MAXMATCH], DICSIZ, infile);
+        n = fread_crc(&text[DICSIZ + MAXMATCH], DICSIZ, rfp, &wp->crc);
+        wp->origsize += n;
         remainder += n;
         pos = DICSIZ;
-        if (outfile != stdout && opts.quiet < 1) {
+        if (wp->fp != stdout && opts.quiet < 1) {
             putc('.', stdout);
         }
     }
@@ -338,16 +339,17 @@ get_next_match(struct match_t *match)
 }
 
 void
-encode(void)
+encode(struct lzh_ostream *wp, FILE *rfp)
 {
     struct match_t match, lastmatch;
 
     allocate_memory();
     init_slide();
-    huf_encode_start(opts.method);
-    remainder = fread_crc(&text[DICSIZ], DICSIZ + MAXMATCH, infile);
+    huf_encode_start(wp, opts.method);
+    remainder = fread_crc(&text[DICSIZ], DICSIZ + MAXMATCH, rfp, &wp->crc);
+    wp->origsize += remainder;
 
-    if (outfile != stdout && opts.quiet < 1) {
+    if (wp->fp != stdout && opts.quiet < 1) {
         putc('.', stdout);
     }
     match.len = 0;
@@ -355,21 +357,21 @@ encode(void)
     insert_node(&match);
     if (match.len > remainder)
         match.len = remainder;
-    while (remainder > 0 && !unpackable) {
+    while (remainder > 0 && !wp->unpackable) {
         lastmatch = match;
-        get_next_match(&match);
+        get_next_match(wp, rfp, &match);
         if (match.len > remainder)
             match.len = remainder;
         if (match.len > lastmatch.len || lastmatch.len < THRESHOLD)
-            output(text[pos - 1], 0);
+            output(wp, text[pos - 1], 0);
         else {
-            output(lastmatch.len + (UCHAR_MAX + 1 - THRESHOLD),
+            output(wp, lastmatch.len + (UCHAR_MAX + 1 - THRESHOLD),
                    (pos - lastmatch.pos - 2) & (DICSIZ - 1));
             while (--lastmatch.len > 0)
-                get_next_match(&match);
+                get_next_match(wp, rfp, &match);
             if (match.len > remainder)
                 match.len = remainder;
         }
     }
-    huf_encode_end();
+    huf_encode_end(wp);
 }