aboutsummaryrefslogtreecommitdiff
path: root/src/eclat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/eclat.c')
-rw-r--r--src/eclat.c73
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
@@ -18,7 +18,6 @@
char *conffile = SYSCONFDIR "/eclat.conf" ;
int lint_mode;
-int debug_level[ECLAT_DEBCAT_MAX];
int dry_run_mode;
int preprocess_only = 0;
@@ -30,59 +29,23 @@ 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)
@@ -90,7 +53,7 @@ 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 */
@@ -199,7 +162,7 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data)
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);
@@ -216,7 +179,6 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data)
return realsize;
}
-
#include "cmdline.h"
eclat_command_handler_t handler_tab[] = {
@@ -237,14 +199,15 @@ main(int argc, char **argv)
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) ?
@@ -292,9 +255,9 @@ main(int argc, char **argv)
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);
}

Return to:

Send suggestions and report system problems to the System administrator.