]> git.llucax.com Git - z.facultad/75.06/jacu.git/commitdiff
Agrego Descomprimir con diccionario. POR AHORA SE NECESITA PASAR -r AL DESCOMPRIMIR...
authorRicardo Markiewicz <gazer.arg@gmail.com>
Mon, 28 Jun 2004 04:04:36 +0000 (04:04 +0000)
committerRicardo Markiewicz <gazer.arg@gmail.com>
Mon, 28 Jun 2004 04:04:36 +0000 (04:04 +0000)
 CON -r PARA QUE JACU SEPA!! ... AHORA ME PONGO A METER EL FLAGS EN EL FILE!

src/blocksorting/bs.c
src/blocksorting/bs.h
src/jacu.c
src/statichuff/statichuff.c
src/statichuff/statichuff.h

index 1988f49e450430e9078d10b8ec27208b018e4ff3..1b7c0e30d8e62c03530df04147aa95d5fbc54f0b 100644 (file)
@@ -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<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;
+}
+
index 0cfec7fd05080bc32f4ed6ab41ac097ca18f3f55..d3c47c9ec365c18af7a0eb6d55d65876a560c4c2 100644 (file)
@@ -6,7 +6,9 @@
 #include <stdlib.h>
 #include <stdio.h>
 
+#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
 
index 1648e82eb0b6599a62c98fcf1e861af59f6ef9ed..8f9beb0fb2f9230153d0bca58abbba76aadb646b 100644 (file)
@@ -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);
                }
index 6b3b4d526a5defb62c25d13583993ba811a3934c..f339ef0558b67c93b54905a7514f223516a343a6 100644 (file)
@@ -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;      
index 065b8c39b6bd06ce3e63bce6256842ca2498e669..3289aeb3a89f6738cd74483fa94c8284eb08700e 100644 (file)
@@ -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)
  *