]> git.llucax.com Git - z.facultad/75.06/jacu.git/blob - src/statichuff/main.c
Cambios minimos, no se si entraran en la impresion :(
[z.facultad/75.06/jacu.git] / src / statichuff / main.c
1 /*----------------------------------------------------------------------------
2  *                   jacu - Just Another Compression Utility
3  *----------------------------------------------------------------------------
4  * This file is part of jacu.
5  *
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
9  * version.
10  *
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
14  * details.
15  *
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  *----------------------------------------------------------------------------
20  */
21
22
23 #include "statichuff.h"
24 #include <stdlib.h>
25
26 int main(int argc, char* argv[])
27 {       
28         int cflag = 0;
29         int dflag = 0;
30         int tflag = 0;
31         int mflag = 0;
32         int sflag = 0;
33         long int volumesize = 0;
34         int ch;
35         HUFF_STATE *shuff;
36         char *staticmodel = NULL;
37                         
38         while ((ch = getopt(argc, argv, "scdm:t:")) != -1) { 
39                  
40                 switch (ch) { 
41                         case 'c': cflag = 1; 
42                                           break;
43                         
44                         case 'd': dflag = 1; 
45                                           break; 
46                         
47                         case 't': tflag = 1; 
48                                           volumesize = atoi(optarg);                                      
49                                           break; 
50                         
51                         case 'm': mflag = 1;
52                                           staticmodel = optarg;
53                                           break; 
54                         
55                         case 's': sflag = 1;                                      
56                                           break;
57                         
58                         default: fprintf(stderr, "Usage: %s [-cds] [-t volsizekb] sourcefile targetfile [-m modeldumpfile]\n", argv[0]); 
59                                          return(2);
60                 }
61         }
62                 
63         if ( (argc == 1) || (cflag & dflag) || !(cflag | dflag) || ((argc - optind) < 2) ) {
64                 fprintf(stderr, "Usage: %s [-cds] [-t volsizekb] sourcefile targetfile [-m modeldumpfile]\n", argv[0]); 
65                 if ((tflag == 1) && (volumesize < 0)) fprintf(stderr,"Error: The volume size must be a non-zero value\n");
66                 return (2);             
67         }
68                 
69         if (cflag == 1) {
70                 /* Comprimo */
71                 shuff = shuff_init_encoder_byfile(argv[optind],argv[optind+1],volumesize*1024);
72                 if (mflag == 1) shuff_loadmodel(shuff,staticmodel);
73             shuff_encode_file(shuff);
74                 if (sflag == 1) shuff_savemodel(shuff);
75                 shuff_deinit_encoder(shuff);
76                 free(shuff);
77         }
78         
79         if (dflag == 1) { 
80                 /* Descomprimo */
81                 shuff = shuff_init_decoder(argv[optind],argv[optind+1]);
82                 shuff_decode_file(shuff);
83                 shuff_deinit_decoder(shuff);
84                 free(shuff);
85         }
86                 
87         return 0;
88 }