#include #include #include "string.h" #include "fstream" /* Implementazione by Ugo Cirmignani Analista programmatore (Roma) Il sorgente può essere compilato con Dev-cpp (windows), GCC (unix) e altri. */ //262143 == 20 bit == 1gb circa //#define dictionary_size 1048575 //262143 == 19 bit == 500 MB circa //#define dictionary_size 524287 //262143 == 18 bit == 255 MB circa //#define dictionary_size 262143 //17 bit //#define dictionary_size 131071 //16 bit //#define dictionary_size 65535 //14 bit #define dictionary_size 16383 //9 bit //#define dictionary_size 5000 #define reset_dictionary 1 //Reset the dictionary if it become too big! #define bit_writing 1 //Reset the dictionary if it become too big! using namespace std; struct lzwn { //The byte value! unsigned char value; //The index/prefix value unsigned int index; //The value code === node index unsigned int code; //Pointer struct lzwn *p[256]; }; //struct lzwn *dictionary; //struct lzwn *dictionary = new lzwn[dictionary_size]; //fino a 1 miglione pare che funzioni.. struct lzwn dictionary[dictionary_size+100]; //The writer buffer! unsigned char write_buffer[5] = {0}; int wb_index; int wb_rest; int wb_bit_size; int wb_processed; int wb_operation_minus; int wb_old_bit_size; unsigned char given_rest_char; int operation = 0; char reversing_buffer[50000]; int rb_index; //How many word i can not insert into the data dictionary unsigned int full_after; //Compression success items after the full_after! unsigned int after_full_after_successes; unsigned long next_code = 0; unsigned long primo, secondo, vecchio, givecode; void dic_reset(); void dic_init(); int GetBitFlag( unsigned char, int); unsigned char SetBitFlag(unsigned char, int, int); unsigned int get_end_bit() { return ((1 << (wb_bit_size)) - 1); } void print_buffered(unsigned int value) { //printf("\nIl valore in ingresso : %d\n", value); //printf("\nBit size : %d\n", wb_bit_size); //parto da dove ho lasciato.. if (wb_rest != 0) { //printf("\nIl byte precedente elaborato era pieno!\n"); write_buffer[0] = (write_buffer[wb_index-1]) << 8-wb_rest; write_buffer[0] = write_buffer[wb_index]; //printf("\nIl write buffer o shiftato = %d", write_buffer[0]); } wb_index = 0; //controllo quale bit size devo utilizzare.. //while ( value >= (int)pow(2,wb_bit_size) ) //{ //Increase the bit size! //wb_bit_size++; //} //Questa operazione è fatta direttamente nella funzione put_to_table //printf("\n\nIl bit size = %d\n", wb_bit_size); //system("pause"); //Per tutti i bit size di questo valore.. for ( int i = wb_bit_size; i > 0; i-- ) { //printf("\nIl char di output vale: %d",write_buffer[wb_index]); //Prendo il bit piu significativo! unsigned char ilbit = ( ( ( value<<(32 - i) ) >> (31) ) ); //printf("\nIl bit n%d vale: %d",i,ilbit); write_buffer[wb_index] = SetBitFlag(write_buffer[wb_index], 7 - wb_rest, (int)ilbit ); wb_rest++; //il primo byte è fatto! if (wb_rest == 8 ) { //printf("\nOutput: %d", write_buffer[wb_index]); wb_index++; wb_rest = 0; } } } //Funzione che spacchetta l'input in modo corretto.. int give_code(unsigned char ingresso) { //wb_old_bit_size //printf("\n\n\n Char in ingresso : %d", ingresso); //printf("\n\n\n Bit size : %d", wb_bit_size); //This is the most simple case, the data_bit is eight! if ( wb_bit_size == 8 ) { //In this case the function will just return the input value.. givecode = ingresso; given_rest_char = 0; wb_processed = 0; //All bits were processed with success! wb_rest =0; return ingresso; } else { //given_rest //wb_rest || The rest of bytes to be readen! //get the number of bits to process.. //The number of effective bits to process is the bite_size minus the readen! int bit_to_process = wb_bit_size - wb_processed; //printf("\nBits to process: %d", bit_to_process); //We have already have processed a code! if ( bit_to_process == wb_bit_size ) { givecode = 0; //printf("\nI reset the last given code!"); } if (wb_rest > 0) { //printf("\nC'è del resto da processare!"); if ( (bit_to_process - wb_rest) >= 0 ) { //printf("\nCon questo resto posso forse creare un output!"); //we shift the values as needed... givecode += (unsigned int)( given_rest_char << (bit_to_process - wb_rest)) ; //printf("\nIl codice con questo resto vale: %d", givecode); wb_processed = wb_processed + wb_rest; bit_to_process = bit_to_process - wb_rest; //The rest of bits coming from ingresso are 0 wb_rest = 0; //printf("\nI bit da processare ora sono: %d", bit_to_process); if ( bit_to_process == 0 ) { //We can reset this variable.. wb_processed = 0; return givecode; } } else { //printf("\nCon questo resto devo creare un output!"); } /* else { //we shift the values as needed... givecode += (unsigned int)( given_rest_char << (bit_to_process - wb_rest)) ; //The rest of bits coming from ingresso are 0 wb_rest = 0; //printf("\nIl codice con questo resto vale: %d", givecode); wb_processed = wb_processed + wb_rest; bit_to_process = bit_to_process - wb_rest; printf("\nCon questo resto devo creare un output!"); given_rest_char = ( ( ingresso<<(8 - bit_to_process) ) >> (bit_to_process) ); givecode += ( ingresso>>(8-bit_to_process) ); //We can reset this variable.. wb_processed = 0; //The rest coming from the input wb_rest = wb_rest-bit_to_process; wb_processed = 0; return givecode; //Must return a valide value and a rest! } */ } if ( (bit_to_process - 8) >= 0 ) { //printf("\nGivencode += ingresso %d << %d = %d",ingresso, bit_to_process - 8,(unsigned int)( ingresso << bit_to_process - 8)); //we shift the values as needed... givecode += (unsigned int)( ingresso << bit_to_process - 8); //The rest of bits coming from ingresso are 0 wb_rest = 0; wb_processed = wb_processed + 8; bit_to_process = bit_to_process -8; //printf("\n\n1)..Given code = %d", givecode); if ( bit_to_process == 0 ) { //We can reset this variable.. //printf("\nI return the givencode"); wb_processed = 0; return givecode; } else { //printf("\n I can't return the givencode"); return -1; //The output is not yet ready! } } else { //The rest coming from the input wb_rest = 8-bit_to_process; given_rest_char = ( ( ingresso<<(bit_to_process) ) ); given_rest_char = given_rest_char >> bit_to_process; //printf("\nGive code %d + needed part of input %d", givecode, (unsigned int)( ingresso>>(8-bit_to_process) )); givecode += (unsigned int)( ingresso>>(8-bit_to_process) ); //We can reset this variable.. wb_processed = 0; //printf("\n\nGiven code = %d", givecode); //printf("\nResto len = %d", wb_rest); //printf("\nResto Value = %d", given_rest_char); return givecode; } } return -1; } //Get bit 0-7 flag return 1 or 0, if any error return -1 int GetBitFlag( unsigned char MyByte, int BitN ) { unsigned char B; switch (BitN) { case 0: B =(MyByte & 0x01); return B; break; case 1: B = (MyByte & 0x02); B = (B >> 1); return B; break; case 2: B = (MyByte & 0x04); B = (B >> 2); return B; break; case 3: B = (MyByte & 0x08); B = (B >> 3); return B; break; case 4: B = (MyByte & 0x10); B = (B >> 4); return B; break; case 5: B = (MyByte & 0x20); B = (B >> 5); return B; break; case 6: B = (MyByte & 0x40); B = (B >> 6); return B; break; case 7: B = (MyByte & 0x80); B = (B >> 7); return B; break; default: return -1; break; } return -1; } //Set bit 0-7 flag, return a setted Byte.. if any error return the original byte unsigned char SetBitFlag(unsigned char MyByte, int BitN, int value) { // If any errors return the original Byte! if (((BitN < 0) && (BitN > 7)) || ((value < 0) && (value > 1))) return MyByte; //Setting the bit… switch (BitN) { case 0: if (value == 0) { // Is the bit 0 == 0? if (GetBitFlag(MyByte, 0) == 0) return MyByte; // It’s Already setted to 0! else //it’s setted to 1 { MyByte = ( MyByte ^ 0x01); // Need to set it to 0 return MyByte; } } if (value == 1) // Is the bit 0 == 1? if (GetBitFlag(MyByte, 0) == 1) return MyByte; // It’s Already setted to 1! else //it’s setted to 0 { MyByte = (MyByte ^ 0x01);// Need to set it to 1 return MyByte; } break; case 1: if (value == 0) { // Is the bit 0 == 0? if (GetBitFlag(MyByte, 1) == 0) return MyByte; // It’s Already setted to 0! else //it’s setted to 1 { MyByte = (MyByte ^ 0x02); // Need to set it to 0 return MyByte; } } if (value == 1) // Is the bit 0 == 1? if (GetBitFlag(MyByte, 1) == 1) return MyByte; // It’s Already setted to 1! else //it’s setted to 0 { MyByte = (MyByte ^ 0x02);// Need to set it to 1 return MyByte; } break; case 2: if (value == 0) { // Is the bit 0 == 0? if (GetBitFlag(MyByte, 2) == 0) return MyByte; // It’s Already setted to 0! else //it’s setted to 1 { MyByte = (MyByte ^ 0x04); // Need to set it to 0 return MyByte; } } if (value == 1) // Is the bit 0 == 1? if (GetBitFlag(MyByte, 2) == 1) return MyByte; // It’s Already setted to 1! else //it’s setted to 0 { MyByte = (MyByte ^ 0x04);// Need to set it to 1 return MyByte; } break; case 3: if (value == 0) { // Is the bit 0 == 0? if (GetBitFlag(MyByte, 3) == 0) return MyByte; // It’s Already setted to 0! else //it’s setted to 1 { MyByte = (MyByte ^ 0x08); // Need to set it to 0 return MyByte; } } if (value == 1) // Is the bit 0 == 1? if (GetBitFlag(MyByte, 3) == 1) return MyByte; // It’s Already setted to 1! else //it’s setted to 0 { MyByte = (MyByte ^ 0x08);// Need to set it to 1 return MyByte; } break; case 4: if (value == 0) { // Is the bit 0 == 0? if (GetBitFlag(MyByte, 4) == 0) return MyByte; // It’s Already setted to 0! else //it’s setted to 1 { MyByte = (MyByte ^ 0x10); // Need to set it to 0 return MyByte; } } if (value == 1) // Is the bit 0 == 1? if (GetBitFlag(MyByte, 4) == 1) return MyByte; // It’s Already setted to 1! else //it’s setted to 0 { MyByte = (MyByte ^ 0x10);// Need to set it to 1 return MyByte; } break; case 5: if (value == 0) { // Is the bit 0 == 0? if (GetBitFlag(MyByte, 5) == 0) return MyByte; // It’s Already setted to 0! else //it’s setted to 1 { MyByte = (MyByte ^ 0x20); // Need to set it to 0 return MyByte; } } if (value == 1) // Is the bit 0 == 1? if (GetBitFlag(MyByte, 5) == 1) return MyByte; // It’s Already setted to 1! else //it’s setted to 0 { MyByte = (MyByte ^ 0x20);// Need to set it to 1 return MyByte; } break; case 6: if (value == 0) { // Is the bit 0 == 0? if (GetBitFlag(MyByte, 6) == 0) return MyByte; // It’s Already setted to 0! else //it’s setted to 1 { MyByte = (MyByte ^ 0x40); // Need to set it to 0 return MyByte; } } if (value == 1) // Is the bit 0 == 1? if (GetBitFlag(MyByte, 6) == 1) return MyByte; // It’s Already setted to 1! else //it’s setted to 0 { MyByte = (MyByte ^ 0x40);// Need to set it to 1 return MyByte; } break; case 7: if (value == 0) { // Is the bit 0 == 0? if (GetBitFlag(MyByte, 7) == 0) return MyByte; // It’s Already setted to 0! else //it’s setted to 1 { MyByte = (MyByte ^ 0x80); // Need to set it to 0 return MyByte; } } if (value == 1) // Is the bit 0 == 1? if (GetBitFlag(MyByte, 7) == 1) return MyByte; // It’s Already setted to 1! else //it’s setted to 0 { MyByte = (MyByte ^ 0x80);// Need to set it to 1 return MyByte; } break; case 8: if (value == 0) { // Is the bit 0 == 0? if (GetBitFlag(MyByte, 8) == 0) return MyByte; // It’s Already setted to 0! else //it’s setted to 1 { MyByte = (MyByte ^ 0x01); // Need to set it to 0 return MyByte; } } if (value == 1) // Is the bit 0 == 1? if (GetBitFlag(MyByte, 8) == 1) return MyByte; // It’s Already setted to 1! else //it’s setted to 0 { MyByte = (MyByte ^ 0x01);// Need to set it to 1 return MyByte; } break; default: return MyByte; break; } return MyByte; } long find(long index, unsigned char value) { //Not found data case.. i will return -1 if ( dictionary[index].p[value] == NULL ) return -1; else //I will return the new prefix! return dictionary[index].p[value]->code; } void put_to_table(unsigned long index, unsigned char value) { if ( operation == 0 ) { //printf("\nNella compressione"); //printf("\nInsert into table %d %d", index, value); //printf("\nNext code: %d\nBit size: %d", next_code, wb_bit_size); } if ( bit_writing == 1 && operation == 0 ) { //if ( next_code < ((1 << (9)) - 1) ) //wb_bit_size = 9; //FUNZIONAVA if ( next_code == get_end_bit()-2 ) if ( next_code == get_end_bit()-2 ) { wb_bit_size++; } } if ( operation == 1 ) { //printf("\nNella decompressione"); //printf("\nInsert into table %d %d", index, value); //printf("\nNext code: %d\nBit size: %d", next_code, wb_bit_size); } if ( bit_writing == 1 && operation == 1 ) { //if ( next_code < ((1 << (9)) - 1) ) //wb_bit_size = 9; //-4 if ( next_code == get_end_bit()-4 ) { wb_bit_size++; } } //The prefix that already exist has now a new entry that points to the new item of the data dictionary.. dictionary[index].p[value] = &dictionary[next_code]; dictionary[next_code].value = value; dictionary[next_code].index = index; dictionary[next_code].code = next_code; next_code++; } int compress_file(char *input, char *output) { int do_reset = 0; after_full_after_successes = 0; full_after = 0; //printf("Full after: %d\n Successes after full after: %d", full_after, after_full_after_successes); //system("pause"); operation = 0; FILE *fp = fopen(input, "rb"); if (fp == NULL) { printf("\nErrore nell'aprire il file %s", input); printf("Full after: %d", full_after); //system("pause"); return 0; } int rc; if ( (rc = fgetc(fp)) == EOF ) { printf("\nIl file in ingresso e' vuoto!"); // FULL AFTER! \\ printf("\nFull after: %d", full_after); //system("pause"); return 0; } else primo = rc; //Lets open the output file! ofstream outfile; outfile.open(output,ios::out | ios::binary ); //Get the second char by char.. while ( (secondo = getc(fp)) != EOF ) { long find_result = -1; if ( bit_writing == 0 ) find_result = find(primo, secondo); else find_result = find(primo, secondo); if ( find_result == -1 ) { //se la tabella non if ( next_code < dictionary_size - 5 ) { //I put the new symbol into the dictionary put_to_table(primo, secondo); //Il prefisso può uscire... //printf("\nOut: %d", primo); //outfile.put(primo / 16777216); //outfile.put(primo / 65536); if ( bit_writing == 0 ) { outfile.put(primo / 256); outfile.put(primo % 256); } else { print_buffered(primo); for ( int x = 0; x < wb_index; x++ ) outfile.put(write_buffer[x]); } //Il primo è uscito.. primo = secondo; } else { full_after++; /* if ( full_after == 1000 ) { printf("\nI have to reset the dictionary.."); system("pause"); //if ( bit_writing == 0 ) dic_reset(); //I put the new symbol into the dictionary put_to_table(primo, secondo); } */ //Se il flag reset è settato if (reset_dictionary == 1 ) { if ( bit_writing == 1 ) { do_reset = 1; } //printf("\nI reset the dictionary when Next code: %d", next_code); //printf("\nI put: %d %d", primo, secondo); //system("pause"); dic_reset(); put_to_table(primo, secondo); } //Il prefisso può uscire... //printf("\nOut: %d", primo); if ( bit_writing == 0 ) { outfile.put(primo / 256); outfile.put(primo % 256); } else { print_buffered(primo); for ( int x = 0; x < wb_index; x++ ) outfile.put(write_buffer[x]); if ( do_reset == 1 ) { print_buffered(dictionary_size); for ( int x = 0; x < wb_index; x++ ) outfile.put(write_buffer[x]); //printf("\nI write the fake byte!"); //system("pause"); wb_bit_size=9; } } //Il primo è uscito.. primo = secondo; } } else { if ( full_after > 0 ) after_full_after_successes++; //This code already exist, so i get the nex prefix/index.. primo = find_result; } } //printf("Full after: %d, Successes: %d\nRelative compression ratio: %d", full_after, after_full_after_successes, after_full_after_successes / 100 * full_after ); //system("pause"); //Close the input file fclose(fp); //Il prefisso può uscire... if ( bit_writing == 0 ) { outfile.put(primo / 256); outfile.put(primo % 256); } else { print_buffered(primo); for ( int x = 0; x < wb_index; x++ ) outfile.put(write_buffer[x]); } if ( wb_rest != 0 ) { print_buffered(0); for ( int x = 0; x < wb_index; x++ ) outfile.put(write_buffer[x]); } outfile.close(); return 1; } void decoding_printf(unsigned long pcodice) { rb_index = 0; if ( pcodice < 256 ){ reversing_buffer[rb_index] = pcodice; //printf("%c", pcodice); rb_index++; } else { while (pcodice >= 256) { if ( full_after > 0 ) after_full_after_successes++; reversing_buffer[rb_index] = dictionary[pcodice].value; rb_index++; //printf("%c", simbolo[pcodice - 256]); pcodice = dictionary[pcodice].index; } //printf("%c", pcodice); reversing_buffer[rb_index] = pcodice; rb_index++; } //for ( int i = rb_index -1; i >= 0; i-- ) //printf("%c", reversing_buffer[i]); } long decompress_file(char *lfile, char *ofilen) { unsigned int last_next = 0; full_after = 0; after_full_after_successes = 0; int print_last_flag = 0; operation = 1; unsigned char fc; ofstream ofile; ofile.open(ofilen,ios::out | ios::binary ); FILE *fp = fopen(lfile, "rb"); if (fp == NULL) { printf("\nErrore nell'aprire il file %s", lfile); return 0; } int rch; int rcl; if ( bit_writing == 1 ) { rch = fgetc(fp); while ( (give_code(rch)) == -1 ) { if ( (rch = fgetc(fp)) == EOF ) { return 0; } } primo = givecode; } else { if ( ((rch = fgetc(fp)) == EOF) || ((rcl = fgetc(fp)) == EOF) ) { printf("\nIl file in ingresso e' vuoto!"); return 0; } else primo = (rch*256)+rcl; } //Il prefisso può uscire... decoding_printf(primo); for ( int i = rb_index -1; i >= 0; i-- ) ofile.put(reversing_buffer[i]); fc = primo; vecchio = fc; while(( (rch = fgetc(fp)) != EOF) ) { unsigned int next_old = 0; if ( bit_writing == 1 ) { //Ottengo un codice valido... while ( (give_code(rch)) == -1 ) { if ( (rch = fgetc(fp)) == EOF ) { return 0; } } //Stampo il codice valido... //printf("\n\nGive code: %d",givecode); if (reset_dictionary == 1 && bit_writing == 1 ) { if ( givecode == dictionary_size ) { //printf("\nGivercode = size %d", givecode); //printf("\n Givecode = al dizionario!"); //printf("\nDopo il reset put %d %d", primo, vecchio); //next_old = next_code; last_next = next_code-1; //system("pause"); dic_reset(); //Carattere di scarto.. //printf("given_rest_char %d\n Processed: %d,\nWb rest: %d", given_rest_char, wb_processed, wb_rest ); wb_bit_size = 9; /* wb_rest = 0; wb_bit_size=9; wb_rest = 0; wb_processed = 0; wb_index = 0; given_rest_char = 0; rb_index = 0; */ //Con questo senza mod biot size funziona if ( ( rch = fgetc(fp)) == EOF ) { return 0; } while ( (give_code(rch)) == -1 ) { if ( (rch = fgetc(fp)) == EOF ) { return 0; } } //givecode = 0; //primo = 97; //secondo = 256; secondo = givecode; //printf("\nvecchio: %d\nDopo il reset put %d %d",vecchio, primo, secondo); //printf("\n\next_code; %d", last_next); //system("pause"); //put_to_table(primo, secondo); //printf("fatto!"); //system("pause"); } else secondo = givecode; } else secondo = givecode; //printf("\nGivecode: %d", givecode); /* if (secondo >= dictionary_size ) dic_reset(); */ } else { rcl = fgetc(fp); secondo = (rch*256)+rcl; } if ( secondo == next_code ) { /* if ( full_after > 0 ) after_full_after_successes++; */ //printf("\nCaso sni\n"); //printf("\nDecodifico primo %d ", primo); //system("pause"); print_last_flag = 0; //Il prefisso può uscire... decoding_printf(primo); for ( int i = rb_index -1; i >= 0; i-- ) { ofile.put(reversing_buffer[i]); //printf("%c", reversing_buffer[i]); } fc = reversing_buffer[rb_index -1]; //printf("\nDecodifico vecchio %d ", vecchio); //printf("\nDecodifico vecchio %d ", vecchio); //Il prefisso può uscire... print_last_flag = 0; decoding_printf(vecchio); //printf("\nDecodifico vecchio %d DECODIFICATO", vecchio); for ( int i = rb_index -1; i >= 0; i-- ) { ofile.put(reversing_buffer[i]); //printf("%c", reversing_buffer[i]); } } else { /* if ( full_after > 0 ) after_full_after_successes++; /**/ //printf("\nStampo "); //Il codice può uscire //printf("\nDecodifico secondo %d ", secondo); print_last_flag = 0; decoding_printf(secondo); for ( int i = rb_index -1; i >= 0; i-- ) { ofile.put(reversing_buffer[i]); //printf("%c", reversing_buffer[i]); } fc = reversing_buffer[rb_index -1]; } vecchio = fc; //printf("\nVecchio = %d ",vecchio); //if ( bit_writing == 0) if ( next_code < dictionary_size - 5) { //printf("\nInserisco pre %d sim %d", primo, vecchio); //system("pause"); put_to_table(primo, vecchio); } else { full_after++; /* if ( full_after == 1000-6 ) { printf("\nI have to reset the dictionary.."); system("pause"); //if ( bit_writing == 0 ) dic_reset(); //I put the new symbol into the dictionary put_to_table(primo, secondo); } */ //printf("\nImpossibile aggiungere questo al dizionario, è pieno!"); //system("pause"); //Se il flag reset è settato if (reset_dictionary == 1 ) { if (bit_writing == 1) { ; } else { //printf("\nI Reset the dictionary when the next code: %d", next_code); //printf("\nAfter the reset i put: %d %d", primo, secondo); //system("pause"); //if ( bit_writing == 0 ) dic_reset(); //I put the new symbol into the dictionary put_to_table(primo, secondo); } //wb_bit_size = 9; } } print_last_flag = 1; primo = secondo; } //printf("Full after: %d \nSuccesses: %d\n", full_after, after_full_after_successes); system("pause"); /* if ( print_last_flag == 1) { printf("I print the last flag!"); decoding_printf(primo); for ( int i = rb_index -1; i >= 0; i-- ) { ofile.put(reversing_buffer[i]); //printf("%c", reversing_buffer[i]); } }*/ return 0; } //Initialize the dictionary with 256 simbols.. void dic_init() { //dictionary = new lzwn[dictionary_size]; //dictionary = malloc(sizeof(struct lzwn) * dictionary_size); for ( int i = 0; i < dictionary_size; i++) { for ( int z = 0; z < 256; z++) dictionary[i].p[z] = NULL; } for ( int i = 0; i < 256; i++){ dictionary[i].index -1; //Initialize it with an empty index! dictionary[i].value = i; dictionary[i].code = i; } next_code = 256; wb_bit_size = 9; wb_rest = 0; wb_processed = 0; } //Reset the dictionary with 256 simbols.. void dic_reset() { //dictionary = new lzwn[dictionary_size]; //dictionary = malloc(sizeof(struct lzwn) * dictionary_size); for ( int i = 0; i < dictionary_size; i++) { for ( int z = 0; z < 256; z++) dictionary[i].p[z] = NULL; } for ( int i = 0; i < 256; i++){ dictionary[i].index -1; //Initialize it with an empty index! dictionary[i].value = i; dictionary[i].code = i; } next_code = 256; //wb_bit_size=9; //wb_rest = 0; //wb_processed = 0; //wb_index = 0; //given_rest_char = 0; //rb_index = 0; //givecode = 0; } int main(int argc, char *argv[]) { //Dictionary initialization dic_init(); printf("\nCompressing a file.."); compress_file("t.bin","test.lzw"); dic_init(); printf("\n\n\nDecompressing a file.."); decompress_file("test.lzw","oregn.bin"); system("PAUSE"); return EXIT_SUCCESS; }