Uint32 block_size, k;
char *block, *mtf, *orig;
char *z;
- int z_len;
+ int z_len,moredata = 0,decoded = 0;
- 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");
+ /* Inicializo el descompresor */
+ if ((shuff = shuff_init_decoder(argv[optind],NULL)) == NULL) return 1;
+
+ /* Abrimos el archivo de salida */
fp_out = fopen(argv[optind+1], "wb");
- while (!feof(fp_in)) {
- block_size = 0;
- fread(&block_size, sizeof(Uint32), 1, fp_in);
+ /* Descomprimimos de a chunks segun convenga */
+ do {
+ block_size = 0;
+ moredata = shuff_decode_chunk(shuff,(char*)&block_size,sizeof(Uint32),&decoded);
if (block_size > 0) {
- fread(&z_len, sizeof(int), 1, fp_in);
+ moredata = shuff_decode_chunk(shuff,(char*)&z_len,sizeof(int),&decoded);
z = malloc(sizeof(char)*z_len);
- fread(z, z_len, sizeof(char), fp_in);
+ moredata = shuff_decode_chunk(shuff,z,z_len,&decoded);
/*printf("MTF Z (len=%d) = [", z_len);
{
block = malloc(block_size*sizeof(char)+sizeof(Uint32));
orig = malloc(block_size*sizeof(char));
- fread(block, block_size+sizeof(Uint32), sizeof(char), fp_in);
+ moredata = shuff_decode_chunk(shuff,block,block_size+sizeof(Uint32),&decoded);
/*printf("Antes MTF_inv = [");
{
free(mtf);
free(z);
}
- }
- fclose(fp_in);
+ } while (moredata);
+
+ /* Close up files */
fclose(fp_out);
+
+ /* Shutdown Huffman */
+ shuff_deinit_decoder(shuff);
+ free(shuff);
}
return 0;