From: Alan Kennedy Date: Wed, 23 Jun 2004 08:55:15 +0000 (+0000) Subject: Modifico el main del Jacu para que compile con la nueva API de Huffman por lo que... X-Git-Tag: svn_import~69 X-Git-Url: https://git.llucax.com/z.facultad/75.06/jacu.git/commitdiff_plain/5baec768425c89244fb216ccf65f515d4336e96b Modifico el main del Jacu para que compile con la nueva API de Huffman por lo que puedan hacer svn up tranquilos. No obstante, dado que estoy muy cansado, sigue usando el archivo temporal y a huffman por file, pero ya esta implementado huffman by chunks que en cuanto este un poco mas depurado jacu en si, lo metemos. --- diff --git a/src/jacu.c b/src/jacu.c index 9971abf..c91f0e0 100644 --- a/src/jacu.c +++ b/src/jacu.c @@ -22,6 +22,7 @@ int main(int argc, char* argv[]) size_t pagesize = 32768; /* 32KB */ int ch; t_BlockSort *bs; + HUFF_STATE *shuff; while ((ch = getopt(argc, argv, "cdzt:q:")) != -1) { @@ -175,14 +176,17 @@ int main(int argc, char* argv[]) bs_destroy(bs); /* Comprimo con huffman */ - i = shuff_encode_file("tmp.comp", argv[optind+1], volumesize); + if ((shuff = shuff_init_encoder_byfile("tmp.comp", argv[optind+1], volumesize)) == NULL) return 1; + shuff_encode_file(shuff); + shuff_deinit_encoder(shuff); + free(shuff); /* borro el temporal */ remove("tmp.comp"); /* Muestro bpb */ printf("Comprimido a %.04f bpb.\n", get_file_size(argv[optind+1])*8.0/get_file_size(argv[optind])); - return i; + return 0; } if (dflag == 1) { @@ -194,7 +198,11 @@ int main(int argc, char* argv[]) char *z; int z_len; - shuff_decode_file(argv[optind], "tmp.comp"); /*argv[optind+1]);*/ + if ((shuff = shuff_init_decoder(argv[optind],"tmp.comp")) == NULL) return 1; + shuff_decode_file(shuff); + shuff_deinit_decoder(shuff); + free(shuff); + fp_in = fopen("tmp.comp", "rb"); fp_out = fopen(argv[optind+1], "wb"); @@ -267,4 +275,3 @@ long get_file_size(const char* filename) fclose(file); return file_size; } - diff --git a/src/statichuff/statichuff.c b/src/statichuff/statichuff.c index 908729b..55346bd 100644 --- a/src/statichuff/statichuff.c +++ b/src/statichuff/statichuff.c @@ -1,6 +1,7 @@ #include "statichuff.h" #include +#include void putbit(char bit, char restart, char flush, VFILE *fp) { @@ -393,7 +394,7 @@ HUFF_STATE *shuff_init_decoder(char *inputfile, char *outputfile) } /* Levanto cuantos bytes decodeo y la freq table */ - if ((shuff->decoderfp = vfopen(shuff->sourcefile,"r",0)) == NULL) return 0; + if ((shuff->decoderfp = vfopen(shuff->sourcefile,"r",0)) == NULL) return NULL; vfread(&(shuff->bytesleft),sizeof(unsigned long int),1,shuff->decoderfp); vfread(shuff->freqtable,sizeof(unsigned long int),256,shuff->decoderfp); shuff->codetree = shuff_buildtree(shuff->freqtable); diff --git a/src/statichuff/statichuff.h b/src/statichuff/statichuff.h index 35a550c..3d80401 100644 --- a/src/statichuff/statichuff.h +++ b/src/statichuff/statichuff.h @@ -40,6 +40,7 @@ HUFF_STATE *shuff_init_encoder_byfile(char *inputfile, char *outputfile, long vo HUFF_STATE *shuff_init_encoder_bychunk(char *outputfile, long volsize); HUFF_STATE *shuff_init_decoder(char *inputfile, char *outputfile); void shuff_deinit_encoder(HUFF_STATE *shuff); +void shuff_deinit_decoder(HUFF_STATE *shuff); int shuff_encode_file(HUFF_STATE *shuff); int shuff_decode_file(HUFF_STATE *shuff);