]>
git.proxmox.com Git - mirror_frr.git/blob - lib/command_graph.h
1 #ifndef COMMAND_GRAPH_H
2 #define COMMAND_GRAPH_H
24 enum graph_node_type type
;
26 int is_root
; // true if first token in command
27 int is_leaf
; // true if last token in command
28 struct graph_node
* end
; // pointer to end for selector & option
30 int (*func
)(struct vty
*, int, const char *[]);
32 /* various data fields for nodes */
33 char* text
; // for words and variables
34 int value
; // for numbers
35 int min
, max
; // for ranges
39 * Adds a child to a node.
40 * If the node already has the exact same child, nothing is done. This is
41 * decided with cmp_node.
43 * @param[in] parent node
44 * @param[in] child node
45 * @return the new child, or the existing child if the parent already has the
48 extern struct graph_node
*
49 add_node(struct graph_node
*, struct graph_node
*);
52 * Compares two nodes for parsing equivalence.
53 * Equivalence in this case means that a single user input token
54 * should be able to unambiguously match one of the two nodes.
55 * For example, two nodes which have all fields equal except their
56 * function pointers would be considered equal.
58 * @param[in] first node to compare
59 * @param[in] second node to compare
60 * @return 1 if equal, zero otherwise.
63 cmp_node(struct graph_node
*, struct graph_node
*);
67 * Initializes all fields to default values and sets the node type.
69 * @param[in] node type
70 * @return pointer to the newly allocated node
72 extern struct graph_node
*
73 new_node(enum graph_node_type
);
76 * Walks a command DFA, printing structure to stdout.
79 * @param[in] start node of graph to walk
80 * @param[in] graph depth for recursion, caller passes 0
83 walk_graph(struct graph_node
*, int);
86 * Returns a string representation of the given node.
87 * @param[in] the node to describe
88 * @return pointer to description string
91 describe_node(struct graph_node
*);