aboutsummaryrefslogtreecommitdiff
path: root/tests/gcffmt.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-06-23 13:29:06 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-06-23 13:46:11 +0300
commit582d89672b36583a50a10be741853d3315d95bd0 (patch)
tree4c1e03152001525517abc784b4d546f40a5d2902 /tests/gcffmt.c
parent00466520a845c0abd58ca7e98bc8bdbbe754702a (diff)
downloadgrecs-582d89672b36583a50a10be741853d3315d95bd0.tar.gz
grecs-582d89672b36583a50a10be741853d3315d95bd0.tar.bz2
Conditionally include tests related to parser formats that can be disabled at configuration time.
* src/Make.am (PARSER_DEFS, AM_CPPFLAGS): New variables. [GRECS_COND_META1_PARSER]: Update PARSER_DEFS. [GRECS_COND_BIND_PARSER]: Likewise. [GRECS_COND_GIT_PARSER]: Likewise. (GRECS_SRC): Add parsertab.c * src/parsertab.c: New file. * src/grecs.h (grecs_parser_t): New typedef. (grecs_enumerate_parsers) (grecs_get_parser_by_type): New functions. * tests/Makefile.am (PARSER_DEFS): New variable. [GRECS_COND_META1_PARSER]: Update PARSER_DEFS. [GRECS_COND_BIND_PARSER]: Likewise. [GRECS_COND_GIT_PARSER]: Likewise. (package.m4): Define ENABLE_* according to the PARSER_DEFS settings. * tests/empty.at: Test ENABLE_* defines to avoid testing unsupported parser formats. * tests/testsuite.at: Likewise. * tests/gcffmt.c: New option -list. Improve help output.
Diffstat (limited to 'tests/gcffmt.c')
-rw-r--r--tests/gcffmt.c83
1 files changed, 68 insertions, 15 deletions
diff --git a/tests/gcffmt.c b/tests/gcffmt.c
index 6df2490..1352e5c 100644
--- a/tests/gcffmt.c
+++ b/tests/gcffmt.c
@@ -21,12 +21,38 @@
#include <errno.h>
#include "grecs.h"
+struct list_helper {
+ FILE *file;
+ int delim;
+};
+
+static int
+list_parser_types(const char *name, grecs_parser_t parser, void *data)
+{
+ struct list_helper *p = data;
+ fprintf(p->file, "%c%s", p->delim, name);
+ p->delim = '|';
+ return 0;
+}
+
static void
usage(const char *arg, FILE *fp, int code)
{
+ struct list_helper lh;
+ int w;
+
fprintf(fp,
- "usage: %s [-h] [-locus] [-delim=char] [-reduce] [-sort] "
- "[-type=grecs|bind|meta1|git|path] [-Idir] [-include=dir] file [file...]\n",
+ "usage: %s%n [-h] [-list[=type]] [-locus] [-delim=char] [-reduce] [-sort]\n",
+ arg, &w);
+ do
+ fputc(' ', fp);
+ while (w--);
+
+ fprintf(fp, "[-type");
+ lh.file = fp;
+ lh.delim = '=';
+ grecs_enumerate_parsers(list_parser_types, &lh);
+ fprintf(fp, "] [-Idir] [-include=dir] file [file...]\n",
arg);
exit(code);
}
@@ -36,7 +62,33 @@ node_ident_cmp(struct grecs_node const *a, struct grecs_node const *b)
{
return strcmp(a->ident, b->ident);
}
-
+
+int
+list_parser(const char *name, grecs_parser_t parser, void *data)
+{
+ printf("%s\n", name);
+ return 0;
+}
+
+int
+find_parser(const char *name, grecs_parser_t parser, void *data)
+{
+ if (strcasecmp(name, (char*)data) == 0)
+ exit(0);
+ return 0;
+}
+
+int
+set_parser(const char *arg)
+{
+ grecs_parser_t p = grecs_get_parser_by_type(arg);
+ if (p) {
+ grecs_parser_fun = p;
+ return 0;
+ }
+ return 1;
+}
+
int
main(int argc, char **argv)
{
@@ -59,18 +111,14 @@ main(int argc, char **argv)
sort = 1;
else if (strcmp(arg, "-h") == 0)
usage(progname, stdout, 0);
- else if (strncmp(arg, "-type=", 6) == 0) {
- if (strcasecmp(arg+6, "GRECS") == 0)
- grecs_parser_fun = grecs_grecs_parser;
- else if (strcasecmp(arg+6, "META1") == 0)
- grecs_parser_fun = grecs_meta1_parser;
- else if (strcasecmp(arg+6, "BIND") == 0)
- grecs_parser_fun = grecs_bind_parser;
- else if (strcasecmp(arg+6, "GIT") == 0)
- grecs_parser_fun = grecs_git_parser;
- else if (strcasecmp(arg+6, "PATH") == 0)
- grecs_parser_fun = grecs_path_parser;
- else
+ else if (strcmp(arg, "-list") == 0) {
+ grecs_enumerate_parsers(list_parser, NULL);
+ exit(0);
+ } else if (strncmp(arg, "-list=", 6) == 0) {
+ grecs_enumerate_parsers(find_parser, arg + 6);
+ exit(2);
+ } else if (strncmp(arg, "-type=", 6) == 0) {
+ if (set_parser(arg + 6))
usage(progname, stderr, 1);
} else if (strncmp(arg, "-I", 2) == 0)
grecs_preproc_add_include_dir(arg+2);
@@ -88,6 +136,11 @@ main(int argc, char **argv)
break;
}
}
+
+ if (!grecs_parser_fun) {
+ fprintf(stderr, "%s: requested type not supported", progname);
+ exit(2);
+ }
if (!file)
usage(progname, stderr, 1);

Return to:

Send suggestions and report system problems to the System administrator.