2 #include "statichuff/statichuff.h"
3 #include "blocksorting/bs.h"
5 #include "vfile/vfile.h"
10 int main(int argc, char* argv[])
16 long int volumesize = 0;
17 size_t pagesize = 32768; /* 32KB */
21 while ((ch = getopt(argc, argv, "cdt:p:")) != -1) {
31 volumesize = atol(optarg);
35 pagesize = atoi(optarg);
38 default: fprintf(stderr, "Usage: %s [-cdpt] sourcefile targetfile\n", argv[0]);
43 if ( (argc == 1) || (cflag & dflag) || !(cflag | dflag) || ((argc - optind) < 2) ) {
44 fprintf(stderr, "Usage: %s [-cdt] sourcefile targetfile\n", argv[0]);
47 if ((tflag) && (volumesize <= 0l)) {
48 fprintf(stderr,"Error: The volume size must be a non-zero value\n");
51 if ((pflag) && (pagesize <= 1u)) {
52 fprintf(stderr,"Error: El tamaño de página debe ser mayor a 1 byte.\n");
58 /* No me gusta el tmpfile ... es para probar como anda todo junto */
60 unsigned long int i, j, total, k;
62 char *salida, *data, c;
63 data = malloc(sizeof(char)*pagesize);
64 /* Reservo lugar tambien para guardar el k y el tamaño */
65 salida = malloc(sizeof(char)*(pagesize)+sizeof(unsigned long int)*2);
66 bs = bs_create(pagesize);
68 fp = fopen(argv[optind], "rb");
69 fp_out = fopen("tmp.comp", "wb");
75 while ((!feof(fp)) && (i < pagesize)) {
82 bs_solve(data, salida, bs, &k, i);
84 /* Le aplico el MTF, salteo el tamaño del bloque para que no se pierda. */
85 mtf = jacu_mtf(salida+sizeof(unsigned long int), i+sizeof(unsigned long int));
87 fputc(mtf[j], fp_out);
96 /* Comprimo con huffman */
97 i = shuff_encode_file("tmp.comp",argv[optind+1], volumesize);
99 /* borro el temporal */
108 unsigned long int block_size, k;
109 char *block, *mtf, *orig;
112 shuff_decode_file(argv[optind], "tmp.comp"); /*argv[optind+1]);*/
113 fp_in = vfopen("tmp.comp", "r", 0);
114 fp_out = fopen(argv[optind+1], "wb");
116 while (!vfeof(fp_in)) {
118 vfread(&block_size, sizeof(unsigned long int), 1, fp_in);
119 if (block_size > 0) {
120 block = malloc((block_size+sizeof(unsigned long int))*sizeof(char));
121 orig = malloc(block_size*sizeof(char));
122 vfread(block, block_size, sizeof(char), fp_in);
124 mtf = jacu_mtf_inv(block, /*XXX NO LO TENGO XXX */pos, block_size);
126 memcpy(&k, block, sizeof(unsigned long int));
128 bs_restore(orig, block+sizeof(unsigned long int), k, block_size);
130 fwrite(orig, block_size, sizeof(char), fp_out);