diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-09-22 16:15:48 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-09-22 16:30:07 +0300 |
commit | 0666fc3caae8e2db660d781e43bee2258bf06a00 (patch) | |
tree | 97380903872520efa3b2bf659465e63f2cf51a2a /src/eclat.c | |
parent | 7f3dd0599ac3fb3a69c512b0ecfd043c67ca94ee (diff) | |
download | eclat-0666fc3caae8e2db660d781e43bee2258bf06a00.tar.gz eclat-0666fc3caae8e2db660d781e43bee2258bf06a00.tar.bz2 |
Introduce output formatting language
* configure.ac: Check for lex and yacc.
* lib/diag.c: New file (moved from ../src with edits)
* lib/forlan.c: New file.
* lib/forlan.h: New file.
* lib/forlangrm.y: New file.
* lib/forlanlex.l: New file.
* lib/.gitignore: Add new files.
* lib/Makefile.am: Add new file.
* lib/libeclat.h: Add diagnostics-related stuff.
* src/Makefile.am (eclat_SOURCES): Remove diag.c
* src/cmdline.opt (set_program_name): Move to ../lib/diag.c
* src/diag.c: Remove (see above).
* src/config.c: Reflect changes to the diagnostics subsystem.
* src/eclat.c: Likewise.
* src/eclat.h: Remove diagnostics-related stuff.
It lives in libeclat.h from now on.
* src/error.c: Remove.
* tests/forlan01.at: New testcase.
* tests/testsuite.at: Include forlan01.at
* tests/tforlan.c: New file.
* tests/.gitignore: Add new files.
* tests/Makefile.am: Add new files.
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 @@ -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); } |