]> git.llucax.com Git - z.facultad/75.06/jacu.git/blobdiff - src/jacu.c
Bugfixes y mas cosas a la pantalla
[z.facultad/75.06/jacu.git] / src / jacu.c
index ba8daf1cdf4f47c23b2a2f71bcd507234821d2f6..dd1848594c3646e6695129682e62212cad2d4ef4 100644 (file)
@@ -96,7 +96,7 @@ int main(int argc, char* argv[])
 
                data = malloc(sizeof(char)*pagesize);
                /* Reservo lugar tambien para guardar el k y el tamaño  */
-               salida = malloc(sizeof(char)*(pagesize)+sizeof(Uint32)*2);
+               salida = malloc(sizeof(char)*pagesize+sizeof(Uint32)*2);
                bs = bs_create(pagesize);
 
                fp = fopen(argv[optind], "rb");
@@ -115,9 +115,27 @@ int main(int argc, char* argv[])
                        /* Hago el BS */
                        bs_solve(data, salida, bs, &k, i);
 
+                       printf("BS k=%ld\n", *(Uint32 *)(salida+sizeof(Uint32)));
+                       printf("PageSize = %ld\n", *(Uint32 *)salida);
+
+                       printf("Antes de MTF = %ld [", i);
+                       {
+                               int ii;
+                               for(ii=0; ii<(i+sizeof(Uint32)); ii++)
+                                       printf("(%c)", salida[ii+sizeof(Uint32)]);
+                               printf("]\n");
+                       }
                        /* Le aplico el MTF, salteo el tamaño del bloque para que no se pierda. */
                        mtf = jacu_mtf(salida+sizeof(Uint32), i+sizeof(Uint32), &z, &z_len);
 
+                       printf("MTF Z (len=%d) = [", z_len);
+                       {
+                               int ii;
+                               for(ii=0; ii<z_len; ii++)
+                                       printf("(%c)", z[ii]);
+                               printf("]\n");
+
+                       }
                        /* Si me lo piden, aplico ZG. */
                        if (zflag) {
                                size_t len;
@@ -129,17 +147,21 @@ int main(int argc, char* argv[])
                                        if ((len = zg_group(&zg, buff, mtf[j]))) fwrite(buff, 1, len, fp_out);
                        } else {
                                /* Guardo el PageSize */
-                               //for(j=0; j<sizeof(Uint32); j++)
-                               //      fputc(mtf[j], fp_out);
-                               fwrite(mtf, sizeof(Uint32), 1, fp_out);
+                               fwrite(salida, sizeof(Uint32), 1, fp_out);
 
                                /* Guardo el Z len y el Z */
                                fwrite(&z_len, sizeof(int), 1, fp_out);
                                fwrite(z, z_len, sizeof(char), fp_out);
 
                                /* Guardo la salida del MTF */
-                               for(j=sizeof(Uint32); j<i; j++)
+                               printf("Despues de MTF : [");
+                               for(j=0; j<(i+sizeof(Uint32)); j++) {
                                        fputc(mtf[j], fp_out);
+                                       putchar('(');
+                                       fputc(mtf[j], stdout);
+                                       putchar(')');
+                               }
+                               printf("]\n");
                        }
                        free(mtf);
                        free(z);
@@ -178,23 +200,52 @@ int main(int argc, char* argv[])
                        block_size = 0;
                        PERR("Leo bloque");
                        fread(&block_size, sizeof(Uint32), 1, fp_in);
+                       printf("PageSize = %ld\n", block_size);
                        fread(&z_len, sizeof(int), 1, fp_in);
                        z = malloc(sizeof(char)*z_len);
                        fread(z, z_len, sizeof(char), fp_in);
 
+                       printf("MTF Z (len=%d) = [", z_len);
+                       {
+                               int ii;
+                               for(ii=0; ii<z_len; ii++)
+                                       printf("(%c)", z[ii]);
+                               printf("]\n");
+
+                       }
                        if (block_size > 0) {
                                block = malloc(block_size*sizeof(char)+sizeof(Uint32));
                                orig = malloc(block_size*sizeof(char));
-                               fread(block, block_size, sizeof(char), fp_in);
+                               fread(block, block_size+sizeof(Uint32), sizeof(char), fp_in);
 
+                               printf("Antes MTF_inv = [");
+                               {
+                                       int ii;
+                                       for(ii=0; ii<block_size+sizeof(Uint32); ii++)
+                                               printf("(%c)", block[ii]);
+                                       printf("]\n");
+                               }
                                /* Hago el MTF inverso */
-                               mtf = jacu_mtf_inv(z, block, block_size);
+                               PERR("Haciendo MTF Inv");
+                               mtf = jacu_mtf_inv(z, block, block_size*sizeof(char)+sizeof(Uint32));
+
+                               printf("Luego de MTF Inv= [");
+                               {
+                                       int ii;
+                                       for(ii=0; ii<block_size+sizeof(Uint32); ii++)
+                                               printf("(%c)", mtf[ii]);
+                                       printf("]\n");
+                               }
 
                                /* Luego de hacer el MTF inverso ya puedo recuperar el k */
-                               memcpy(&k, block, sizeof(Uint32));
+                               PERR("Recuperando K");
+                               memcpy(&k, mtf, sizeof(Uint32));
 
+                               printf("Restored : k=%ld\n", k);
+                               PERR("BS_Restore");
                                bs_restore(orig, block+sizeof(Uint32), k, block_size);
 
+                               PERR("Saving Data");
                                fwrite(orig, block_size, sizeof(char), fp_out);
                                free(block);
                                free(orig);