+ FILE *fp_out;
+ /*FILE *fp_in;*/
+ Uint32 block_size = 0, k;
+ unsigned char *block, *mtf, *orig;
+ unsigned char *z;
+ int z_len,moredata = 0,decoded = 0;
+ char use_zg;
+
+ /* 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");
+
+ /* Descomprimo primero que nada el pagesize utilizado para comprimir */
+ if (!(moredata = shuff_decode_chunk(shuff,(char*)&block_size,sizeof(Uint32),&decoded))) return 1;
+
+ /* Descomprimo byte que indica si se usa ZG */
+ if (!(moredata = shuff_decode_chunk(shuff, &use_zg, 1, &decoded))) return 1;
+
+ /* Creo buffers */
+ block = malloc(block_size*sizeof(unsigned char)+sizeof(Uint32));
+ orig = malloc(block_size*sizeof(unsigned char));
+
+ /* Descomprimimos de a chunks segun convenga */
+ do {
+ if (block_size > 0) {
+ /* Descomprimo el Zlen y el Z del MTF */
+ moredata = shuff_decode_chunk(shuff,(char*)&z_len,sizeof(int),&decoded);
+ z = malloc(sizeof(unsigned char)*z_len);
+ moredata = shuff_decode_chunk(shuff,z,z_len,&decoded);
+
+ /* Levanto una salida de MTF y le aplico MTF Inverso */
+ moredata = shuff_decode_chunk(shuff,block,block_size+sizeof(Uint32),&decoded);
+ mtf = jacu_mtf_inv(z, block, decoded);
+
+ /* Ya tengo la salida del BS, tonces levanto su K */
+ memcpy(&k, mtf, sizeof(Uint32));
+
+ /* Obtengo el chunk original aplicando BS Inverso */
+ bs_restore(orig, mtf+sizeof(Uint32), k, decoded - sizeof(Uint32));
+
+ fwrite(orig, decoded - sizeof(Uint32), sizeof(unsigned char), fp_out);
+ free(mtf);
+ free(z);
+ }
+ else return 1;
+ } while (moredata);
+
+ /* Close up files and free mem */
+ fclose(fp_out);
+ free(block);
+ free(orig);