]>
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
;
27 int is_root
; // true if first token in command
28 struct graph_node
* end
; // pointer to end for SELECTOR_GN & OPTION_GN
30 // cmd_element struct pointer, only valid for END_GN
31 struct cmd_element
*element
;
33 /* various data fields for nodes */
34 char* text
; // for WORD_GN and VARIABLE_GN
35 int value
; // for NUMBER_GN
36 int min
, max
; // for RANGE_GN
40 * Adds a child to a node.
41 * If the node already has the exact same child, nothing is done. This is
42 * decided with cmp_node.
44 * @param[in] parent node
45 * @param[in] child node
46 * @return the new child, or the existing child if the parent already has the
49 extern struct graph_node
*
50 add_node(struct graph_node
*, struct graph_node
*);
53 * Compares two nodes for parsing equivalence.
54 * Equivalence in this case means that a single user input token
55 * should be able to unambiguously match one of the two nodes.
56 * For example, two nodes which have all fields equal except their
57 * function pointers would be considered equal.
59 * @param[in] first node to compare
60 * @param[in] second node to compare
61 * @return 1 if equal, zero otherwise.
64 cmp_node(struct graph_node
*, struct graph_node
*);
68 * Initializes all fields to default values and sets the node type.
70 * @param[in] node type
71 * @return pointer to the newly allocated node
73 extern struct graph_node
*
74 new_node(enum graph_node_type
);
77 * Walks a command DFA, printing structure to stdout.
80 * @param[in] start node of graph to walk
81 * @param[in] graph depth for recursion, caller passes 0
84 walk_graph(struct graph_node
*, int);
87 * Returns a string representation of the given node.
88 * @param[in] the node to describe
89 * @param[out] the buffer to write the description into
90 * @return pointer to description string
93 describe_node(struct graph_node
*, char *, unsigned int);