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 | 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 | |||
@@ -18,7 +18,6 @@ | |||
18 | 18 | ||
19 | char *conffile = SYSCONFDIR "/eclat.conf" ; | 19 | char *conffile = SYSCONFDIR "/eclat.conf" ; |
20 | int lint_mode; | 20 | int lint_mode; |
21 | int debug_level[ECLAT_DEBCAT_MAX]; | ||
22 | int dry_run_mode; | 21 | int dry_run_mode; |
23 | int preprocess_only = 0; | 22 | int preprocess_only = 0; |
24 | 23 | ||
@@ -30,59 +29,23 @@ char *region_name; | |||
30 | enum eclat_command eclat_command; | 29 | enum eclat_command eclat_command; |
31 | 30 | ||
32 | 31 | ||
33 | struct debug_trans { | 32 | static char *categories[] = { |
34 | const char *name; | 33 | "main", |
35 | size_t length; | 34 | "cfgram", |
36 | int cat; | 35 | "cflex", |
36 | "conf", | ||
37 | "curl", | ||
37 | }; | 38 | }; |
38 | 39 | ||
39 | static struct debug_trans debug_trans[] = { | 40 | static void |
40 | #define S(s) #s, sizeof(#s)-1 | 41 | debug_init() |
41 | { S(main), ECLAT_DEBCAT_MAIN }, | ||
42 | { S(cfgram), ECLAT_DEBCAT_CFGRAM }, | ||
43 | { S(cflex), ECLAT_DEBCAT_CFLEX }, | ||
44 | { S(conf), ECLAT_DEBCAT_CONF }, | ||
45 | { S(curl), ECLAT_DEBCAT_CURL }, | ||
46 | { NULL } | ||
47 | }; | ||
48 | |||
49 | static int | ||
50 | parse_debug_level(const char *arg) | ||
51 | { | 42 | { |
52 | unsigned long cat, lev; | 43 | int i; |
53 | char *p; | ||
54 | 44 | ||
55 | if (isascii(*arg) && isdigit(*arg)) { | 45 | for (i = 0; i < sizeof(categories)/sizeof(categories[0]); i++) |
56 | cat = strtoul(arg, &p, 10); | 46 | debug_register(categories[i]); |
57 | if (cat > ECLAT_DEBCAT_MAX) | ||
58 | return -1; | ||
59 | } else { | ||
60 | size_t len = strcspn(arg, "."); | ||
61 | struct debug_trans *dp; | ||
62 | |||
63 | for (dp = debug_trans; dp->name; dp++) | ||
64 | if (dp->length == len && | ||
65 | memcmp(dp->name, arg, len) == 0) | ||
66 | break; | ||
67 | |||
68 | if (!dp->name) | ||
69 | return -1; | ||
70 | cat = dp->cat; | ||
71 | p = (char*) arg + len; | ||
72 | } | ||
73 | |||
74 | if (*p == 0) | ||
75 | lev = 100; | ||
76 | else if (*p != '.') | ||
77 | return -1; | ||
78 | else { | ||
79 | lev = strtoul(p + 1, &p, 10); | ||
80 | if (*p) | ||
81 | return -1; | ||
82 | } | ||
83 | debug_level[cat] = lev; | ||
84 | return 0; | ||
85 | } | 47 | } |
48 | |||
86 | 49 | ||
87 | static void | 50 | static void |
88 | dump(const char *text, FILE *stream, unsigned char *ptr, size_t size) | 51 | 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) | |||
90 | size_t i; | 53 | size_t i; |
91 | size_t c; | 54 | size_t c; |
92 | unsigned int width = 0x10; | 55 | unsigned int width = 0x10; |
93 | int hex = debug_level[ECLAT_DEBCAT_CURL] > 2; | 56 | int hex = debug_level(ECLAT_DEBCAT_CURL) > 2; |
94 | 57 | ||
95 | if (!hex) | 58 | if (!hex) |
96 | /* without the hex output, we can fit more on screen */ | 59 | /* 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) | |||
199 | int column = XML_GetCurrentColumnNumber(parser); | 162 | int column = XML_GetCurrentColumnNumber(parser); |
200 | 163 | ||
201 | /* FIXME: Debugging level. */ | 164 | /* FIXME: Debugging level. */ |
202 | if (debug_level[ECLAT_DEBCAT_MAIN] > 10) { | 165 | if (debug_level(ECLAT_DEBCAT_MAIN) > 10) { |
203 | dump_text(stderr, line, column, ptr, realsize); | 166 | dump_text(stderr, line, column, ptr, realsize); |
204 | } | 167 | } |
205 | status = XML_Parse(parser, ptr, realsize, 0); | 168 | status = XML_Parse(parser, ptr, realsize, 0); |
@@ -215,7 +178,6 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data) | |||
215 | } | 178 | } |
216 | return realsize; | 179 | return realsize; |
217 | } | 180 | } |
218 | |||
219 | 181 | ||
220 | #include "cmdline.h" | 182 | #include "cmdline.h" |
221 | 183 | ||
@@ -237,14 +199,15 @@ main(int argc, char **argv) | |||
237 | struct grecs_node *xmltree; | 199 | struct grecs_node *xmltree; |
238 | 200 | ||
239 | set_program_name(argv[0]); | 201 | set_program_name(argv[0]); |
202 | debug_init(); | ||
240 | config_init(); | 203 | config_init(); |
241 | parse_options(argc, argv, &index); | 204 | parse_options(argc, argv, &index); |
242 | 205 | ||
243 | argc -= index; | 206 | argc -= index; |
244 | argv += index; | 207 | argv += index; |
245 | 208 | ||
246 | grecs_gram_trace(debug_level[ECLAT_DEBCAT_CFGRAM]); | 209 | grecs_gram_trace(debug_level(ECLAT_DEBCAT_CFGRAM)); |
247 | grecs_lex_trace(debug_level[ECLAT_DEBCAT_CFLEX]); | 210 | grecs_lex_trace(debug_level(ECLAT_DEBCAT_CFLEX)); |
248 | 211 | ||
249 | if (preprocess_only) | 212 | if (preprocess_only) |
250 | exit(grecs_preproc_run(conffile, grecs_preprocessor) ? | 213 | exit(grecs_preproc_run(conffile, grecs_preprocessor) ? |
@@ -292,9 +255,9 @@ main(int argc, char **argv) | |||
292 | if (!curl) | 255 | if (!curl) |
293 | die(EX_UNAVAILABLE, "curl_easy_init failed"); | 256 | die(EX_UNAVAILABLE, "curl_easy_init failed"); |
294 | 257 | ||
295 | if (debug_level[ECLAT_DEBCAT_CURL]) { | 258 | if (debug_level(ECLAT_DEBCAT_CURL)) { |
296 | curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); | 259 | curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); |
297 | if (debug_level[ECLAT_DEBCAT_CURL] > 1) | 260 | if (debug_level(ECLAT_DEBCAT_CURL) > 1) |
298 | curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, | 261 | curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, |
299 | eclat_trace_fun); | 262 | eclat_trace_fun); |
300 | } | 263 | } |