OSDN Git Service

added a long option --debug=dumplzss which display debugging information for the...
authorKoji Arai <jca02266@gmail.com>
Fri, 2 May 2008 15:02:02 +0000 (00:02 +0900)
committerKoji Arai <jca02266@gmail.com>
Wed, 14 May 2008 14:46:21 +0000 (23:46 +0900)
ChangeLog
src/extract.c
src/lha.h
src/lharc.c
src/slide.c
tests/lha-test1

index 6d73090..c0a6c8f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2008-05-02  Koji Arai  <arai@users.sourceforge.jp>
+
+       * added a long option --debug=dumplzss which display debugging information for the LZSS.
+
 2008-03-08  Koji Arai  <arai@users.sourceforge.jp>
 
        * src/lhext.c (add_dirinfo): no longer suppose that contents of the LZH archive is sorted by pathname.
index 814df7f..328226c 100644 (file)
@@ -73,6 +73,10 @@ decode_lzhuf(infp, outfp, original_size, packed_size, name, method, read_sizep)
                         original_size,
                         verify_mode ? "Testing " : "Melting ",
                         2048);
+
+        if (dump_lzss)
+            printf("no use slide\n");
+
         *read_sizep = copyfile(infp, (verify_mode ? NULL : outfp),
                                original_size, 2, &crc);
     }
@@ -81,6 +85,9 @@ decode_lzhuf(infp, outfp, original_size, packed_size, name, method, read_sizep)
                         original_size,
                         verify_mode ? "Testing " : "Melting ",
                         1 << interface.dicbit);
+        if (dump_lzss)
+            printf("\n");
+
         crc = decode(&interface);
         *read_sizep = interface.read_size;
     }
index 0949500..2fdad9e 100644 (file)
--- a/src/lha.h
+++ b/src/lha.h
@@ -335,6 +335,7 @@ EXTERN boolean decode_macbinary_contents;
 /* for debugging */
 EXTERN boolean sort_contents;
 EXTERN boolean recursive_archiving;
+EXTERN boolean dump_lzss;
 
 
 /* ------------------------------------------------------------------------ */
index d2e98eb..23b0755 100644 (file)
@@ -108,6 +108,7 @@ init_variable()     /* Added N.Watazaki */
     decode_macbinary_contents = FALSE;
     sort_contents = TRUE;
     recursive_archiving = TRUE;
+    dump_lzss = FALSE;
 }
 
 /* ------------------------------------------------------------------------ */
@@ -450,7 +451,7 @@ parse_suboption(int argc, char **argv)
 
         case DEBUG_OPTION:
             if (!optarg) {
-                error("debugging item is not specified for --%s=item",
+                error("debugging item is not specified for --%s",
                       long_options[option_index].name);
                 return -1;
             }
@@ -460,8 +461,12 @@ parse_suboption(int argc, char **argv)
             else if (strcmp(optarg, "norecursion") == 0) {
                 recursive_archiving = FALSE;
             }
+            else if (strcmp(optarg, "dumplzss") == 0) {
+                dump_lzss = TRUE;
+                quiet = TRUE;
+            }
             else {
-                error("unknown debugging item \"%s\" for --%s=item",
+                error("unknown debugging item \"%s\" for --%s",
                       optarg, long_options[option_index].name);
                 return -1;
             }
index e73e317..b6c27d6 100644 (file)
@@ -430,9 +430,15 @@ decode(interface)
     while (decode_count < origsize) {
         c = decode_set.decode_c();
         if (c < 256) {
-#ifdef DEBUG
-          fprintf(fout, "%u C %02X\n", decode_count, c);
+            if (dump_lzss) {
+#if SIZEOF_OFF_T == 8
+                printf("%04llu %02x(%c)\n",
+                       decode_count, c, isprint(c) ? c : '?');
+#else
+                printf("%04lu %02x(%c)\n",
+                       decode_count, c, isprint(c) ? c : '?');
 #endif
+            }
             dtext[loc++] = c;
             if (loc == dicsiz) {
                 fwrite_crc(&crc, dtext, dicsiz, outfile);
@@ -447,25 +453,35 @@ decode(interface)
             match.len = c - adjust;
             match.off = decode_set.decode_p() + 1;
             matchpos = (loc - match.off) & dicsiz1;
-#ifdef DEBUG
-            fprintf(fout, "%u M <%u %u> ",
-                    decode_count, match.len, decode_count-match.off);
+            if (dump_lzss) {
+#if SIZEOF_OFF_T == 8
+                printf("%04llu <%u %llu>\n",
+                       decode_count, match.len, decode_count-match.off);
+#else
+                printf("%04lu <%u %lu>\n",
+                       decode_count, match.len, decode_count-match.off);
 #endif
+            }
+
             decode_count += match.len;
             for (i = 0; i < match.len; i++) {
                 c = dtext[(matchpos + i) & dicsiz1];
-#ifdef DEBUG
-                fprintf(fout, "%02X ", c & 0xff);
-#endif
+                /*
+                if (dump_lzss) {
+                    printf(" %02x", c & 0xff);
+                }
+                */
                 dtext[loc++] = c;
                 if (loc == dicsiz) {
                     fwrite_crc(&crc, dtext, dicsiz, outfile);
                     loc = 0;
                 }
             }
-#ifdef DEBUG
-            fprintf(fout, "\n");
-#endif
+            /*
+            if (dump_lzss) {
+                printf("\n");
+            }
+            */
         }
     }
     if (loc != 0) {
index f4c8526..e69c885 100644 (file)
@@ -20,7 +20,32 @@ $lha l test-1.lzh
 
 test -d test-1 || mkdir test-1
 mv test-[abc] test-1
-$lha x test-1.lzh
+$lha x test-1.lzh --debug=dumplzss > test-tmp-stdout
+                                                       check $? $LINENO
+cat test-tmp-stdout
+cat <<EOF | diff test-tmp-stdout -
+
+0000 66(f)
+0001 6f(o)
+0002 6f(o)
+0003 0a(?)
+0004 <256 0>
+0260 <140 256>
+
+0000 62(b)
+0001 61(a)
+0002 72(r)
+0003 0a(?)
+0004 <256 0>
+0260 <140 256>
+
+0000 62(b)
+0001 61(a)
+0002 7a(z)
+0003 0a(?)
+0004 <256 0>
+0260 <140 256>
+EOF
                                                        check $? $LINENO
 diff test-1/test-a test-a
                                                        check $? $LINENO