]> 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 d31c648505d8bbd2a63d52335df36992d5f85e46..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,16 @@ int main(int argc, char* argv[])
                        /* Hago el BS */
                        bs_solve(data, salida, bs, &k, i);
 
-                       printf("BS k=%ld\n", k);
-                       printf("PageSize = %ld\n", 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);
 
@@ -125,7 +132,7 @@ int main(int argc, char* argv[])
                        {
                                int ii;
                                for(ii=0; ii<z_len; ii++)
-                                       printf("%c", z[ii]);
+                                       printf("(%c)", z[ii]);
                                printf("]\n");
 
                        }
@@ -140,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(&i, 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);
@@ -198,24 +209,43 @@ int main(int argc, char* argv[])
                        {
                                int ii;
                                for(ii=0; ii<z_len; ii++)
-                                       printf("%c", z[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);