diff options
Diffstat (limited to 'src/eclat.c')
-rw-r--r-- | src/eclat.c | 73 |
1 files changed, 18 insertions, 55 deletions
diff --git a/src/eclat.c b/src/eclat.c index 3703376..86b4627 100644 --- a/src/eclat.c +++ b/src/eclat.c @@ -15,85 +15,48 @@ along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ #include "eclat.h" char *conffile = SYSCONFDIR "/eclat.conf" ; int lint_mode; -int debug_level[ECLAT_DEBCAT_MAX]; int dry_run_mode; int preprocess_only = 0; char *endpoint = "ec2.amazonaws.com"; int use_ssl; char *access_key; char *secret_key; char *region_name; 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; - - 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; + int i; - if (!dp->name) - return -1; - cat = dp->cat; - p = (char*) arg + len; + for (i = 0; i < sizeof(categories)/sizeof(categories[0]); i++) + debug_register(categories[i]); } - 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; -} static void dump(const char *text, FILE *stream, unsigned char *ptr, size_t size) { size_t i; 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) /* without the hex output, we can fit more on screen */ width = 0x40; fprintf(stream, "%s, %zd bytes (0x%zx)\n", text, size, size); @@ -196,13 +159,13 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data) XML_Parser parser = data; enum XML_Status status; int line = XML_GetCurrentLineNumber(parser); int column = XML_GetCurrentColumnNumber(parser); /* FIXME: Debugging level. */ - if (debug_level[ECLAT_DEBCAT_MAIN] > 10) { + if (debug_level(ECLAT_DEBCAT_MAIN) > 10) { dump_text(stderr, line, column, ptr, realsize); } status = XML_Parse(parser, ptr, realsize, 0); if (status == XML_STATUS_ERROR) { enum XML_Error error = XML_GetErrorCode(parser); @@ -213,13 +176,12 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data) die(EX_SOFTWARE, "XML parse error at %d:%d: %s", line, column, XML_ErrorString(error)); } return realsize; } - #include "cmdline.h" eclat_command_handler_t handler_tab[] = { NULL, eclat_start_instance, eclat_stop_instance, @@ -234,20 +196,21 @@ main(int argc, char **argv) CURL *curl; XML_Parser parser; eclat_partial_tree_t part; struct grecs_node *xmltree; set_program_name(argv[0]); + debug_init(); config_init(); parse_options(argc, argv, &index); 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) exit(grecs_preproc_run(conffile, grecs_preprocessor) ? EX_CONFIG : 0); if (access(conffile, R_OK) == 0) { @@ -289,15 +252,15 @@ main(int argc, char **argv) die(EX_USAGE, "no command given"); curl = curl_easy_init(); if (!curl) 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); } /* Create XML parser */ |