diff options
Diffstat (limited to 'lzss-main.cpp')
-rw-r--r-- | lzss-main.cpp | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/lzss-main.cpp b/lzss-main.cpp index 0a4a446..d2d9c68 100644 --- a/lzss-main.cpp +++ b/lzss-main.cpp @@ -25,11 +25,9 @@ #include "Output.h" #include "generic.h" #include "lzss.h" - -char * fn1, * fn2, * pname; +#include "Main.h" int lga = 0; -int lzsscompress = 1; struct option long_options[] = { {"1iscomp", 1, &lga, 1 }, @@ -70,6 +68,20 @@ struct option long_options[] = { {0, 0, NULL, 0 } }; +CODE_BEGINS +public: +Appli() : lzsscompress(1), lzss_o(new lzss) {} +virtual ~Appli() { + delete lzss_o; +} +private: + +char * fn1, * fn2, * pname; + +int lzsscompress; + +lzss * lzss_o; + void showhelp(void) { printm(M_BARE, "Usages:\n" @@ -100,6 +112,7 @@ void showhelp(void) { } void showscheme(void) { + lzss::scheme_t scheme = lzss_o->get_scheme(); printm(M_BARE, "Actual scheme:\n" "--1iscomp %i\n" @@ -139,16 +152,17 @@ void dump(void) { int i; printm(M_BARE, "Built-in schemes:\n"); - for (i = 0; schemes[i].name; i++) { - printm(M_BARE, "%2i - %s\n", i, schemes[i].name); + for (i = 0; lzss::schemes[i].name; i++) { + printm(M_BARE, "%2i - %s\n", i, lzss::schemes[i].name); } } -int main(int argc, char ** argv) { +virtual int startup() throw (GeneralException) { long length = -1; Handle * f1, * f2; int p, show = 0; int c, s, t; + lzss::scheme_t scheme = lzss_o->get_scheme(); pname = strdup(argv[0]); p = strlen(pname) - 5; @@ -159,8 +173,8 @@ int main(int argc, char ** argv) { lzsscompress = 0; } - printm(M_BARE, /* -LZSS_MAIN " compressor/decompressor version " LZSS_VERSION ",\n" */ + printm(M_BARE, +LZSS_NAME + " compressor/decompressor version " + LZSS_VERSION + ",\n" "Copyright (C) 2002 Nicolas \"Pixel\" Noble\n" "This software comes with ABSOLUTELY NO WARRANTY; see COPYING for details\n" "Thanks to Czar Dragon, for his little 'lzss' schemes FAQ.\n" @@ -299,7 +313,11 @@ LZSS_MAIN " compressor/decompressor version " LZSS_VERSION ",\n" */ exit(0); case 's': s = atoi(optarg); - scheme = schemes[s]; + if (s >= lzss_o->END) { + printm(M_ERROR, "%s: value too high (no such scheme)\n", s); + exit(-1); + } + scheme = lzss::schemes[s]; break; case 'l': length = atoi(optarg); @@ -323,7 +341,7 @@ LZSS_MAIN " compressor/decompressor version " LZSS_VERSION ",\n" */ lzsscompress = 1; break; case 'b': - blockb = 1; + lzss_o->blockb = 1; break; default: showhelp(); @@ -357,24 +375,27 @@ LZSS_MAIN " compressor/decompressor version " LZSS_VERSION ",\n" */ printm(M_STATUS, "Decompressing `%s' to `%s'...\n", fn1, fn2); } + lzss_o->change_scheme(scheme); + if (lzsscompress) { if (length == -1) { - lzss_comp(f1, f2); + lzss_o->lzss_comp(f1, f2); } else { - lzss_comp(f1, f2, &length); + lzss_o->lzss_comp(f1, f2, &length); } } else { - length = lzss_decomp(f1, f2, length); + length = lzss_o->lzss_decomp(f1, f2, length); } printm(M_STATUS, "Done, filesize changed from %i to %i.\n", f1->GetSize(), f2->GetSize()); - if (!bitmap_count) - bitmap_count = 8; + if (!lzss_o->bitmap_count) + lzss_o->bitmap_count = 8; if (lzsscompress) - printm(M_STATUS, "Compressed %i = 0x%08x blocs, containing %i = 0x%08x chunks.\n", blk + 1, blk + 1, blk * 8 + bitmap_count, blk * 8 + bitmap_count); + printm(M_STATUS, "Compressed %i = 0x%08x blocs, containing %i = 0x%08x chunks.\n", lzss_o->blk + 1, lzss_o->blk + 1, lzss_o->blk * 8 + lzss_o->bitmap_count, lzss_o->blk * 8 + lzss_o->bitmap_count); delete f1; delete f2; exit(0); } +CODE_ENDS |