diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-07-07 20:35:52 +0000 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-07-12 15:05:05 +0000 |
| commit | 782d97897eb26c18721d268b7fa22226d170ee0d (patch) | |
| tree | 34128d0bbc1bd0c8a23a6f29b173d76db839f410 /lib/cmdtree.c | |
| parent | 92055a924a9fe1f8ae730580904487598ae25da9 (diff) | |
lib: Start implementing DFA
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/cmdtree.c')
| -rw-r--r-- | lib/cmdtree.c | 61 |
1 files changed, 32 insertions, 29 deletions
diff --git a/lib/cmdtree.c b/lib/cmdtree.c index 921c6d9cc6..5bb76cce3a 100644 --- a/lib/cmdtree.c +++ b/lib/cmdtree.c @@ -1,41 +1,44 @@ -#include <command.h> -#include <vector.h> +/* + * Command DFA module. + * Provides a DFA data structure and associated functions for manipulating it. + * Used to match user command line input. + * + * @author Quentin Young <qlyoung@cumulusnetworks.com> + */ -enum tree_node_type -{ - WORD_TN, - IPV4_TN, - IPV4_PREFIX_TN, - IPV6_TN, - IPV6_PREFIX_TN, - VARIABLE_TN, - RANGE_TN, - NUMBER_TN, - SELECTOR_TN, - OPTION_TN -} - -struct tree_node -{ - enum tree_node_type type; - vector children; - int leaf; - (int) (*func(struct cmd_info *, struct vty *, int, const char *[])); -} +#include "memory.h" +#include "cmdtree.h" -void add_node(struct tree_node *parent, struct tree_node *child) +struct graph_node * +add_node(struct graph_node *parent, struct graph_node *child) { + int index; + struct graph_node *p_child; + for (index = 0; index < vector_active(parent->children); index++) + { + *p_child = vector_slot(parent->children, index); + if (cmp_node(child, p_child)) + return p_child; + } + vector_set(parent->children, child); + return child; } -// checks nodes for equivalence; definition of equivalence depends -// on node type (WORD_TN strcmps words, etc) -int cmp_node(struct tree_node *first, struct tree_node *second) +int +cmp_node(struct graph_node *first, struct graph_node *second) { - } -int merge_tree(struct tree_node *first, struct tree_node *second) +struct graph_node * +new_node(enum graph_node_type type) { + struct graph_node *node = XMALLOC(MTYPE_TMP, sizeof(graph_node)); + node->type = type; + node->children = vector_init(VECTOR_MIN_SIZE); + node->is_leaf = 0; + node->is_root = 0; + node->func = NULL; + return node; } |
