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 /lib | |
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 'lib')
-rw-r--r-- | lib/.gitignore | 4 | ||||
-rw-r--r-- | lib/Makefile.am | 15 | ||||
-rw-r--r-- | lib/diag.c | 181 | ||||
-rw-r--r-- | lib/forlan.c | 258 | ||||
-rw-r--r-- | lib/forlan.h | 123 | ||||
-rw-r--r-- | lib/forlangrm.y | 237 | ||||
-rw-r--r-- | lib/forlanlex.l | 137 | ||||
-rw-r--r-- | lib/libeclat.h | 33 |
8 files changed, 988 insertions, 0 deletions
diff --git a/lib/.gitignore b/lib/.gitignore new file mode 100644 index 0000000..e0d9b22 --- /dev/null +++ b/lib/.gitignore | |||
@@ -0,0 +1,4 @@ | |||
1 | forlangrm.c | ||
2 | forlangrm.h | ||
3 | forlangrm.output | ||
4 | forlanlex.c | ||
diff --git a/lib/Makefile.am b/lib/Makefile.am index 2c1d3a8..50b28a5 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am | |||
@@ -18,6 +18,12 @@ noinst_LIBRARIES=libeclat.a | |||
18 | 18 | ||
19 | libeclat_a_SOURCES=\ | 19 | libeclat_a_SOURCES=\ |
20 | base64.c\ | 20 | base64.c\ |
21 | diag.c\ | ||
22 | forlan.c\ | ||
23 | forlan.h\ | ||
24 | forlangrm.h\ | ||
25 | forlangrm.y\ | ||
26 | forlanlex.l\ | ||
21 | hmac_sha1.c\ | 27 | hmac_sha1.c\ |
22 | libeclat.h\ | 28 | libeclat.h\ |
23 | q2url.c\ | 29 | q2url.c\ |
@@ -33,3 +39,12 @@ libeclat_a_SOURCES=\ | |||
33 | 39 | ||
34 | AM_LDFLAGS = $(CURL_LIBS) | 40 | AM_LDFLAGS = $(CURL_LIBS) |
35 | INCLUDES = -I$(top_srcdir)/grecs/src/ $(CURL_CFLAGS) | 41 | INCLUDES = -I$(top_srcdir)/grecs/src/ $(CURL_CFLAGS) |
42 | |||
43 | forlanlex.c: forlangrm.h | ||
44 | forlangrm.c forlangrm.h: forlangrm.y | ||
45 | |||
46 | AM_YFLAGS=-tdv | ||
47 | AM_LFLAGS=-dvp | ||
48 | |||
49 | |||
50 | |||
diff --git a/lib/diag.c b/lib/diag.c new file mode 100644 index 0000000..d061e9e --- /dev/null +++ b/lib/diag.c | |||
@@ -0,0 +1,181 @@ | |||
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 "libeclat.h" | ||
18 | #include <string.h> | ||
19 | #include <sysexits.h> | ||
20 | |||
21 | const char *program_name; | ||
22 | struct debug_category debug_category[LIBECLAT_DBG_MAX]; | ||
23 | int debug_avail; | ||
24 | |||
25 | void | ||
26 | set_program_name(const char *arg) | ||
27 | { | ||
28 | program_name = strrchr(arg, '/'); | ||
29 | if (!program_name) | ||
30 | program_name = arg; | ||
31 | else | ||
32 | program_name++; | ||
33 | } | ||
34 | |||
35 | void | ||
36 | vdiag(grecs_locus_t const *locus, const char *qual, const char *fmt, | ||
37 | va_list ap) | ||
38 | { | ||
39 | if (program_name) | ||
40 | fprintf(stderr, "%s: ", program_name); | ||
41 | |||
42 | if (locus) { | ||
43 | size_t size = 0; | ||
44 | |||
45 | if (locus->beg.col == 0) | ||
46 | fprintf(stderr, "%s:%u", | ||
47 | locus->beg.file, | ||
48 | locus->beg.line); | ||
49 | else if (strcmp(locus->beg.file, locus->end.file)) | ||
50 | fprintf(stderr, "%s:%u.%u-%s:%u.%u", | ||
51 | locus->beg.file, | ||
52 | locus->beg.line, locus->beg.col, | ||
53 | locus->end.file, | ||
54 | locus->end.line, locus->end.col); | ||
55 | else if (locus->beg.line != locus->end.line) | ||
56 | fprintf(stderr, "%s:%u.%u-%u.%u", | ||
57 | locus->beg.file, | ||
58 | locus->beg.line, locus->beg.col, | ||
59 | locus->end.line, locus->end.col); | ||
60 | else | ||
61 | fprintf(stderr, "%s:%u.%u-%u", | ||
62 | locus->beg.file, | ||
63 | locus->beg.line, locus->beg.col, | ||
64 | locus->end.col); | ||
65 | fprintf(stderr, ": "); | ||
66 | } | ||
67 | |||
68 | if (qual) | ||
69 | fprintf(stderr, "%s: ", qual); | ||
70 | vfprintf(stderr, fmt, ap); | ||
71 | fputc('\n', stderr); | ||
72 | } | ||
73 | |||
74 | void | ||
75 | diag(grecs_locus_t const *locus, const char *qual, const char *fmt, ...) | ||
76 | { | ||
77 | va_list ap; | ||
78 | |||
79 | va_start(ap, fmt); | ||
80 | vdiag(locus, qual, fmt, ap); | ||
81 | va_end(ap); | ||
82 | } | ||
83 | |||
84 | void | ||
85 | die(int status, const char *fmt, ...) | ||
86 | { | ||
87 | va_list ap; | ||
88 | |||
89 | va_start(ap, fmt); | ||
90 | vdiag(NULL, NULL, fmt, ap); | ||
91 | va_end(ap); | ||
92 | exit(status); | ||
93 | } | ||
94 | |||
95 | void | ||
96 | err(const char *fmt, ...) | ||
97 | { | ||
98 | va_list ap; | ||
99 | |||
100 | va_start(ap, fmt); | ||
101 | vdiag(NULL, NULL, fmt, ap); | ||
102 | va_end(ap); | ||
103 | } | ||
104 | |||
105 | void | ||
106 | warn(const char *fmt, ...) | ||
107 | { | ||
108 | va_list ap; | ||
109 | |||
110 | va_start(ap, fmt); | ||
111 | vdiag(NULL, "warning", fmt, ap); | ||
112 | va_end(ap); | ||
113 | } | ||
114 | |||
115 | void | ||
116 | debug_printf(const char *fmt, ...) | ||
117 | { | ||
118 | va_list ap; | ||
119 | |||
120 | va_start(ap, fmt); | ||
121 | vdiag(NULL, "debug", fmt, ap); | ||
122 | va_end(ap); | ||
123 | } | ||
124 | |||
125 | static struct debug_category * | ||
126 | find_category(const char *arg, size_t len) | ||
127 | { | ||
128 | struct debug_category *dp; | ||
129 | |||
130 | for (dp = debug_category; dp < debug_category + debug_avail; dp++) | ||
131 | if (dp->length == len && memcmp(dp->name, arg, len) == 0) | ||
132 | return dp; | ||
133 | return NULL; | ||
134 | } | ||
135 | |||
136 | int | ||
137 | parse_debug_level(const char *arg) | ||
138 | { | ||
139 | unsigned long lev; | ||
140 | char *p; | ||
141 | size_t len = strcspn(arg, "."); | ||
142 | struct debug_category *dp; | ||
143 | |||
144 | if (arg[len] == 0) { | ||
145 | lev = strtoul(arg, &p, 10); | ||
146 | if (*p) | ||
147 | return -1; | ||
148 | for (dp = debug_category; dp < debug_category + debug_avail; | ||
149 | dp++) | ||
150 | dp->level = lev; | ||
151 | return 0; | ||
152 | } | ||
153 | |||
154 | dp = find_category(arg, len); | ||
155 | if (!dp) | ||
156 | return -1; | ||
157 | |||
158 | p = (char*) arg + len; | ||
159 | if (*p == 0) | ||
160 | lev = 100; | ||
161 | else if (*p != '.') | ||
162 | return -1; | ||
163 | else { | ||
164 | lev = strtoul(p + 1, &p, 10); | ||
165 | if (*p) | ||
166 | return -1; | ||
167 | } | ||
168 | dp->level = lev; | ||
169 | return 0; | ||
170 | } | ||
171 | |||
172 | int | ||
173 | debug_register(char *name) | ||
174 | { | ||
175 | if (debug_avail >= LIBECLAT_DBG_MAX) | ||
176 | die(EX_SOFTWARE, "no more debug slots available"); | ||
177 | debug_category[debug_avail].name = grecs_strdup(name); | ||
178 | debug_category[debug_avail].length = strlen(name); | ||
179 | debug_category[debug_avail].level = 0; | ||
180 | return debug_avail++; | ||
181 | } | ||
diff --git a/lib/forlan.c b/lib/forlan.c new file mode 100644 index 0000000..0854d08 --- /dev/null +++ b/lib/forlan.c | |||
@@ -0,0 +1,258 @@ | |||
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/>. */ | ||