2 #include "statichuff.h"
5 int main(int argc, char* argv[])
9 char *chunk = (char*)malloc(sizeof(char)*4);
13 long int volumesize = 0;
16 while ((ch = getopt(argc, argv, "cdt:")) != -1) {
26 volumesize = atoi(optarg);
29 default: fprintf(stderr, "Usage: %s [-cdt] sourcefile targetfile\n", argv[0]);
34 if ( (argc == 1) || (cflag & dflag) || !(cflag | dflag) || ((argc - optind) < 2) ) {
35 fprintf(stderr, "Usage: %s [-cdt] sourcefile targetfile\n", argv[0]);
36 if ((tflag == 1) && (volumesize < 0)) fprintf(stderr,"Error: The volume size must be a non-zero value\n");
41 /* Inicio un compresor huffman estatico por chunks */
42 if ((shuff = shuff_init_static_bychunk(argv[optind+1],volumesize*1024)) == NULL) return 0;
44 /* Comprimo por chunks */
45 if ((fp = fopen(argv[optind],"rb")) == NULL) return 1;
48 while (!feof(fp) && (i < 4))
51 if (feof(fp)) continue;
55 /* Comprimo el chunk con huffman estatico */
56 shuff_encode_chunk(shuff,chunk,i,0);
58 /* Le indico al huffman que efectivamente comprima los chunks */
59 shuff_encode_file(shuff);
61 /* De init shuffman by chunks */
62 shuff_deinit_static_bychunk(shuff);
64 /* Free mem allocated by main */
68 /* Close files opened by main */
74 return shuff_decode_file(argv[optind],argv[optind+1]);