aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2012-09-25 17:31:24 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2012-09-25 17:45:23 +0300
commit455e12faaf5efd997ff74ad04c0fcc62608477a5 (patch)
tree46d24aba487fb2ea76078ef4da60357ff0a340e4 /tests
parent2f5d961c798802f1e467de1cd310f661e0a45fa7 (diff)
downloadeclat-455e12faaf5efd997ff74ad04c0fcc62608477a5.tar.gz
eclat-455e12faaf5efd997ff74ad04c0fcc62608477a5.tar.bz2
Use forlan to format the output.
* lib/forlan.h (forlan_lex_begin): Remove (forlan_lex_from_buffer) (forlan_lex_from_file): New protos. (forlan_parse): Remove. (forlan_parse_bufferm,forlan_parse_file): New protos. * lib/forlangrm.y (forlan_parse): Remove. (forlan_parse_bufferm,forlan_parse_file): New functions. * lib/forlanlex.l (YY_INPUT): Optionally, read input from file. (forlan_lex_begin): Remove (forlan_lex_from_buffer) (forlan_lex_from_file): New functions. * src/cmdline.opt: New options: --format, --sort * src/config.c: New statement: format. * src/eclat.c: Use output format scripts, if provided. * src/eclat.conf: Define output format for DescribeTags. * src/eclat.h: Include forlan.h (define_format): New proto. * tests/tforlan.c: New option: -s
Diffstat (limited to 'tests')
-rw-r--r--tests/tforlan.c49
1 files changed, 34 insertions, 15 deletions
diff --git a/tests/tforlan.c b/tests/tforlan.c
index 8969c6d..403438e 100644
--- a/tests/tforlan.c
+++ b/tests/tforlan.c
@@ -31,7 +31,13 @@
void
usage()
{
- printf("usage: %s [-dD] FILE [INPUT]\n");
+ printf("usage: %s [OPTIONS] FILE [INPUT]\n", program_name);
+ printf("OPTIONS are:\n");
+ printf(" -D dump parse tree\n");
+ printf(" -d LEVEL set debug level\n");
+ printf(" -f use file interface\n");
+ printf(" -s sort XML tree\n");
+ printf(" -h produce this help list\n");
}
struct grecs_node *
@@ -75,6 +81,10 @@ node_ident_cmp(struct grecs_node const *a, struct grecs_node const *b)
return strcmp(a->ident, b->ident);
}
+#define OPT_DUMP 0x01
+#define OPT_SORT 0x02
+#define OPT_FILE 0x04
+
int
main(int argc, char **argv)
{
@@ -84,17 +94,16 @@ main(int argc, char **argv)
struct stat st;
struct grecs_locus_point pt;
int rc;
- int dump_option = 0;
- int sort_option = 0;
+ int options = 0;
forlan_eval_env_t env;
set_program_name(argv[0]);
forlan_init();
- while ((rc = getopt(argc, argv, "Dd:hs")) != EOF)
+ while ((rc = getopt(argc, argv, "Dd:fhs")) != EOF)
switch (rc) {
case 'D':
- dump_option++;
+ options |= OPT_DUMP;
break;
case 'd':
@@ -102,12 +111,16 @@ main(int argc, char **argv)
die(EX_USAGE, "bad debug category or level");
break;
+ case 'f':
+ options |= OPT_FILE;
+ break;
+
case 'h':
usage();
return 0;
case 's':
- sort_option = 1;
+ options |= OPT_SORT;
break;
default:
@@ -122,25 +135,31 @@ main(int argc, char **argv)
if (stat(argv[0], &st))
die(EX_UNAVAILABLE, "cannot stat input file \"%s\": %s",
argv[0], strerror(errno));
- len = st.st_size;
- buf = grecs_malloc(len);
+
fp = fopen(argv[0], "r");
if (!fp)
die(EX_UNAVAILABLE, "cannot open input file \"%s\": %s",
argv[0], strerror(errno));
- if (fread(buf, len, 1, fp) != 1)
- die(EX_UNAVAILABLE, "error reading from \"%s\": %s",
- argv[0], strerror(errno));
- fclose(fp);
pt.file = argv[0];
pt.line = 1;
pt.col = 0;
- env = forlan_parse(buf, len, &pt);
+ if (options & OPT_FILE) {
+ env = forlan_parse_file(fp, &pt);
+ } else {
+ len = st.st_size;
+ buf = grecs_malloc(len);
+ if (fread(buf, len, 1, fp) != 1)
+ die(EX_UNAVAILABLE, "error reading from \"%s\": %s",
+ argv[0], strerror(errno));
+ env = forlan_parse_buffer(buf, len, &pt);
+ }
+ fclose(fp);
+
if (!env)
return EX_UNAVAILABLE;
- if (dump_option)
+ if (options & OPT_DUMP)
forlan_dump_tree(stdout, env);
if (argv[1]) {
@@ -154,7 +173,7 @@ main(int argc, char **argv)
tree = parse_xml(fp);
fclose(fp);
- if (sort_option)
+ if (options & OPT_SORT)
grecs_tree_sort(tree, node_ident_cmp);
forlan_run(env, tree);

Return to:

Send suggestions and report system problems to the System administrator.