+/*----------------------------------------------------------------------------
+ * 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"
+void print_v(char *txt, char *data, Uint32 len)
+{
+ Uint32 i;
+
+ printf("%s", txt);
+
+ for(i=0; i<len; i++) {
+ if (data[i] == '\n')
+ printf("#");
+ else
+ printf("%c", data[i]);
+ }
+ printf("\n");
+}
+
int main(int argc, char *argv[])
{
char *data;
fp = fopen(argv[1], "r");
len = atoi(argv[2]);
} else if (argc == 2) {
- fp = stdin; /*fopen(argv[1], "r");*/
+ fp = stdin;
len = atoi(argv[1]);
} else {
printf("no, no\n");
}
data = malloc(sizeof(char)*len);
- salida = malloc(sizeof(char)*(len+1));
+ 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++;
- }
+ 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 : %s -> %ld\n", salida, k);
- bs_restore(orig, salida, k, i);
- printf("Orig : %s\n", orig);
+ 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
- printf("(%s)\n", salida);
+ fwrite(salida, 1, i, stdout);
}
fclose(fp);
bs_destroy(bs);
- printf("Total bytes : %ld\n", total);
- free(data);
+ /*printf("Total bytes : %ld\n", total);*/
free(salida);
free(orig);
return 0;