Changeset 388 for pwntcha/trunk
- Timestamp:
- Jan 3, 2005, 5:32:07 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pwntcha/trunk/src/main.c
r387 r388 12 12 #include <stdio.h> 13 13 #include <stdlib.h> 14 #include <getopt.h> 14 15 15 16 #include "config.h" … … 18 19 int main(int argc, char *argv[]) 19 20 { 20 struct image *img; 21 char *result; 21 char *mode = "auto"; 22 22 23 if(argc != 2) 23 int c; 24 int digit_optind = 0; 25 26 for(;;) 24 27 { 25 fprintf(stderr, "usage: %s <image>\n", argv[0]); 26 return -1; 28 int this_option_optind = optind ? optind : 1; 29 int option_index = 0; 30 static struct option long_options[] = 31 { 32 { "mode", 1, 0, 'm' }, 33 { "help", 0, 0, 'h' }, 34 { "version", 0, 0, 'v' }, 35 { 0, 0, 0, 0 } 36 }; 37 38 c = getopt_long(argc, argv, "hm:v", long_options, &option_index); 39 if(c == -1) 40 break; 41 42 switch(c) 43 { 44 case 'h': /* --help */ 45 printf("Usage: %s [OPTION]... FILE...\n", argv[0]); 46 printf(" -m, --mode force operating mode\n"); 47 printf(" -h, --help display this help and exit\n"); 48 printf(" -v, --version output version information and exit\n"); 49 return 0; 50 case 'm': /* --mode */ 51 mode = optarg; 52 break; 53 case 'v': /* --version */ 54 printf("pwntcha (CAPTCHA decoder) %s\n", VERSION); 55 printf("Written by Sam Hocevar.\n"); 56 printf("\n"); 57 printf("Copyright (C) 2004-2005 Sam Hocevar <sam@zoy.org>\n"); 58 printf("This is free software; see the source for copying conditions. There is NO\n"); 59 printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"); 60 return 0; 61 case '?': 62 break; 63 default: 64 printf("%s: invalid option -- %i\n", argv[0], c); 65 printf("Try `%s --help' for more information.\n", argv[0]); 66 return 1; 67 } 27 68 } 28 69 29 img = image_load(argv[1]); 30 if(!img) 70 if(optind >= argc) 31 71 { 32 fprintf(stderr, "cannot load %s\n", argv[1]); 33 return -1; 72 printf("%s: too few arguments\n", argv[0]); 73 printf("Try `%s --help' for more information.\n", argv[0]); 74 return 1; 34 75 } 35 76 36 result = decode_slashdot(img); 37 if(!result) 77 for(; optind < argc; optind++) 38 78 { 39 fprintf(stderr, "sorry, decoding failed\n"); 40 return -1; 79 char *input = argv[optind], *result; 80 struct image *img; 81 82 img = image_load(argv[optind]); 83 if(!img) 84 { 85 fprintf(stderr, "%s: cannot load %s\n", argv[0], input); 86 printf("\n"); 87 continue; 88 } 89 90 result = decode_slashdot(img); 91 if(!result) 92 { 93 fprintf(stderr, "%s: sorry, decoding failed\n", argv[0]); 94 printf("\n"); 95 continue; 96 } 97 98 printf("%s\n", result); 99 free(result); 41 100 } 42 43 printf("%s\n", result);44 101 45 102 return 0;
Note: See TracChangeset
for help on using the changeset viewer.