diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/cmdline.opt | 10 | ||||
-rw-r--r-- | src/config.c | 2 | ||||
-rw-r--r-- | src/diag.c | 108 | ||||
-rw-r--r-- | src/eclat.c | 73 | ||||
-rw-r--r-- | src/eclat.h | 19 | ||||
-rw-r--r-- | src/error.c | 64 |
7 files changed, 20 insertions, 257 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index b5f7912..bda0584 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -18,13 +18,12 @@ bin_PROGRAMS=eclat eclat_SOURCES=\ accfile.c\ cmdline.h\ config.c\ descrtags.c\ - diag.c\ eclat.c\ eclat.h\ startinst.c AM_LDFLAGS = $(CURL_LIBS) LDADD=../lib/libeclat.a @LIBOBJS@ ../grecs/src/libgrecs.a diff --git a/src/cmdline.opt b/src/cmdline.opt index 82e0e95..1f8d56d 100644 --- a/src/cmdline.opt +++ b/src/cmdline.opt @@ -205,22 +205,12 @@ BEGIN exit(0); END OPTIONS_END void -set_program_name(const char *arg) -{ - program_name = strrchr(arg, '/'); - if (!program_name) - program_name = arg; - else - program_name++; -} - -void parse_options(int argc, char *argv[], int *index) { GETOPT(argc, argv, *index, exit(EX_USAGE)) if (pp_cmd_buffer && grecs_preprocessor) { char *cmd = grecs_malloc(strlen(grecs_preprocessor) + diff --git a/src/config.c b/src/config.c index c40d307..b718486 100644 --- a/src/config.c +++ b/src/config.c @@ -146,13 +146,13 @@ config_init() void config_finish(struct grecs_node *tree) { struct grecs_node *node; grecs_tree_reduce(tree, eclat_kw, GRECS_AGGR); - if (debug_level[ECLAT_DEBCAT_CONF]) { + if (debug_level(ECLAT_DEBCAT_CONF)) { grecs_print_node(tree, GRECS_NODE_FLAG_DEFAULT, stderr); fputc('\n', stdout); } if (grecs_tree_process(tree, eclat_kw)) exit(EX_CONFIG); if (grecs_error_count || run_config_finish_hooks()) diff --git a/src/diag.c b/src/diag.c deleted file mode 100644 index 30ffa34..0000000 --- a/src/diag.c +++ /dev/null @@ -1,108 +0,0 @@ -/* This file is part of Eclat. - Copyright (C) 2012 Sergey Poznyakoff. - - Eclat is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - Eclat is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ - -#include "eclat.h" - -const char *program_name; - -void -vdiag(grecs_locus_t const *locus, const char *qual, const char *fmt, va_list ap) -{ - if (program_name) - fprintf(stderr, "%s: ", program_name); - - if (locus) { - size_t size = 0; - - if (locus->beg.col == 0) - fprintf(stderr, "%s:%u", - locus->beg.file, - locus->beg.line); - else if (strcmp(locus->beg.file, locus->end.file)) - fprintf(stderr, "%s:%u.%u-%s:%u.%u", - locus->beg.file, - locus->beg.line, locus->beg.col, - locus->end.file, - locus->end.line, locus->end.col); - else if (locus->beg.line != locus->end.line) - fprintf(stderr, "%s:%u.%u-%u.%u", - locus->beg.file, - locus->beg.line, locus->beg.col, - locus->end.line, locus->end.col); - else - fprintf(stderr, "%s:%u.%u-%u", - locus->beg.file, - locus->beg.line, locus->beg.col, - locus->end.col); - fprintf(stderr, ": "); - } - - if (qual) - fprintf(stderr, "%s: ", qual); - vfprintf(stderr, fmt, ap); - fputc('\n', stderr); -} - -void -diag(grecs_locus_t const *locus, const char *qual, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vdiag(locus, qual, fmt, ap); - va_end(ap); -} - -void -die(int status, const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vdiag(NULL, NULL, fmt, ap); - va_end(ap); - exit(status); -} - -void -err(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vdiag(NULL, NULL, fmt, ap); - va_end(ap); -} - -void -warn(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vdiag(NULL, "warning", fmt, ap); - va_end(ap); -} - -void -debug_printf(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - vdiag(NULL, "debug", fmt, ap); - va_end(ap); -} 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 */ diff --git a/src/eclat.h b/src/eclat.h index b0d46ac..e588b57 100644 --- a/src/eclat.h +++ b/src/eclat.h @@ -30,39 +30,22 @@ #define ECLAT_DEBCAT_MAIN 0 #define ECLAT_DEBCAT_CFGRAM 1 #define ECLAT_DEBCAT_CFLEX 2 #define ECLAT_DEBCAT_CONF 3 #define ECLAT_DEBCAT_CURL 4 -#define ECLAT_DEBCAT_MAX 5 - -extern const char *program_name; -extern int debug_level[]; +#define ECLAT_DEBCAT_FORLAN 5 extern char *endpoint; extern int use_ssl; extern int dry_run_mode; extern char *region_name; extern char *access_file_name; extern char *access_key; extern char *secret_key; -#define debug(cat, lev, s) \ - do { \ - if (debug_level[cat] >= (lev)) \ - debug_printf s; \ - } while(0) - -void die(int status, const char *fmt, ...); -void vdiag(grecs_locus_t const *locus, const char *qual, const char *fmt, - va_list ap); -void diag(grecs_locus_t const *locus, const char *qual, const char *fmt, ...); -void err(const char *fmt, ...); -void warn(const char *fmt, ...); -void debug_printf(const char *fmt, ...); - typedef int (*config_finish_hook_t) (void*); void add_config_finish_hook(config_finish_hook_t fun, void *data); void config_help(void); void config_init(void); diff --git a/src/error.c b/src/error.c deleted file mode 100644 index 6c86d34..0000000 --- a/src/error.c +++ /dev/null @@ -1,64 +0,0 @@ -/* This file is part of Eclat. - Copyright (C) 2012 Sergey Poznyakoff. - - Eclat is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 3, or (at your option) - any later version. - - Eclat is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Eclat. If not, see <http://www.gnu.org/licenses/>. */ - -#include "eclat.h" -#include <stdargs.h> -#include <stdio.h> - -char *program_name; - -void -diag(const char *qual, const char *fmt, va_list ap) -{ - if (program_name) - fprintf(stderr, "%s: ", program_name); - if (qual) - fprintf(stderr, "%s: ", qual); - va_start(ap, fmt); - vfprintf(stderr, ftm, ap); - va_end(ap); - fputc('\n', stderr); -} - -void -err(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - diag(NULL, ftm, ap); - va_end(ap); -} - -void -warn(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - diag("warning", ftm, ap); - va_end(ap); -} - -void -debug_printf(const char *fmt, ...) -{ - va_list ap; - - va_start(ap, fmt); - diag("debug", ftm, ap); - va_end(ap); -} |