From: Alan Kennedy Date: Wed, 23 Jun 2004 07:36:16 +0000 (+0000) Subject: Another safe upload.. X-Git-Tag: svn_import~71 X-Git-Url: https://git.llucax.com/z.facultad/75.06/jacu.git/commitdiff_plain/d3fc39701c21dada8a143812c34e044b4b1ae704?ds=sidebyside Another safe upload.. --- diff --git a/src/statichuff/main_bychunk.c b/src/statichuff/main_bychunk.c index 5ce8016..eafe694 100644 --- a/src/statichuff/main_bychunk.c +++ b/src/statichuff/main_bychunk.c @@ -39,7 +39,7 @@ int main(int argc, char* argv[]) if (cflag == 1) { /* Inicio un compresor huffman estatico por chunks */ - if ((shuff = shuff_init_static_bychunk(argv[optind+1],volumesize*1024)) == NULL) return 0; + if ((shuff = shuff_init_encoder_bychunk(argv[optind+1],volumesize*1024)) == NULL) return 0; /* Comprimo por chunks */ if ((fp = fopen(argv[optind],"rb")) == NULL) return 1; @@ -59,7 +59,7 @@ int main(int argc, char* argv[]) shuff_encode_file(shuff); /* De init shuffman by chunks */ - shuff_deinit_static_bychunk(shuff); + shuff_deinit_encoder(shuff); /* Free mem allocated by main */ free(shuff); @@ -71,7 +71,7 @@ int main(int argc, char* argv[]) if (dflag == 1) { /* Descomprimo */ - return shuff_decode_file(argv[optind],argv[optind+1]); + /*return shuff_decode_file(argv[optind],argv[optind+1]);*/ } return 0; diff --git a/src/statichuff/statichuff.c b/src/statichuff/statichuff.c index 28b932d..a2f6265 100644 --- a/src/statichuff/statichuff.c +++ b/src/statichuff/statichuff.c @@ -78,7 +78,10 @@ int shuff_scanfreq_chunk(HUFF_STATE *chunkshuff, char* chunk, int chunksize) /* Si llegue al tope de freq acumulada, halve em */ if (chunkshuff->sumfreq == 14930352) chunkshuff->sumfreq = shuff_rescalefreq(chunkshuff->freqtable); - } + } + + /* Dumpeamos el chunk en el temporal homero */ + fwrite(chunk,chunksize,1,chunkshuff->coderfp); return 1; } @@ -230,7 +233,8 @@ int shuff_encode_symbols(HUFF_STATE *shuff, SHUFFCODE *ctable) char bit; SHUFFCODE symbolcode; - /* Abrimos el file */ + /* Abrimos el source y el destino */ + if (shuff->coderfp != NULL) fclose(shuff->coderfp); /* close bychunk temp file */ if ((fpsource = fopen(shuff->sourcefile,"r")) == NULL) return 0; if ((fpdest = vfopen(shuff->targetfile,"w",shuff->volsize)) == NULL) return 0; @@ -418,11 +422,11 @@ HUFF_STATE *shuff_init_encoder_bychunk(char *outputfile, long volsize) void shuff_deinit_encoder(HUFF_STATE *shuff) { /* Libero mallocs y cierro archivos */ - free(shuff->freqtable); - free(shuff->sourcefile); - free(shuff->targetfile); + free(shuff->freqtable); if (shuff->coderfp != NULL) fclose(shuff->coderfp); - if (shuff->decoderfp != NULL) vfclose(shuff->decoderfp); + if (shuff->preloadfreq == 1) unlink(shuff->sourcefile); + free(shuff->sourcefile); + free(shuff->targetfile); /* Destruyo recursivamente el arbol de codigos */ } diff --git a/src/statichuff/statichuff.h b/src/statichuff/statichuff.h index 5bc1645..d892aea 100644 --- a/src/statichuff/statichuff.h +++ b/src/statichuff/statichuff.h @@ -33,10 +33,12 @@ typedef struct t_huff { unsigned long int bytesleft; /* cuanto falta descomprimir en un bychunk */ } HUFF_STATE; + HUFF_STATE *shuff_init_encoder_byfile(char *inputfile, char *outputfile, long volsize); 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); +int shuff_encode_file(HUFF_STATE *shuff); int shuff_decode_file(HUFF_STATE *shuff); #endif /* _STATICHUFF_H_ */