From ccc661c6e52abb3ed16418f70ceaa4b3bd1fd035 Mon Sep 17 00:00:00 2001 From: Koji Arai Date: Sat, 3 May 2008 00:02:02 +0900 Subject: [PATCH] added a long option --debug=dumplzss which display debugging information for the LZSS. --- ChangeLog | 4 ++++ src/extract.c | 7 +++++++ src/lha.h | 1 + src/lharc.c | 9 +++++++-- src/slide.c | 38 +++++++++++++++++++++++++++----------- tests/lha-test1 | 27 ++++++++++++++++++++++++++- 6 files changed, 72 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 6d73090..c0a6c8f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2008-05-02 Koji Arai + + * added a long option --debug=dumplzss which display debugging information for the LZSS. + 2008-03-08 Koji Arai * src/lhext.c (add_dirinfo): no longer suppose that contents of the LZH archive is sorted by pathname. diff --git a/src/extract.c b/src/extract.c index 814df7f..328226c 100644 --- a/src/extract.c +++ b/src/extract.c @@ -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; } diff --git a/src/lha.h b/src/lha.h index 0949500..2fdad9e 100644 --- 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; /* ------------------------------------------------------------------------ */ diff --git a/src/lharc.c b/src/lharc.c index d2e98eb..23b0755 100644 --- a/src/lharc.c +++ b/src/lharc.c @@ -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; } diff --git a/src/slide.c b/src/slide.c index e73e317..b6c27d6 100644 --- a/src/slide.c +++ b/src/slide.c @@ -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) { diff --git a/tests/lha-test1 b/tests/lha-test1 index f4c8526..e69c885 100644 --- a/tests/lha-test1 +++ b/tests/lha-test1 @@ -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 < +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 -- 2.11.0