aboutsummaryrefslogtreecommitdiff
path: root/tests/gcffmt.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-05-06 11:58:47 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2011-05-06 13:00:06 +0300
commit52c12573a505bf29a0301a1c9553e88c3270713e (patch)
tree642047e5b3de469199b68a76064f756990a3b249 /tests/gcffmt.c
parent8465fa7066d3c922b738346335f801cf9ea2243f (diff)
downloadgrecs-52c12573a505bf29a0301a1c9553e88c3270713e.tar.gz
grecs-52c12573a505bf29a0301a1c9553e88c3270713e.tar.bz2
Rewrite list support to keep doubly-linked lists. Implement tree reduction.
* src/format.c (grecs_format_node) (grecs_format_node_path): Handle grecs_node_root. * src/grecs-gram.y (input production): Create root node. * src/grecs.h (grecs_list_entry)<prev>: New member. (grecs_node_root): New node type. (grecs_node_eq): New proto. (grecs_list_add,grecs_tree_reduce): New protos. * src/list.c: Rewrite as a doubly-linked list. * src/tree.c (grecs_node_bind): Bugfix. (grecs_node_unlink): New function. (_tree_recurse): Allow for removal of the current node. (grecs_node_eq): New function. (grecs_tree_reduce): New function. (grecs_tree_process): Descend into the first subnode at once. * src/lookup.c (node_finder): Handle grecs_node_root. * tests/reduce00.at: New testcase. * tests/reduce01.at: New testcase. * tests/reduce02.at: New testcase. * tests/testsuite.at (GRECS_TEST): New macro. Include reduce0[0-2].at. * tests/gcffmt.c: New option -reduce. * tests/gcfpeek.c: Likewise. * tests/gcfset.c: Likewise.
Diffstat (limited to 'tests/gcffmt.c')
-rw-r--r--tests/gcffmt.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/tests/gcffmt.c b/tests/gcffmt.c
index aa73717..cacf7d2 100644
--- a/tests/gcffmt.c
+++ b/tests/gcffmt.c
@@ -24,7 +24,8 @@
static void
usage(const char *arg, FILE *fp, int code)
{
- fprintf(fp, "usage: %s [-h] [-locus] [-delim=char] file\n", arg);
+ fprintf(fp, "usage: %s [-h] [-locus] [-delim=char] [-reduce] file\n",
+ arg);
exit(code);
}
@@ -35,13 +36,16 @@ main(int argc, char **argv)
char *file = NULL;
struct grecs_node *tree, *node;
int flags = GRECS_NODE_FLAG_DEFAULT;
-
+ int reduce = 0;
+
while (--argc) {
char *arg = *++argv;
if (strcmp(arg, "-locus") == 0)
flags |= GRECS_NODE_FLAG_LOCUS;
else if (strncmp(arg, "-delim=", 7) == 0)
flags |= arg[7];
+ else if (strcmp(arg, "-reduce") == 0)
+ reduce = 1;
else if (strcmp(arg, "-h") == 0)
usage(progname, stdout, 0);
else if (arg[0] == '-')
@@ -58,7 +62,8 @@ main(int argc, char **argv)
tree = grecs_parse(file);
if (!tree)
exit(1);
-
+ if (reduce)
+ grecs_tree_reduce(tree, NULL);
for (node = tree; node; node = node->next) {
grecs_format_node(node, flags, stdout);
fputc('\n', stdout);

Return to:

Send suggestions and report system problems to the System administrator.