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 | |
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')
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/cmdline.opt | 10 | ||||
-rw-r--r-- | src/config.c | 2 | ||||
-rw-r--r-- | src/diag.c | 108 | ||||
-rw-r--r-- | src/eclat.c | 73 | ||||
-rw-r--r-- | src/eclat.h | 19 | ||||
-rw-r--r-- | src/error.c | 64 |
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 | |||
208 | OPTIONS_END | 208 | OPTIONS_END |
209 | 209 | ||
210 | void | 210 | void |
211 | set_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 | |||
220 | void | ||
221 | parse_options(int argc, char *argv[], int *index) | 211 | parse_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 | |||
19 | const char *program_name; | ||
20 | |||
21 | void | ||
22 | vdiag(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 | |||
59 | void | ||
60 | diag(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 | |||
69 | void | ||
70 | die(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 | |||
80 | void | ||
81 | err(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 | |||
90 | void | ||
91 | warn(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 | |||
100 | void | ||
101 | debug_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 | ||
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 | |||
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 |