summaryrefslogtreecommitdiffabout
path: root/src/eclat.c
Unidiff
Diffstat (limited to 'src/eclat.c') (more/less context) (ignore whitespace changes)
-rw-r--r--src/eclat.c77
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
19char *conffile = SYSCONFDIR "/eclat.conf" ; 19char *conffile = SYSCONFDIR "/eclat.conf" ;
20int lint_mode; 20int lint_mode;
21int debug_level[ECLAT_DEBCAT_MAX];
22int dry_run_mode; 21int dry_run_mode;
23int preprocess_only = 0; 22int preprocess_only = 0;
24 23
@@ -30,59 +29,23 @@ char *region_name;
30enum eclat_command eclat_command; 29enum eclat_command eclat_command;
31 30
32 31
33struct debug_trans { 32static 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
39static struct debug_trans debug_trans[] = { 40static void
40#define S(s) #s, sizeof(#s)-1 41debug_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
49static int
50parse_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
87static void 50static void
88dump(const char *text, FILE *stream, unsigned char *ptr, size_t size) 51dump(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 }

Return to:

Send suggestions and report system problems to the System administrator.