diff options
Diffstat (limited to 'src/eclat.c')
-rw-r--r-- | src/eclat.c | 77 |
1 files changed, 20 insertions, 57 deletions
diff --git a/src/eclat.c b/src/eclat.c index 3703376..86b4627 100644 --- a/src/eclat.c +++ b/src/eclat.c @@ -19,5 +19,4 @@ char *conffile = SYSCONFDIR "/eclat.conf" ; int lint_mode; -int debug_level[ECLAT_DEBCAT_MAX]; int dry_run_mode; int preprocess_only = 0; @@ -31,57 +30,21 @@ enum eclat_command eclat_command; -struct debug_trans { - const char *name; - size_t length; - int cat; +static char *categories[] = { + "main", + "cfgram", + "cflex", + "conf", + "curl", }; -static struct debug_trans debug_trans[] = { -#define S(s) #s, sizeof(#s)-1 - { S(main), ECLAT_DEBCAT_MAIN }, - { S(cfgram), ECLAT_DEBCAT_CFGRAM }, - { S(cflex), ECLAT_DEBCAT_CFLEX }, - { S(conf), ECLAT_DEBCAT_CONF }, - { S(curl), ECLAT_DEBCAT_CURL }, - { NULL } -}; - -static int -parse_debug_level(const char *arg) +static void +debug_init() { - unsigned long cat, lev; - char *p; + int i; - if (isascii(*arg) && isdigit(*arg)) { - cat = strtoul(arg, &p, 10); - if (cat > ECLAT_DEBCAT_MAX) - return -1; - } else { - size_t len = strcspn(arg, "."); - struct debug_trans *dp; - - for (dp = debug_trans; dp->name; dp++) - if (dp->length == len && - memcmp(dp->name, arg, len) == 0) - break; - - if (!dp->name) - return -1; - cat = dp->cat; - p = (char*) arg + len; - } - - if (*p == 0) - lev = 100; - else if (*p != '.') - return -1; - else { - lev = strtoul(p + 1, &p, 10); - if (*p) - return -1; - } - debug_level[cat] = lev; - return 0; + for (i = 0; i < sizeof(categories)/sizeof(categories[0]); i++) + debug_register(categories[i]); } + static void @@ -91,5 +54,5 @@ dump(const char *text, FILE *stream, unsigned char *ptr, size_t size) size_t c; unsigned int width = 0x10; - int hex = debug_level[ECLAT_DEBCAT_CURL] > 2; + int hex = debug_level(ECLAT_DEBCAT_CURL) > 2; if (!hex) @@ -200,5 +163,5 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data) /* FIXME: Debugging level. */ - if (debug_level[ECLAT_DEBCAT_MAIN] > 10) { + if (debug_level(ECLAT_DEBCAT_MAIN) > 10) { dump_text(stderr, line, column, ptr, realsize); } @@ -216,5 +179,4 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data) return realsize; } - #include "cmdline.h" @@ -238,4 +200,5 @@ main(int argc, char **argv) set_program_name(argv[0]); + debug_init(); config_init(); parse_options(argc, argv, &index); @@ -243,7 +206,7 @@ main(int argc, char **argv) argc -= index; argv += index; - - grecs_gram_trace(debug_level[ECLAT_DEBCAT_CFGRAM]); - grecs_lex_trace(debug_level[ECLAT_DEBCAT_CFLEX]); + + grecs_gram_trace(debug_level(ECLAT_DEBCAT_CFGRAM)); + grecs_lex_trace(debug_level(ECLAT_DEBCAT_CFLEX)); if (preprocess_only) @@ -293,7 +256,7 @@ main(int argc, char **argv) die(EX_UNAVAILABLE, "curl_easy_init failed"); - if (debug_level[ECLAT_DEBCAT_CURL]) { + if (debug_level(ECLAT_DEBCAT_CURL)) { curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); - if (debug_level[ECLAT_DEBCAT_CURL] > 1) + if (debug_level(ECLAT_DEBCAT_CURL) > 1) curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, eclat_trace_fun); |