Ignore:
Timestamp:
Jan 4, 2005, 12:26:29 AM (18 years ago)
Author:
Sam Hocevar
Message:
  • debug message system
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pwntcha/trunk/src/main.c

    r391 r392  
    1414#include <string.h>
    1515#include <getopt.h>
     16#include <stdarg.h>
    1617
    1718#include "config.h"
     
    2425#endif
    2526
     27/* Used for the debug messages */
     28char *argv0 = NULL;
     29int debug = 1;
     30
    2631int main(int argc, char *argv[])
    2732{
    2833    char *mode = "auto";
     34
     35    argv0 = argv[0];
    2936
    3037    int c;
     
    4047            { "mode", 1, 0, 'm' },
    4148            { "help", 0, 0, 'h' },
     49            { "quiet", 0, 0, 'q' },
    4250            { "version", 0, 0, 'v' },
    4351            { 0, 0, 0, 0 }
    4452        };
    4553
    46         c = getopt_long(argc, argv, "hm:v", long_options, &option_index);
     54        c = getopt_long(argc, argv, "hm:qv", long_options, &option_index);
    4755#else
    48         c = getopt(argc, argv, "hm:v");
     56        c = getopt(argc, argv, "hm:qv");
    4957#endif
    5058        if(c == -1)
     
    5765#ifdef HAVE_GETOPT_LONG
    5866            printf("  -m, --mode      force operating mode\n");
     67            printf("  -q, --quiet     do not print information messages\n");
    5968            printf("  -h, --help      display this help and exit\n");
    6069            printf("  -v, --version   output version information and exit\n");
    6170#else
    6271            printf("  -m     force operating mode\n");
     72            printf("  -q     do not print information messages\n");
    6373            printf("  -h     display this help and exit\n");
    6474            printf("  -v     output version information and exit\n");
     
    6777        case 'm': /* --mode */
    6878            mode = optarg;
     79            break;
     80        case 'q': /* --quiet */
     81            debug = 0;
    6982            break;
    7083        case 'v': /* --version */
     
    101114        if(!img)
    102115        {
    103             fprintf(stderr, "%s: cannot load %s\n", argv[0], input);
     116            dprintf("cannot load %s\n", input);
    104117            printf("\n");
    105118            continue;
     
    115128        {
    116129            if(img->width == 320 && img->height == 50)
     130            {
     131                dprintf("autodetecting phpBB captcha\n");
    117132                result = decode_phpbb(img);
     133            }
    118134            else if(img->height == 69)
     135            {
     136                dprintf("autodetecting slashdot captcha\n");
    119137                result = decode_slashdot(img);
     138            }
    120139            else
    121140            {
    122                 fprintf(stderr, "%s: could not guess captcha type\n", argv[0]);
     141                dprintf("could not guess captcha type\n");
    123142                printf("\n");
    124143                image_free(img);
     
    131150        if(!result)
    132151        {
    133             fprintf(stderr, "%s: sorry, decoding failed\n", argv[0]);
     152            dprintf("sorry, decoding failed\n");
    134153            printf("\n");
    135154            continue;
     
    143162}
    144163
     164void dprintf(const char *fmt, ...)
     165{
     166    va_list args;
     167
     168    if(!debug)
     169        return;
     170
     171    va_start(args, fmt);
     172    fprintf(stderr, "%s: ", argv0);
     173    vfprintf(stderr, fmt, args);
     174    va_end(args);
     175}
     176
Note: See TracChangeset for help on using the changeset viewer.