aboutsummaryrefslogtreecommitdiff
path: root/src/eclat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/eclat.c')
-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
@@ -20,3 +20,2 @@ char *conffile = SYSCONFDIR "/eclat.conf" ;
20int lint_mode; 20int lint_mode;
21int debug_level[ECLAT_DEBCAT_MAX];
22int dry_run_mode; 21int dry_run_mode;
@@ -32,55 +31,19 @@ enum eclat_command eclat_command;
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
@@ -92,3 +55,3 @@ dump(const char *text, FILE *stream, unsigned char *ptr, size_t size)
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
@@ -201,3 +164,3 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data)
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);
@@ -217,3 +180,2 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data)
217} 180}
218
219 181
@@ -239,2 +201,3 @@ main(int argc, char **argv)
239 set_program_name(argv[0]); 201 set_program_name(argv[0]);
202 debug_init();
240 config_init(); 203 config_init();
@@ -244,5 +207,5 @@ main(int argc, char **argv)
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
@@ -294,5 +257,5 @@ main(int argc, char **argv)
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,

Return to:

Send suggestions and report system problems to the System administrator.