size_t pagesize = 32768; /* 32KB */
int ch;
t_BlockSort *bs;
+ HUFF_STATE *shuff;
while ((ch = getopt(argc, argv, "cdzt:q:")) != -1) {
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) {
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");
fclose(file);
return file_size;
}
-
#include "statichuff.h"
#include <stdlib.h>
+#include <string.h>
void putbit(char bit, char restart, char flush, VFILE *fp)
{
}
/* 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);
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);