]> git.llucax.com Git - z.facultad/75.06/jacu.git/blobdiff - src/blocksorting/bs.c
Agrego manejo de flags en el header, en total se puden usar hasta 8 flahs. 2 usadas
[z.facultad/75.06/jacu.git] / src / blocksorting / bs.c
index b0010c1534e3a7d39291e4b87bb69e29caa11fd2..a71e2619fea21c11416414108adb595861227d98 100644 (file)
@@ -312,13 +312,21 @@ int bs_readblock(FILE *fp, char *data, Uint32 pagesize, int usar_dic)
 
        while ((!feof(fp)) && ((i+buffer_pos) < pagesize)) {
                c = fgetc(fp);
-               hint = check_hint(c);
-
+               
                if (usar_dic != 1) {
                        data[i++] = c;
                        continue;
                }
 
+               if (c == ESCAPE_CHARACTER) {
+                       data[i++] = c;
+                       data[i++] = 0xF;
+                       bs_clean_dic();
+                       continue;
+               }
+
+               hint = check_hint(c);
+
                switch (hint) {
                        case -1:
                                /* No hay hints, vacio el buffer y luego saco el c */
@@ -341,15 +349,8 @@ 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();
-                               /* Imprimo el buffer que deberia ser la palabra que reemplazo */
-/*                             {
-                                       int iii;
-                                       for(iii=0; iii<buffer_pos; iii++)
-                                               printf("%c", buffer[iii]);
-                                       printf("%c\n", c);
-                               }                                       */
                                /* El buffer no lo necesito mas */
                                buffer_pos = 0;
                }
@@ -363,3 +364,39 @@ 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];
+                               size += dic[(size_t)tmp].len;
+                               out = (char *)realloc(out, size*sizeof(char));
+                               for(j=0; j<dic[(size_t)tmp].len; j++) {
+                                       out[size-dic[(size_t)tmp].len+j] = dic[(size_t)tmp].word[j];
+                               }
+                               /* 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;
+}
+