aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-09-22 16:15:48 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-09-22 16:30:07 +0300
commit0666fc3caae8e2db660d781e43bee2258bf06a00 (patch)
tree97380903872520efa3b2bf659465e63f2cf51a2a
parent7f3dd0599ac3fb3a69c512b0ecfd043c67ca94ee (diff)
downloadeclat-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.
-rw-r--r--NEWS4
-rw-r--r--configure.ac2
-rw-r--r--lib/.gitignore4
-rw-r--r--lib/Makefile.am15
-rw-r--r--lib/diag.c (renamed from src/diag.c)77
-rw-r--r--lib/forlan.c258
-rw-r--r--lib/forlan.h123
-rw-r--r--lib/forlangrm.y237
-rw-r--r--lib/forlanlex.l137
-rw-r--r--lib/libeclat.h33
-rw-r--r--src/Makefile.am1
-rw-r--r--src/cmdline.opt10
-rw-r--r--src/config.c2
-rw-r--r--src/eclat.c77
-rw-r--r--src/eclat.h19
-rw-r--r--src/error.c64
-rw-r--r--tests/.gitignore1
-rw-r--r--tests/Makefile.am2
-rw-r--r--tests/forlan01.at77
-rw-r--r--tests/testsuite.at4
-rw-r--r--tests/tforlan.c100
21 files changed, 1092 insertions, 155 deletions
diff --git a/NEWS b/NEWS
index a38e2aa..ebe5900 100644
--- a/NEWS
+++ b/NEWS
@@ -1,2 +1,2 @@
1Eclat NEWS -- history of user-visible changes. 2012-09-19 1Eclat NEWS -- history of user-visible changes. 2012-09-22
2Copyright (C) 2012 Sergey Poznyakoff 2Copyright (C) 2012 Sergey Poznyakoff
@@ -7,3 +7,3 @@ Please send Eclat bug reports to <gray+eclat@gnu.org.ua>
7 7
8No news is good news. 8Version 0.1 - No news is good news.
9 9
diff --git a/configure.ac b/configure.ac
index fd22d37..b0aba5e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -29,2 +29,4 @@ AM_SILENT_RULES([yes])
29AC_PROG_CC 29AC_PROG_CC
30AC_PROG_LEX
31AC_PROG_YACC
30AC_PROG_RANLIB 32AC_PROG_RANLIB
diff --git a/lib/.gitignore b/lib/.gitignore
new file mode 100644
index 0000000..e0d9b22
--- /dev/null
+++ b/lib/.gitignore
@@ -0,0 +1,4 @@
1forlangrm.c
2forlangrm.h
3forlangrm.output
4forlanlex.c
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 2c1d3a8..50b28a5 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -20,2 +20,8 @@ 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\
@@ -35 +41,10 @@ AM_LDFLAGS = $(CURL_LIBS)
35INCLUDES = -I$(top_srcdir)/grecs/src/ $(CURL_CFLAGS) 41INCLUDES = -I$(top_srcdir)/grecs/src/ $(CURL_CFLAGS)
42
43forlanlex.c: forlangrm.h
44forlangrm.c forlangrm.h: forlangrm.y
45
46AM_YFLAGS=-tdv
47AM_LFLAGS=-dvp
48
49
50
diff --git a/src/diag.c b/lib/diag.c
index 30ffa34..d061e9e 100644
--- a/src/diag.c
+++ b/lib/diag.c
@@ -16,8 +16,23 @@
16 16
17#include "eclat.h" 17#include "libeclat.h"
18#include <string.h>
19#include <sysexits.h>
18 20
19const char *program_name; 21const char *program_name;
22struct debug_category debug_category[LIBECLAT_DBG_MAX];
23int debug_avail;
20 24
21void 25void
22vdiag(grecs_locus_t const *locus, const char *qual, const char *fmt, va_list ap) 26set_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
35void
36vdiag(grecs_locus_t const *locus, const char *qual, const char *fmt,
37 va_list ap)
23{ 38{
@@ -108 +123,59 @@ debug_printf(const char *fmt, ...)
108} 123}
124
125static struct debug_category *
126find_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
136int
137parse_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
172int
173debug_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/>. */
16
17#include "libeclat.h"
18#include "grecs.h"
19#include "forlan.h"
20
21int forlan_dbg = -1;
22
23void
24forlan_init()
25{
26 forlan_dbg = debug_register("forlan");
27}
28
29union forlan_node *
30forlan_node_create(enum forlan_type type)
31{
32 union forlan_node *p = grecs_zalloc(sizeof(*p));
33 p->type = type;
34 return p;
35}
36
37static void f_dump_node(FILE *fp, union forlan_node *p, int *num, int lev);
38
39
40static void
41free_type_null(union forlan_node *p)
42{
43 warn("freeing undefined forlan_node");
44}
45
46void
47dump_null(FILE *fp, union forlan_node *p, int *num, int lev)
48{
49 fprintf(fp, "[undefined node]\n");
50}
51
52static void
53free_type_comp(union forlan_node *p)
54{
55 forlan_node_free(p->comp.node);
56}
57void
58dump_comp(FILE *fp, union forlan_node *p, int *num, int lev)
59{
60 fprintf(fp, "COMP");
61 if (p->comp.abs)
62 fprintf(fp, " ABS");
63 fputc('\n', fp);
64 forlan_dump_node(fp, p->comp.node, num, lev + 1);
65}
66
67static void
68free_type_test(union forlan_node *p)
69{
70 free(p->test.comp);
71 free(p->test.value);
72}
73void
74dump_test(FILE *fp, union forlan_node *p, int *num, int lev)
75{
76 fprintf(fp, "TEST: %s[%s]\n", p->test.comp, p->test.value);
77}
78
79static void
80free_type_func(union forlan_node *p)
81{