1 /*----------------------------------------------------------------------------
2 * jacu - Just Another Compression Utility
3 *----------------------------------------------------------------------------
4 * This file is part of jacu.
6 * jacu is free software; you can redistribute it and/or modify it under the
7 * terms of the GNU General Public License as published by the Free Software
8 * Foundation; either version 2 of the License, or (at your option) any later
11 * jacu is distributed in the hope that it will be useful, but WITHOUT ANY
12 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
16 * You should have received a copy of the GNU General Public License along
17 * with jacu; if not, write to the Free Software Foundation, Inc., 59 Temple
18 * Place, Suite 330, Boston, MA 02111-1307 USA
19 *----------------------------------------------------------------------------
23 #include "statichuff.h"
26 int main(int argc, char* argv[])
30 char *chunk = (char*)malloc(sizeof(char)*4);
36 long int volumesize = 0;
37 int lastchunk,i,j,ch,decoded = 0;
40 while ((ch = getopt(argc, argv, "scdm:t:")) != -1) {
50 volumesize = atoi(optarg);
60 default: fprintf(stderr, "Usage: %s [-cds] [-t volsizekb] sourcefile targetfile [-m modeldumpfile]\n", argv[0]);
65 if ( (argc == 1) || (cflag & dflag) || !(cflag | dflag) || ((argc - optind) < 2) || (mflag & sflag)) {
66 fprintf(stderr, "Usage: %s [-cds] [-t volsizekb] sourcefile targetfile [-m modeldumpfile]\n", argv[0]);
67 if ((tflag == 1) && (volumesize < 0)) fprintf(stderr,"Error: The volume size must be a non-zero value\n");
72 /* Inicio un compresor huffman estatico por chunks */
73 if ((shuff = shuff_init_encoder_bychunk(argv[optind+1],volumesize*1024)) == NULL) return 0;
74 if (mflag == 1) shuff_loadmodel(shuff,staticmodel);
76 /* Comprimo por chunks */
77 if ((fp = fopen(argv[optind],"rb")) == NULL) return 1;
80 while (!feof(fp) && (i < 4))
83 if (feof(fp)) continue;
87 /* Comprimo el chunk con huffman estatico */
88 shuff_scanfreq_chunk(shuff,chunk,i);
90 /* Le indico al huffman que efectivamente comprima los chunks */
91 shuff_encode_file(shuff);
92 if (sflag == 1) shuff_savemodel(shuff);
95 shuff_deinit_encoder(shuff);
97 /* Free mem allocated by main */
100 /* Close files opened by main */
106 shuff = shuff_init_decoder(argv[optind],NULL);
107 fp = fopen(argv[optind+1],"w");
109 /* Gimme chunks till last one */
110 while (shuff_decode_chunk(shuff,chunk,4,&decoded))
111 fwrite(chunk,decoded,1,fp);
113 /* Last chunk written alone */
114 fwrite(chunk,decoded,1,fp);
118 shuff_deinit_decoder(shuff);