]>
git.proxmox.com Git - mirror_frr.git/blob - lib/command_graph.h
1 #ifndef COMMAND_GRAPH_H
2 #define COMMAND_GRAPH_H
25 enum graph_node_type type
;// data type this node matches or holds
26 unsigned int is_start
; // whether this node is a start node
27 vector children
; // this node's children
28 struct graph_node
* end
; // pointer to end for SELECTOR_GN & OPTION_GN
30 char* text
; // for WORD_GN and VARIABLE_GN
31 long long value
; // for NUMBER_GN
32 long long min
, max
; // for RANGE_GN
34 /* cmd_element struct pointer, only valid for END_GN */
35 struct cmd_element
*element
;
36 /* used for passing arguments to command functions */
39 /* refcount for node parents */
44 * Adds a node as a child of another node.
46 * @param[in] parent node
47 * @param[in] child node
48 * @return child node, for convenience
51 add_node(struct graph_node
*, struct graph_node
*);
54 * Compares two nodes for parsing equivalence.
55 * Equivalence in this case means that a single user input token
56 * should be able to unambiguously match one of the two nodes.
57 * For example, two nodes which have all fields equal except their
58 * function pointers would be considered equal.
60 * @param[in] first node to compare
61 * @param[in] second node to compare
62 * @return 1 if equal, zero otherwise.
65 cmp_node(struct graph_node
*, struct graph_node
*);
69 * Initializes all fields to default values and sets the node type.
71 * @param[in] node type
72 * @return pointer to the newly allocated node
75 new_node(enum graph_node_type
);
78 * Frees the data associated with a graph_node.
79 * @param[out] pointer to graph_node to free
82 free_node(struct graph_node
*);
85 * Recursively calls free_node on a graph node
86 * and all its children.
87 * @param[out] graph to free
90 free_graph(struct graph_node
*);
93 * Walks a command DFA, printing structure to stdout.
96 * @param[in] start node of graph to walk
97 * @param[in] graph depth for recursion, caller passes 0
100 walk_graph(struct graph_node
*, int);
103 * Returns a string representation of the given node.
104 * @param[in] the node to describe
105 * @param[out] the buffer to write the description into
106 * @return pointer to description string
109 describe_node(struct graph_node
*, char *, unsigned int);
112 dump_node (struct graph_node
*);