2 #include "blocksorting/bs.h"
4 #include "zerogrouping/zerogrouping.h"
5 #include "statichuff/statichuff.h"
6 #include "vfile/vfile.h"
11 int main(int argc, char* argv[])
18 long int volumesize = 0;
19 size_t pagesize = 32768; /* 32KB */
23 while ((ch = getopt(argc, argv, "cdzt:p:")) != -1) {
36 volumesize = atol(optarg);
40 pagesize = atoi(optarg);
43 default: fprintf(stderr, "Usage: %s [-cdpt] sourcefile targetfile\n", argv[0]);
48 if ( (argc == 1) || (cflag & dflag) || !(cflag | dflag) || ((argc - optind) < 2) ) {
49 fprintf(stderr, "Usage: %s [-cdt] sourcefile targetfile\n", argv[0]);
52 if ((tflag) && (volumesize <= 0l)) {
53 fprintf(stderr,"Error: The volume size must be a non-zero value\n");
56 if ((pflag) && (pagesize <= 1u)) {
57 fprintf(stderr,"Error: El tamaño de página debe ser mayor a 1 byte.\n");
63 /* No me gusta el tmpfile ... es para probar como anda todo junto */
65 unsigned long int i, j, total, k;
67 char *salida, *data, c;
68 data = malloc(sizeof(char)*pagesize);
69 /* Reservo lugar tambien para guardar el k y el tamaño */
70 salida = malloc(sizeof(char)*(pagesize)+sizeof(unsigned long int)*2);
71 bs = bs_create(pagesize);
73 fp = fopen(argv[optind], "rb");
74 fp_out = fopen("tmp.comp", "wb");
80 while ((!feof(fp)) && (i < pagesize)) {
87 bs_solve(data, salida, bs, &k, i);
89 /* Le aplico el MTF, salteo el tamaño del bloque para que no se pierda. */
90 mtf = jacu_mtf(salida+sizeof(unsigned long int), i+sizeof(unsigned long int));
92 /* Si me lo piden, aplico ZG. */
99 for (j = 0; j < i; ++j)
100 if ((len = zg_group(&zg, buff, mtf[j]))) fwrite(buff, 1, len, fp_out);
105 fputc(mtf[j], fp_out);
115 /* Comprimo con huffman */
116 i = shuff_encode_file("tmp.comp",argv[optind+1], volumesize);
118 /* borro el temporal */
127 unsigned long int block_size, k;
128 char *block, *mtf, *orig;
131 shuff_decode_file(argv[optind], "tmp.comp"); /*argv[optind+1]);*/
132 fp_in = vfopen("tmp.comp", "r", 0);
133 fp_out = fopen(argv[optind+1], "wb");
135 while (!vfeof(fp_in)) {
137 vfread(&block_size, sizeof(unsigned long int), 1, fp_in);
138 if (block_size > 0) {
139 block = malloc((block_size+sizeof(unsigned long int))*sizeof(char));
140 orig = malloc(block_size*sizeof(char));
141 vfread(block, block_size, sizeof(char), fp_in);
143 mtf = jacu_mtf_inv(block, /*XXX NO LO TENGO XXX */pos, block_size);
145 memcpy(&k, block, sizeof(unsigned long int));
147 bs_restore(orig, block+sizeof(unsigned long int), k, block_size);
149 fwrite(orig, block_size, sizeof(char), fp_out);