From 0e2f6af6947a3915d2ba95e013ed0d81ab49fbd0 Mon Sep 17 00:00:00 2001 From: Ricardo Markiewicz Date: Mon, 28 Jun 2004 04:04:36 +0000 Subject: [PATCH] Agrego Descomprimir con diccionario. POR AHORA SE NECESITA PASAR -r AL DESCOMPRIMIR SI SE COMPRIMIO CON -r PARA QUE JACU SEPA!! ... AHORA ME PONGO A METER EL FLAGS EN EL FILE! --- src/blocksorting/bs.c | 41 ++++++++++++++++++++++++++++++++++++- src/blocksorting/bs.h | 4 ++++ src/jacu.c | 14 ++++++++----- src/statichuff/statichuff.c | 2 +- src/statichuff/statichuff.h | 2 +- 5 files changed, 55 insertions(+), 8 deletions(-) diff --git a/src/blocksorting/bs.c b/src/blocksorting/bs.c index 1988f49..1b7c0e3 100644 --- a/src/blocksorting/bs.c +++ b/src/blocksorting/bs.c @@ -349,7 +349,7 @@ int bs_readblock(FILE *fp, char *data, Uint32 pagesize, int usar_dic) /* 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; @@ -364,3 +364,42 @@ int bs_readblock(FILE *fp, char *data, Uint32 pagesize, int usar_dic) 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 #include +#ifndef Uint32 typedef unsigned long int Uint32; +#endif typedef struct _bs_t_ t_BlockSort; @@ -58,5 +60,7 @@ void bs_restore(char *dst, char *c, Uint32 k, Uint32 len); int bs_readblock(FILE *fp, char *data, Uint32 pagesize, int usar_dic); +char *bs_finalblock(char *data, Uint32 len, Uint32 *new_size); + #endif diff --git a/src/jacu.c b/src/jacu.c index 1648e82..8f9beb0 100644 --- a/src/jacu.c +++ b/src/jacu.c @@ -24,7 +24,7 @@ typedef struct _flags_ { } 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[]) { @@ -111,7 +111,7 @@ 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; @@ -219,14 +219,14 @@ int comprimir(char *src, char *dst, Uint32 pagesize, Uint32 volumesize, t_Flags 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; @@ -298,7 +298,11 @@ int descomprimir(char *src, char *dst) /* 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); } diff --git a/src/statichuff/statichuff.c b/src/statichuff/statichuff.c index 6b3b4d5..f339ef0 100644 --- a/src/statichuff/statichuff.c +++ b/src/statichuff/statichuff.c @@ -346,7 +346,7 @@ SHUFFNODE *shuff_decode_symbols(SHUFFNODE *entrynode, unsigned long int buffer, } /** 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; diff --git a/src/statichuff/statichuff.h b/src/statichuff/statichuff.h index 065b8c3..3289aeb 100644 --- a/src/statichuff/statichuff.h +++ b/src/statichuff/statichuff.h @@ -124,7 +124,7 @@ int shuff_scanfreq_chunk(HUFF_STATE *shuff, char* chunk, int chunksize); * \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) * -- 2.43.0