2 #include "statichuff.h"
5 int main(int argc, char* argv[])
9 char *chunk = (char*)malloc(sizeof(char)*4);
15 long int volumesize = 0;
16 int lastchunk,i,j,ch,decoded = 0;
19 while ((ch = getopt(argc, argv, "scdm:t:")) != -1) {
29 volumesize = atoi(optarg);
39 default: fprintf(stderr, "Usage: %s [-cds] [-t volsizekb] sourcefile targetfile [-m modeldumpfile]\n", argv[0]);
44 if ( (argc == 1) || (cflag & dflag) || !(cflag | dflag) || ((argc - optind) < 2) || (mflag & sflag)) {
45 fprintf(stderr, "Usage: %s [-cds] [-t volsizekb] sourcefile targetfile [-m modeldumpfile]\n", argv[0]);
46 if ((tflag == 1) && (volumesize < 0)) fprintf(stderr,"Error: The volume size must be a non-zero value\n");
51 /* Inicio un compresor huffman estatico por chunks */
52 if ((shuff = shuff_init_encoder_bychunk(argv[optind+1],volumesize*1024)) == NULL) return 0;
53 if (mflag == 1) shuff_loadmodel(shuff,staticmodel);
55 /* Comprimo por chunks */
56 if ((fp = fopen(argv[optind],"rb")) == NULL) return 1;
59 while (!feof(fp) && (i < 4))
62 if (feof(fp)) continue;
66 /* Comprimo el chunk con huffman estatico */
67 shuff_scanfreq_chunk(shuff,chunk,i);
69 /* Le indico al huffman que efectivamente comprima los chunks */
70 shuff_encode_file(shuff);
71 if (sflag == 1) shuff_savemodel(shuff);
74 shuff_deinit_encoder(shuff);
76 /* Free mem allocated by main */
79 /* Close files opened by main */
85 shuff = shuff_init_decoder(argv[optind],NULL);
86 fp = fopen(argv[optind+1],"w");
88 /* Gimme chunks till last one */
89 while (shuff_decode_chunk(shuff,chunk,4,&decoded))
90 fwrite(chunk,decoded,1,fp);
92 /* Last chunk written alone */
93 fwrite(chunk,decoded,1,fp);
97 shuff_deinit_decoder(shuff);