Script started on Fri Feb 14 10:29:18 2003 uhunix2:~/212% cat makefile lzdecompress: lzdecompress.o decompress.o gcc lzdecompress.o decompress.o -o lzdecompress lzdecompress.o: lzdecompress.c lz.h gcc -c lzdecompress.c decompress.o: decompress.c lz.h gcc -c decompress.c uhunix2:~/212% cat lz.h #include #define PROC 4096 /*width of processed bytes array*/ #define UNPROC 16 /*widht of unprocessed bytes array*/ /* in lzdecompress.c */ void usage(); /* in decompress.c */ void decompress(FILE *fileInp, FILE *fileOutp, short verbose); void shiftOn(char nextChar, int *a, FILE *fileOutp); uhunix2:~/212% cat lzdecompress.c /*lzdecompress.c */ /*Decompresses a file that was compressed with LZ compression */ /*Author: Zach Tomaszewski /*Date: 1 October */ #include "lz.h" FILE *fileInp; /*compressed file */ FILE *fileOutp; /*decompressed file */ short verbose = 0; /* true (1) or false (0) */ int main(int argc, char *argv[]) { switch (argc){ case 3: /*two arguments */ fileInp = fopen(argv[1], "rb"); fileOutp = fopen(argv[2], "wb"); break; case 4: if (strcmp(argv[1], "-v")==0){ verbose = 1; fileInp = fopen(argv[2], "rb"); fileOutp = fopen(argv[3], "wb"); }else{ usage(); } break; default: /* number of arguments: 0, 1, >4 */ usage(); break; } /* check that files are really open and ready */ if (fileInp==NULL) { puts("Error: Could not open given input file."); exit(1); } if (fileOutp==NULL) { puts("Error: Could not open output file."); exit(1); } decompress(fileInp, fileOutp, verbose); /*close files */ fclose(fileInp); fclose(fileOutp); }/*end main */ /* Gives a usage message for this program */ void usage() { puts(""); puts("LZdecompress decompresses a file compressed using an LZ technique."); puts("\nUsage: lzcompress [-v] [compressed input file] [file to output] \n"); puts("-v\t verbose. Gives extra debugging information."); puts(""); exit(0); } uhunix2:~/212% cat decompress.c /* decompress.c */ /* Part of LZdecompress, this set of functions does most of the work */ /* of the decompression */ /* Author: Zach Tomaszewski */ /* Date: 17 February 2003 */ #include "lz.h" /* Takes a file to read from and writes out to the given fileOut. If verbose is 1, prints out debugging info */ void decompress(FILE *fileInp, FILE *fileOutp, short verbose) { int i; //loop or counting var unsigned int next1 = 0, next2 = 0; //next pair of bytes read from file int a[PROC]; //array holding bytes being processed for (i=0; i < PROC; i++) { //a[] initialized to NIL a[i] = ' '; } while ((next1 = getc(fileInp)) != EOF) { if (next1 == 0) { //single character next2 = getc(fileInp); shiftOn(next2, a, fileOutp); }else { //complicated abbrev. next2 = getc(fileInp); next1 = next1<<8; next1 = next1 | next2; //combined both into next 1. next2 = next1; //copied next1 = next1>>12; //leaving 4 bits: number of characters to repeat next2 = next2 & 0x0fff; //shaving off first 4 bits. for (i=0; i<= next1; i++){ //since shifting each time, need next2 //from same position next1 times shiftOn(a[next2], a, fileOutp); } } if (verbose) { for (i=PROC-32; i