Lzw.cpp

From CDOT Wiki
Revision as of 16:52, 20 February 2013 by Nprakashpanicker (talk | contribs) (Created page with '#include <time.h> #include "lzw.h" /******************************************************************** ** ** This program gets a file name from the command line. It comp…')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
  1. include <time.h>
  1. include "lzw.h"


/********************************************************************

    • This program gets a file name from the command line. It compresses the
    • file, placing its output in a file named test.lzw. It then expands
    • test.lzw into test.out. Test.out should then be an exact duplicate of
    • the input file.
                                                                                                                                                  • /


main(int argc, char *argv[])

{

clock_t timer;

CLZWCompressFile lzw;


/*

    • Get the file name, open it up, and open up the lzw output file.
  • /
 if (argc==1)
 {
   printf("Input file name to compress?\n");

return 0;

 }


 printf("testing %s...\n", argv[1]);

/*

    • Compress the file.
  • /
 timer = clock();
 int crunch = lzw.Compress(argv[1], "test.lzw");
 timer = clock() - timer; //CLOCKS_PER_SEC
 printf("compress time=%d ms, encoding=%d, size=%u", timer, lzw.get_bits(), crunch);
 int filesize = lzw.u_io;
 printf(" (ratio=%d%%)\n", filesize ? (filesize-crunch)*100/filesize : 0);
 if(lzw.AnyIOErrors())

printf("***I/O ERROR***\n");


/*

    • Expand the file.
  • /
  timer = clock();
 int orig = lzw.Expand("test.lzw", "test.out");
 timer = clock() - timer; //CLOCKS_PER_SEC
 printf("expand time=%d ms, encoding=%d\n", timer, lzw.get_bits());

if(lzw.AnyIOErrors())

printf("***I/O ERROR***\n");


 ATLASSERT(filesize == orig); // did we mangle the file?
 return 0;

}