#include "bs.h"
-void _print_(char *s, size_t len)
+void print_v(char *txt, char *data, Uint32 len)
{
- size_t i;
- for(i=0; i<len; i++)
- printf("(%d)", s[i]);
+ Uint32 i;
+
+ printf("%s", txt);
+
+ for(i=0; i<len; i++) {
+ if (data[i] == '\n')
+ printf("#");
+ else
+ printf("%c", data[i]);
+ }
printf("\n");
}
}
data = malloc(sizeof(char)*len);
- salida = malloc(sizeof(char)*(len+1+sizeof(unsigned long int)*2));
+ salida = malloc(sizeof(char)*(len+1+sizeof(unsigned long int)));
orig = malloc(sizeof(char)*(len+1));
salida[len] = '\0';
bs = bs_create(len);
- c = fgetc(fp);
total = 0;
while (!feof(fp)) {
i = 0;
- while ((!feof(fp)) && (i < len)) {
- data[i++] = c;
- c = fgetc(fp);
- total++;
- }
- /* lleno data mano! */
- srand(time(NULL));
- {
- size_t jj;
- for(jj=0; jj<i;jj++)
- data[jj] = rand()%255;
- }
- printf("Leido : ");
- _print_(data, i);
+ i = bs_readblock(fp, data, len, 1);
+
+ total += i;
+
bs_solve(data, salida, bs, &k, i);
/* XXX ACA SALIDA DEBERIA PASAR A LA SIGUIENTE ETAPA XXX */
if (argc == 3) {
- printf("BS : %ld ", k);
- _print_(salida+8, i);
- bs_restore(orig, salida+sizeof(Uint32)*2, k, i);
- printf("Orig : ");
- _print_(orig, i);
+ bs_restore(orig, salida+sizeof(Uint32), k, i);
+ print_v("Leido : ", data, i);
+ print_v("BS : ", salida+sizeof(Uint32), i);
+ /*print_v("Restorado : ", orig, i);*/
} else
fwrite(salida, 1, i, stdout);
}