diff options
| author | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-07-19 17:06:11 +0000 |
|---|---|---|
| committer | Quentin Young <qlyoung@cumulusnetworks.com> | 2016-07-19 17:06:11 +0000 |
| commit | 340a2b4ac0bcc737e24aa6c0e383f1188aaaaf61 (patch) | |
| tree | f0bf3ce9c04baa763464a8922ec8a227f7595edd /lib/cmdtree.h | |
| parent | 4b0abf2434806d5243527b5c75b8bfdcc311edd7 (diff) | |
lib: Implement node comparison function
Implement comparator for nodes, some miscellaneous cleanup.
Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'lib/cmdtree.h')
| -rw-r--r-- | lib/cmdtree.h | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/lib/cmdtree.h b/lib/cmdtree.h index 9b512e3bb9..3d2366b008 100644 --- a/lib/cmdtree.h +++ b/lib/cmdtree.h @@ -20,20 +20,23 @@ struct graph_node { enum graph_node_type type; vector children; - int is_root; // true if first token in command - int is_leaf; // true if last token in command + int is_root; // true if first token in command + int is_leaf; // true if last token in command + struct graph_node * end; // pointer to end for selector & option int (*func)(struct vty *, int, const char *[]); /* various data fields for nodes */ char* text; // for words and variables int value; // for numbers - int start, end; // for ranges + int min, max; // for ranges }; /* - * Adds a child to a node. If the node already has the exact same - * child, nothing is done. + * Adds a child to a node. + * If the node already has the exact same child, nothing is done. This is + * decided with cmp_node. + * * @param[in] parent node * @param[in] child node * @return the new child, or the existing child if the parent already has the @@ -43,16 +46,35 @@ extern struct graph_node * add_node(struct graph_node *, struct graph_node *); /* - * Compares two nodes for equivalence. - * What exactly constitutes two nodes being equal depends on the - * node type. - * @return 0 if equal, nonzero otherwise. + * Compares two nodes for parsing equivalence. + * Equivalence in this case means that a single user input token + * should be able to unambiguously match one of the two nodes. + * For example, two nodes which have all fields equal except their + * function pointers would be considered equal. + * + * @param[in] first node to compare + * @param[in] second node to compare + * @return 1 if equal, zero otherwise. */ extern int -cmp_node(struct graph_node *first, struct graph_node *second); +cmp_node(struct graph_node *, struct graph_node *); +/* + * Create a new node. + * Initializes all fields to default values and sets the node type. + * + * @param[in] node type + * @return pointer to the newly allocated node + */ extern struct graph_node * -new_node(enum graph_node_type type); +new_node(enum graph_node_type); +/** + * Walks a command DFA, printing structure to stdout. + * For debugging. + * + * @param[in] start node of graph to walk + * @param[in] graph depth for recursion, caller passes 0 + */ extern void walk_graph(struct graph_node *, int); |
