aboutsummaryrefslogtreecommitdiff
path: root/src
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 /src
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.
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
@@ -23,3 +23,2 @@ eclat_SOURCES=\
descrtags.c\
- diag.c\
eclat.c\
diff --git a/src/cmdline.opt b/src/cmdline.opt
index 82e0e95..1f8d56d 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -210,12 +210,2 @@ OPTIONS_END
void
-set_program_name(const char *arg)
-{
- program_name = strrchr(arg, '/');
- if (!program_name)
- program_name = arg;
- else
- program_name++;
-}
-
-void
parse_options(int argc, char *argv[], int *index)
diff --git a/src/config.c b/src/config.c
index c40d307..b718486 100644
--- a/src/config.c
+++ b/src/config.c
@@ -151,3 +151,3 @@ config_finish(struct grecs_node *tree)
grecs_tree_reduce(tree, eclat_kw, GRECS_AGGR);
- if (debug_level[ECLAT_DEBCAT_CONF]) {
+ if (debug_level(ECLAT_DEBCAT_CONF)) {
grecs_print_node(tree, GRECS_NODE_FLAG_DEFAULT, stderr);
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 @@
-/* This file is part of Eclat.
- Copyright (C) 2012 Sergey Poznyakoff.
-
- Eclat is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- Eclat is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "eclat.h"
-
-const char *program_name;
-
-void
-vdiag(grecs_locus_t const *locus, const char *qual, const char *fmt, va_list ap)
-{
- if (program_name)
- fprintf(stderr, "%s: ", program_name);
-
- if (locus) {
- size_t size = 0;
-
- if (locus->beg.col == 0)
- fprintf(stderr, "%s:%u",
- locus->beg.file,
- locus->beg.line);
- else if (strcmp(locus->beg.file, locus->end.file))
- fprintf(stderr, "%s:%u.%u-%s:%u.%u",
- locus->beg.file,
- locus->beg.line, locus->beg.col,
- locus->end.file,
- locus->end.line, locus->end.col);
- else if (locus->beg.line != locus->end.line)
- fprintf(stderr, "%s:%u.%u-%u.%u",
- locus->beg.file,
- locus->beg.line, locus->beg.col,
- locus->end.line, locus->end.col);
- else
- fprintf(stderr, "%s:%u.%u-%u",
- locus->beg.file,
- locus->beg.line, locus->beg.col,
- locus->end.col);
- fprintf(stderr, ": ");
- }
-
- if (qual)
- fprintf(stderr, "%s: ", qual);
- vfprintf(stderr, fmt, ap);
- fputc('\n', stderr);
-}
-
-void
-diag(grecs_locus_t const *locus, const char *qual, const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vdiag(locus, qual, fmt, ap);
- va_end(ap);
-}
-
-void
-die(int status, const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vdiag(NULL, NULL, fmt, ap);
- va_end(ap);
- exit(status);
-}
-
-void
-err(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vdiag(NULL, NULL, fmt, ap);
- va_end(ap);
-}
-
-void
-warn(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vdiag(NULL, "warning", fmt, ap);
- va_end(ap);
-}
-
-void
-debug_printf(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- vdiag(NULL, "debug", fmt, ap);
- va_end(ap);
-}
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" ;
int lint_mode;
-int debug_level[ECLAT_DEBCAT_MAX];
int dry_run_mode;
@@ -32,55 +31,19 @@ enum eclat_command eclat_command;
-struct debug_trans {
- const char *name;
- size_t length;
- int cat;
+static char *categories[] = {
+ "main",
+ "cfgram",
+ "cflex",
+ "conf",
+ "curl",
};
-static struct debug_trans debug_trans[] = {
-#define S(s) #s, sizeof(#s)-1
- { S(main), ECLAT_DEBCAT_MAIN },
- { S(cfgram), ECLAT_DEBCAT_CFGRAM },
- { S(cflex), ECLAT_DEBCAT_CFLEX },
- { S(conf), ECLAT_DEBCAT_CONF },
- { S(curl), ECLAT_DEBCAT_CURL },
- { NULL }
-};
-
-static int
-parse_debug_level(const char *arg)
+static void
+debug_init()
{
- unsigned long cat, lev;
- char *p;
-
- if (isascii(*arg) && isdigit(*arg)) {
- cat = strtoul(arg, &p, 10);
- if (cat > ECLAT_DEBCAT_MAX)
- return -1;
- } else {
- size_t len = strcspn(arg, ".");
- struct debug_trans *dp;
-
- for (dp = debug_trans; dp->name; dp++)
- if (dp->length == len &&
- memcmp(dp->name, arg, len) == 0)
- break;
+ int i;
- if (!dp->name)
- return -1;
- cat = dp->cat;
- p = (char*) arg + len;
+ for (i = 0; i < sizeof(categories)/sizeof(categories[0]); i++)
+ debug_register(categories[i]);
}
- if (*p == 0)
- lev = 100;
- else if (*p != '.')
- return -1;
- else {
- lev = strtoul(p + 1, &p, 10);
- if (*p)
- return -1;
- }
- debug_level[cat] = lev;
- return 0;
-}
@@ -92,3 +55,3 @@ dump(const char *text, FILE *stream, unsigned char *ptr, size_t size)
unsigned int width = 0x10;
- int hex = debug_level[ECLAT_DEBCAT_CURL] > 2;
+ int hex = debug_level(ECLAT_DEBCAT_CURL) > 2;
@@ -201,3 +164,3 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data)
/* FIXME: Debugging level. */
- if (debug_level[ECLAT_DEBCAT_MAIN] > 10) {
+ if (debug_level(ECLAT_DEBCAT_MAIN) > 10) {
dump_text(stderr, line, column, ptr, realsize);
@@ -218,3 +181,2 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data)
-
#include "cmdline.h"
@@ -239,2 +201,3 @@ main(int argc, char **argv)
set_program_name(argv[0]);
+ debug_init();
config_init();
@@ -245,4 +208,4 @@ main(int argc, char **argv)
- grecs_gram_trace(debug_level[ECLAT_DEBCAT_CFGRAM]);
- grecs_lex_trace(debug_level[ECLAT_DEBCAT_CFLEX]);
+ grecs_gram_trace(debug_level(ECLAT_DEBCAT_CFGRAM));
+ grecs_lex_trace(debug_level(ECLAT_DEBCAT_CFLEX));
@@ -294,5 +257,5 @@ main(int argc, char **argv)
- if (debug_level[ECLAT_DEBCAT_CURL]) {
+ if (debug_level(ECLAT_DEBCAT_CURL)) {
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
- if (debug_level[ECLAT_DEBCAT_CURL] > 1)
+ if (debug_level(ECLAT_DEBCAT_CURL) > 1)
curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION,
diff --git a/src/eclat.h b/src/eclat.h
index b0d46ac..e588b57 100644
--- a/src/eclat.h
+++ b/src/eclat.h
@@ -35,6 +35,3 @@
#define ECLAT_DEBCAT_CURL 4
-#define ECLAT_DEBCAT_MAX 5
-
-extern const char *program_name;
-extern int debug_level[];
+#define ECLAT_DEBCAT_FORLAN 5
@@ -48,16 +45,2 @@ extern char *secret_key;
-#define debug(cat, lev, s) \
- do { \
- if (debug_level[cat] >= (lev)) \
- debug_printf s; \
- } while(0)
-
-void die(int status, const char *fmt, ...);
-void vdiag(grecs_locus_t const *locus, const char *qual, const char *fmt,
- va_list ap);
-void diag(grecs_locus_t const *locus, const char *qual, const char *fmt, ...);
-void err(const char *fmt, ...);
-void warn(const char *fmt, ...);
-void debug_printf(const char *fmt, ...);
-
typedef int (*config_finish_hook_t) (void*);
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 @@
-/* This file is part of Eclat.
- Copyright (C) 2012 Sergey Poznyakoff.
-
- Eclat is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3, or (at your option)
- any later version.
-
- Eclat is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with Eclat. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "eclat.h"
-#include <stdargs.h>
-#include <stdio.h>
-
-char *program_name;
-
-void
-diag(const char *qual, const char *fmt, va_list ap)
-{
- if (program_name)
- fprintf(stderr, "%s: ", program_name);
- if (qual)
- fprintf(stderr, "%s: ", qual);
- va_start(ap, fmt);
- vfprintf(stderr, ftm, ap);
- va_end(ap);
- fputc('\n', stderr);
-}
-
-void
-err(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- diag(NULL, ftm, ap);
- va_end(ap);
-}
-
-void
-warn(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- diag("warning", ftm, ap);
- va_end(ap);
-}
-
-void
-debug_printf(const char *fmt, ...)
-{
- va_list ap;
-
- va_start(ap, fmt);
- diag("debug", ftm, ap);
- va_end(ap);
-}

Return to:

Send suggestions and report system problems to the System administrator.