]> git.llucax.com Git - z.facultad/75.06/jacu.git/blob - src/statichuff/main.c
Another safe upload..
[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         long int volumesize = 0;
11         int ch;
12         HUFF_STATE *shuff;
13                         
14         while ((ch = getopt(argc, argv, "cdt:")) != -1) { 
15                  
16                 switch (ch) { 
17                         case 'c': cflag = 1; 
18                                           break;
19                         
20                         case 'd': dflag = 1; 
21                                           break; 
22                         
23                         case 't': tflag = 1; 
24                                           volumesize = atoi(optarg);                                      
25                                           break; 
26                         
27                         default: fprintf(stderr, "Usage: %s [-cdt] sourcefile targetfile\n", argv[0]); 
28                                          return(2);
29                 }
30         }
31                 
32         if ( (argc == 1) || (cflag & dflag) || !(cflag | dflag) || ((argc - optind) < 2) ) {
33                 fprintf(stderr, "Usage: %s [-cdt] sourcefile targetfile\n", argv[0]); 
34                 if ((tflag == 1) && (volumesize < 0)) fprintf(stderr,"Error: The volume size must be a non-zero value\n");
35                 return (2);             
36         }
37                 
38         if (cflag == 1) {
39                 /* Comprimo */
40                 shuff = shuff_init_encoder_byfile(argv[optind],argv[optind+1],volumesize*1024);
41             shuff_encode_file(shuff);
42                 shuff_deinit_encoder(shuff);
43                 free(shuff);
44         }
45         
46         if (dflag == 1) { 
47                 /* Descomprimo */
48                 shuff = shuff_init_decoder(argv[optind],argv[optind+1]);
49                 shuff_decode_file(shuff);
50                 shuff_deinit_decoder(shuff);
51                 free(shuff);
52         }
53                 
54         return 0;
55 }