diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-07-18 16:16:36 +0000 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-07-18 16:16:36 +0000 |
| commit | 4b0abf2434806d5243527b5c75b8bfdcc311edd7 (patch) | |
| tree | 357c2f1e7e6288792e1d2a501d103ffad65f81ef /lib/cmdtree.c | |
| parent | 478bdaeb3b9699d2ceaa9607ef37166e7ca69faf (diff) | |
lib: Fix some DFA construction bugs
Options get null paths, parser state is properly
cleaned up, caller passes start node
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/cmdtree.c')
| -rw-r--r-- | lib/cmdtree.c | 54 |
1 files changed, 53 insertions, 1 deletions
diff --git a/lib/cmdtree.c b/lib/cmdtree.c index c7bdf381c7..da647a7ae3 100644 --- a/lib/cmdtree.c +++ b/lib/cmdtree.c @@ -29,7 +29,7 @@ add_node(struct graph_node *parent, struct graph_node *child) int cmp_node(struct graph_node *first, struct graph_node *second) { - return 1; + return 0; } struct graph_node * @@ -44,3 +44,55 @@ new_node(enum graph_node_type type) return node; } + +void +walk_graph(struct graph_node *start, int level) +{ + // print this node + switch (start->type) { + case WORD_GN: + case IPV4_GN: + case IPV4_PREFIX_GN: + case IPV6_GN: + case IPV6_PREFIX_GN: + case VARIABLE_GN: + case RANGE_GN: + fprintf(stderr, "%s", start->text); + break; + case NUMBER_GN: + fprintf(stderr, "%d", start->value); + break; + case SELECTOR_GN: + fprintf(stderr, "<>"); + break; + case OPTION_GN: + fprintf(stderr, "[]"); + break; + case NUL_GN: + fprintf(stderr, "NUL"); + break; + default: + fprintf(stderr, "ERROR"); + } + fprintf(stderr, "[%d] ", vector_active(start->children)); + + if (vector_active(start->children)) + for (unsigned int i = 0; i < vector_active(start->children); i++) { + struct graph_node *r = vector_slot(start->children, i); + if (!r) { + fprintf(stderr, "Child seems null?\n"); + break; + } + else { + if (start->type == OPTION_GN || start->type == SELECTOR_GN) { + fprintf(stderr, "\n"); + for (int i = 0; i < level+1; i++) + fprintf(stderr, "\t"); + } + walk_graph(r, level+1); + } + } + else { + fprintf(stderr, "\n"); + } +} |
