/* Trato de hacer que el caracter sea comun en textos, para que no me rompa
* la localidad
*/
- data[i++] = hint+32;
+ data[i++] = hint;
bs_clean_dic();
/* El buffer no lo necesito mas */
buffer_pos = 0;
return i;
}
+char *bs_finalblock(char *data, Uint32 len, Uint32 *new_size)
+{
+ Uint32 size=0, i, j;
+ char *out = NULL;
+ unsigned char tmp;
+
+ for(i=0; i < len; i++) {
+ if (data[i] == ESCAPE_CHARACTER) {
+ i++;
+ if (data[i] == 0xF) {
+ /* Solo tengo que dejar el ESCAPE_CHARACTER */
+ size++;
+ out = (char *)realloc(out, size*sizeof(char));
+ out[size-1] = data[i];
+ /* Salteo ese caracter */
+ } else {
+ /* Va una palabra!! */
+ tmp = data[i];
+ printf("%d\n", data[i]);
+ size += dic[(size_t)tmp].len;
+ out = (char *)realloc(out, size*sizeof(char));
+ for(j=0; j<dic[(size_t)tmp].len; j++) {
+ printf("%c", dic[(size_t)tmp].word[j]);
+ out[size-dic[(size_t)tmp].len+j] = dic[(size_t)tmp].word[j];
+ }
+ printf("\n");
+ /* Salteo el caracter siguiente al de escape */
+ }
+ } else {
+ size++;
+ out = (char *)realloc(out, size*sizeof(char));
+ out[size-1] = data[i];
+ }
+ }
+
+ (*new_size) = size;
+ return out;
+}
+
#include <stdlib.h>
#include <stdio.h>
+#ifndef Uint32
typedef unsigned long int Uint32;
+#endif
typedef struct _bs_t_ t_BlockSort;
int bs_readblock(FILE *fp, char *data, Uint32 pagesize, int usar_dic);
+char *bs_finalblock(char *data, Uint32 len, Uint32 *new_size);
+
#endif
} t_Flags;
int comprimir(char *src, char *dst, Uint32 pagesize, Uint32 volumesize, t_Flags *flags, char *staticmodel);
-int descomprimir(char *src, char *dst);
+int descomprimir(char *src, char *dst, t_Flags *flags);
int main(int argc, char* argv[])
{
}
if (flags.dflag == 1) {
- return descomprimir(argv[optind], argv[optind+1]);
+ return descomprimir(argv[optind], argv[optind+1], &flags);
}
return 0;
return 0;
}
-int descomprimir(char *src, char *dst)
+int descomprimir(char *src, char *dst, t_Flags *flags)
{
/* Descomprimo */
FILE *fp_out;
Uint32 block_size = 0, k;
unsigned char *block, *mtf, *orig;
unsigned char *z;
- int z_len=0,moredata = 0,decoded = 0;
+ Uint32 z_len=0,moredata = 0,decoded = 0;
unsigned char use_zg = 0,retbytes = 0;
HUFF_STATE *shuff;
/* 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);
+ /* XXX AHORA METO EL FLAG EN EL ARCHIVO; DON'T WORRRRRYYYYYYY XXX */
+ if (flags->rflag == 1)
+ orig = bs_finalblock(orig, decoded-sizeof(Uint32), &decoded);
+
+ fwrite(orig, decoded, sizeof(unsigned char), fp_out);
free(mtf);
free(z);
}
}
/** Decodifica chunksize symbolos y los devuelve en un chunk de datos */
-int shuff_decode_chunk(HUFF_STATE *shuff, char *chunk, int chunksize, int *decodedbytes)
+int shuff_decode_chunk(HUFF_STATE *shuff, char *chunk, int chunksize, unsigned long int *decodedbytes)
{
SHUFFNODE *currnode = shuff->codetree;
unsigned short int decoded_symbol;
* \param chunksize Size del buffer o chunk que se quiere obtener.
* \return \b int Indica si hay mas datos a descomprimir o no (1 hay, 0 no hay)
*/
-int shuff_decode_chunk(HUFF_STATE *shuff, char *chunk, int chunksize, int *decodedbytes);
+int shuff_decode_chunk(HUFF_STATE *shuff, char *chunk, int chunksize, unsigned long int *decodedbytes);
/** Graba el modelo de un archivo que se ha comprimido. (Tabla de Freq)
*