aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/cmdline.opt10
-rw-r--r--src/config.c2
-rw-r--r--src/diag.c108
-rw-r--r--src/eclat.c73
-rw-r--r--src/eclat.h19
-rw-r--r--src/error.c64
7 files changed, 20 insertions, 257 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index b5f7912..bda0584 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -21,7 +21,6 @@ eclat_SOURCES=\
21 cmdline.h\ 21 cmdline.h\
22 config.c\ 22 config.c\
23 descrtags.c\ 23 descrtags.c\
24 diag.c\
25 eclat.c\ 24 eclat.c\
26 eclat.h\ 25 eclat.h\
27 startinst.c 26 startinst.c
diff --git a/src/cmdline.opt b/src/cmdline.opt
index 82e0e95..1f8d56d 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -208,16 +208,6 @@ END
208OPTIONS_END 208OPTIONS_END
209 209
210void 210void
211set_program_name(const char *arg)
212{
213 program_name = strrchr(arg, '/');
214 if (!program_name)
215 program_name = arg;
216 else
217 program_name++;
218}
219
220void
221parse_options(int argc, char *argv[], int *index) 211parse_options(int argc, char *argv[], int *index)
222{ 212{
223 GETOPT(argc, argv, *index, exit(EX_USAGE)) 213 GETOPT(argc, argv, *index, exit(EX_USAGE))
diff --git a/src/config.c b/src/config.c
index c40d307..b718486 100644
--- a/src/config.c
+++ b/src/config.c
@@ -149,7 +149,7 @@ config_finish(struct grecs_node *tree)
149 struct grecs_node *node; 149 struct grecs_node *node;
150 150
151 grecs_tree_reduce(tree, eclat_kw, GRECS_AGGR); 151 grecs_tree_reduce(tree, eclat_kw, GRECS_AGGR);
152 if (debug_level[ECLAT_DEBCAT_CONF]) { 152 if (debug_level(ECLAT_DEBCAT_CONF)) {
153 grecs_print_node(tree, GRECS_NODE_FLAG_DEFAULT, stderr); 153 grecs_print_node(tree, GRECS_NODE_FLAG_DEFAULT, stderr);
154 fputc('\n', stdout); 154 fputc('\n', stdout);
155 } 155 }
diff --git a/src/diag.c b/src/diag.c
deleted file mode 100644
index 30ffa34..0000000
--- a/src/diag.c
+++ /dev/null
@@ -1,108 +0,0 @@
1/* This file is part of Eclat.
2 Copyright (C) 2012 Sergey Poznyakoff.
3
4 Eclat is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 Eclat is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
16
17#include "eclat.h"
18
19const char *program_name;
20
21void
22vdiag(grecs_locus_t const *locus, const char *qual, const char *fmt, va_list ap)
23{
24 if (program_name)
25 fprintf(stderr, "%s: ", program_name);
26
27 if (locus) {
28 size_t size = 0;
29
30 if (locus->beg.col == 0)
31 fprintf(stderr, "%s:%u",
32 locus->beg.file,
33 locus->beg.line);
34 else if (strcmp(locus->beg.file, locus->end.file))
35 fprintf(stderr, "%s:%u.%u-%s:%u.%u",
36 locus->beg.file,
37 locus->beg.line, locus->beg.col,
38 locus->end.file,
39 locus->end.line, locus->end.col);
40 else if (locus->beg.line != locus->end.line)
41 fprintf(stderr, "%s:%u.%u-%u.%u",
42 locus->beg.file,
43 locus->beg.line, locus->beg.col,
44 locus->end.line, locus->end.col);
45 else
46 fprintf(stderr, "%s:%u.%u-%u",
47 locus->beg.file,
48 locus->beg.line, locus->beg.col,
49 locus->end.col);
50 fprintf(stderr, ": ");
51 }
52
53 if (qual)
54 fprintf(stderr, "%s: ", qual);
55 vfprintf(stderr, fmt, ap);
56 fputc('\n', stderr);
57}
58
59void
60diag(grecs_locus_t const *locus, const char *qual, const char *fmt, ...)
61{
62 va_list ap;
63
64 va_start(ap, fmt);
65 vdiag(locus, qual, fmt, ap);
66 va_end(ap);
67}
68
69void
70die(int status, const char *fmt, ...)
71{
72 va_list ap;
73
74 va_start(ap, fmt);
75 vdiag(NULL, NULL, fmt, ap);
76 va_end(ap);
77 exit(status);
78}
79
80void
81err(const char *fmt, ...)
82{
83 va_list ap;
84
85 va_start(ap, fmt);
86 vdiag(NULL, NULL, fmt, ap);
87 va_end(ap);
88}
89
90void
91warn(const char *fmt, ...)
92{
93 va_list ap;
94
95 va_start(ap, fmt);
96 vdiag(NULL, "warning", fmt, ap);
97 va_end(ap);
98}
99
100void
101debug_printf(const char *fmt, ...)
102{
103 va_list ap;
104
105 va_start(ap, fmt);
106 vdiag(NULL, "debug", fmt, ap);
107 va_end(ap);
108}
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
55 if (isascii(*arg) && isdigit(*arg)) {
56 cat = strtoul(arg, &p, 10);
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 44
68 if (!dp->name) 45 for (i = 0; i < sizeof(categories)/sizeof(categories[0]); i++)
69 return -1; 46 debug_register(categories[i]);
70 cat = dp->cat;
71 p = (char*) arg + len;
72} 47}
73 48
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}
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);
@@ -216,7 +179,6 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data)
216 return realsize; 179 return realsize;
217} 180}
218 181
219
220#include "cmdline.h" 182#include "cmdline.h"
221 183
222eclat_command_handler_t handler_tab[] = { 184eclat_command_handler_t handler_tab[] = {
@@ -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 }
diff --git a/src/eclat.h b/src/eclat.h
index b0d46ac..e588b57 100644
--- a/src/eclat.h
+++ b/src/eclat.h
@@ -33,10 +33,7 @@
33#define ECLAT_DEBCAT_CFLEX 2 33#define ECLAT_DEBCAT_CFLEX 2
34#define ECLAT_DEBCAT_CONF 3 34#define ECLAT_DEBCAT_CONF 3
35#define ECLAT_DEBCAT_CURL 4 35#define ECLAT_DEBCAT_CURL 4
36#define ECLAT_DEBCAT_MAX 5 36#define ECLAT_DEBCAT_FORLAN 5
37
38extern const char *program_name;
39extern int debug_level[];
40 37
41extern char *endpoint; 38extern char *endpoint;
42extern int use_ssl; 39extern int use_ssl;
@@ -46,20 +43,6 @@ extern char *access_file_name;
46extern char *access_key; 43extern char *access_key;
47extern char *secret_key; 44extern char *secret_key;
48 45
49#define debug(cat, lev, s) \
50 do { \
51 if (debug_level[cat] >= (lev)) \
52 debug_printf s; \
53 } while(0)
54
55void die(int status, const char *fmt, ...);
56void vdiag(grecs_locus_t const *locus, const char *qual, const char *fmt,
57 va_list ap);
58void diag(grecs_locus_t const *locus, const char *qual, const char *fmt, ...);
59void err(const char *fmt, ...);
60void warn(const char *fmt, ...);
61void debug_printf(const char *fmt, ...);
62
63typedef int (*config_finish_hook_t) (void*); 46typedef int (*config_finish_hook_t) (void*);
64 47
65void add_config_finish_hook(config_finish_hook_t fun, void *data); 48void add_config_finish_hook(config_finish_hook_t fun, void *data);
diff --git a/src/error.c b/src/error.c
deleted file mode 100644
index 6c86d34..0000000
--- a/src/error.c
+++ /dev/null
@@ -1,64 +0,0 @@
1/* This file is part of Eclat.
2 Copyright (C) 2012 Sergey Poznyakoff.
3
4 Eclat is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 Eclat is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
16
17#include "eclat.h"
18#include <stdargs.h>
19#include <stdio.h>
20
21char *program_name;
22
23void
24diag(const char *qual, const char *fmt, va_list ap)
25{
26 if (program_name)
27 fprintf(stderr, "%s: ", program_name);
28 if (qual)
29 fprintf(stderr, "%s: ", qual);
30 va_start(ap, fmt);
31 vfprintf(stderr, ftm, ap);
32 va_end(ap);
33 fputc('\n', stderr);
34}
35
36void
37err(const char *fmt, ...)
38{
39 va_list ap;
40
41 va_start(ap, fmt);
42 diag(NULL, ftm, ap);
43 va_end(ap);
44}
45
46void
47warn(const char *fmt, ...)
48{
49 va_list ap;
50
51 va_start(ap, fmt);
52 diag("warning", ftm, ap);
53 va_end(ap);
54}
55
56void
57debug_printf(const char *fmt, ...)
58{
59 va_list ap;
60
61 va_start(ap, fmt);
62 diag("debug", ftm, ap);
63 va_end(ap);
64}

Return to:

Send suggestions and report system problems to the System administrator.