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=\
cmdline.h\
config.c\
descrtags.c\
- diag.c\
eclat.c\
eclat.h\
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
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)
{
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)
struct grecs_node *node;
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);
fputc('\n', stdout);
}
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
@@ -18,7 +18,6 @@
char *conffile = SYSCONFDIR "/eclat.conf" ;
int lint_mode;
-int debug_level[ECLAT_DEBCAT_MAX];
int dry_run_mode;
int preprocess_only = 0;
@@ -30,59 +29,23 @@ char *region_name;
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;
-}
static void
dump(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)
size_t i;
size_t c;
unsigned int width = 0x10;
- int hex = debug_level[ECLAT_DEBCAT_CURL] > 2;
+ int hex = debug_level(ECLAT_DEBCAT_CURL) > 2;
if (!hex)
/* 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)
int column = XML_GetCurrentColumnNumber(parser);
/* FIXME: Debugging level. */
- if (debug_level[ECLAT_DEBCAT_MAIN] > 10) {
+ if (debug_level(ECLAT_DEBCAT_MAIN) > 10) {
dump_text(stderr, line, column, ptr, realsize);
}
status = XML_Parse(parser, ptr, realsize, 0);
@@ -216,7 +179,6 @@ write_callback(void *ptr, size_t size, size_t nmemb, void *data)
return realsize;
}
-
#include "cmdline.h"
eclat_command_handler_t handler_tab[] = {
@@ -237,14 +199,15 @@ main(int argc, char **argv)
struct grecs_node *xmltree;
set_program_name(argv[0]);
+ debug_init();
config_init();
parse_options(argc, argv, &index);
argc -= index;
argv += index;
- 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));
if (preprocess_only)
exit(grecs_preproc_run(conffile, grecs_preprocessor) ?
@@ -292,9 +255,9 @@ main(int argc, char **argv)
if (!curl)
die(EX_UNAVAILABLE, "curl_easy_init failed");
- 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,
eclat_trace_fun);
}
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 @@
#define ECLAT_DEBCAT_CFLEX 2
#define ECLAT_DEBCAT_CONF 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
extern char *endpoint;
extern int use_ssl;
@@ -46,20 +43,6 @@ extern char *access_file_name;
extern char *access_key;
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*);
void 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 @@
-/* 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.