source: pwntcha/trunk/src/main.c @ 388

Last change on this file since 388 was 388, checked in by Sam Hocevar, 15 years ago
  • use getopt.
  • Property svn:keywords set to Id
File size: 2.8 KB
Line 
1/*
2 * main.c: main function
3 * $Id: main.c 388 2005-01-03 16:32:07Z sam $
4 *
5 * Copyright: (c) 2004 Sam Hocevar <sam@zoy.org>
6 *   This program is free software; you can redistribute it and/or
7 *   modify it under the terms of the Do What The Fuck You Want To
8 *   Public License as published by Banlu Kemiyatorn. See
9 *   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
10 */
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <getopt.h>
15
16#include "config.h"
17#include "common.h"
18
19int main(int argc, char *argv[])
20{
21    char *mode = "auto";
22
23    int c;
24    int digit_optind = 0;
25
26    for(;;)
27    {
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        }
68    }
69
70    if(optind >= argc)
71    {
72        printf("%s: too few arguments\n", argv[0]);
73        printf("Try `%s --help' for more information.\n", argv[0]);
74        return 1;
75    }
76
77    for(; optind < argc; optind++)
78    {
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);
100    }
101
102    return 0;
103}
104
Note: See TracBrowser for help on using the repository browser.