]> git.llucax.com Git - z.facultad/75.06/jacu.git/blobdiff - src/blocksorting/bs.c
Cambios minimos, no se si entraran en la impresion :(
[z.facultad/75.06/jacu.git] / src / blocksorting / bs.c
index b0010c1534e3a7d39291e4b87bb69e29caa11fd2..c6ad0917f60a7bf884b9fceba1ab1183973d3e4a 100644 (file)
@@ -1,3 +1,24 @@
+/*----------------------------------------------------------------------------
+ *                   jacu - Just Another Compression Utility
+ *----------------------------------------------------------------------------
+ * This file is part of jacu.
+ *
+ * jacu is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 2 of the License, or (at your option) any later
+ * version.
+ *
+ * jacu is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with jacu; if not, write to the Free Software Foundation, Inc., 59 Temple
+ * Place, Suite 330, Boston, MA  02111-1307  USA
+ *----------------------------------------------------------------------------
+ */
+
 
 #include "bs.h"
 #include <stdlib.h>
@@ -92,6 +113,24 @@ t_Diccionario dic[] = {
        PALABRA(" tener"),
        PALABRA(" ningún"),
        PALABRA(" fácil"),
+       /* Algunas cosas de ingles para mejorar otros textos */
+       PALABRA(" as "),
+       PALABRA(" will "),
+       PALABRA(" with "),
+       PALABRA(" this "),
+       PALABRA(" program "),
+       PALABRA(" are "),
+       PALABRA(" The "),
+       PALABRA(" it "),
+       PALABRA(" which "),
+       PALABRA(" for "),
+       PALABRA(" be "),
+       PALABRA(" that "),
+       PALABRA(" is "),
+       PALABRA(" and "),
+       PALABRA(" to "),
+       PALABRA(" of "),
+       PALABRA(" the ")
 };
 
 typedef struct _bs_decode_t_ {
@@ -312,13 +351,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 +388,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 +403,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;
+}
+