]> git.llucax.com Git - z.facultad/75.06/jacu.git/blob - src/statichuff/main.c
Cambio sugerido por nico.
[z.facultad/75.06/jacu.git] / src / statichuff / main.c
1
2 #include "statichuff.h"
3 #include <stdlib.h>
4
5 int main(int argc, char* argv[])
6 {       
7         int cflag = 0;
8         int dflag = 0;
9         int tflag = 0;
10         int mflag = 0;
11         int sflag = 0;
12         long int volumesize = 0;
13         int ch;
14         HUFF_STATE *shuff;
15         char *staticmodel = NULL;
16                         
17         while ((ch = getopt(argc, argv, "scdm:t:")) != -1) { 
18                  
19                 switch (ch) { 
20                         case 'c': cflag = 1; 
21                                           break;
22                         
23                         case 'd': dflag = 1; 
24                                           break; 
25                         
26                         case 't': tflag = 1; 
27                                           volumesize = atoi(optarg);                                      
28                                           break; 
29                         
30                         case 'm': mflag = 1;
31                                           staticmodel = optarg;
32                                           break; 
33                         
34                         case 's': sflag = 1;                                      
35                                           break;
36                         
37                         default: fprintf(stderr, "Usage: %s [-cds] [-t volsizekb] sourcefile targetfile [-m modeldumpfile]\n", argv[0]); 
38                                          return(2);
39                 }
40         }
41                 
42         if ( (argc == 1) || (cflag & dflag) || !(cflag | dflag) || ((argc - optind) < 2) ) {
43                 fprintf(stderr, "Usage: %s [-cds] [-t volsizekb] sourcefile targetfile [-m modeldumpfile]\n", argv[0]); 
44                 if ((tflag == 1) && (volumesize < 0)) fprintf(stderr,"Error: The volume size must be a non-zero value\n");
45                 return (2);             
46         }
47                 
48         if (cflag == 1) {
49                 /* Comprimo */
50                 shuff = shuff_init_encoder_byfile(argv[optind],argv[optind+1],volumesize*1024);
51                 if (mflag == 1) shuff_loadmodel(shuff,staticmodel);
52             shuff_encode_file(shuff);
53                 if (sflag == 1) shuff_savemodel(shuff);
54                 shuff_deinit_encoder(shuff);
55                 free(shuff);
56         }
57         
58         if (dflag == 1) { 
59                 /* Descomprimo */
60                 shuff = shuff_init_decoder(argv[optind],argv[optind+1]);
61                 shuff_decode_file(shuff);
62                 shuff_deinit_decoder(shuff);
63                 free(shuff);
64         }
65                 
66         return 0;
67 }