]> git.proxmox.com Git - mirror_frr.git/blob - lib/command_graph.h
lib: Reorganize some matching stuff
[mirror_frr.git] / lib / command_graph.h
1 #ifndef COMMAND_GRAPH_H
2 #define COMMAND_GRAPH_H
3
4 #include "vty.h"
5 #include "vector.h"
6
7 enum graph_node_type
8 {
9 WORD_GN,
10 IPV4_GN,
11 IPV4_PREFIX_GN,
12 IPV6_GN,
13 IPV6_PREFIX_GN,
14 VARIABLE_GN,
15 RANGE_GN,
16 NUMBER_GN,
17 SELECTOR_GN,
18 OPTION_GN,
19 NUL_GN,
20 END_GN
21 };
22
23 struct graph_node
24 {
25 enum graph_node_type type;
26 vector children;
27 int is_root; // true if first token in command
28 struct graph_node * end; // pointer to end for SELECTOR_GN & OPTION_GN
29
30 // cmd_element struct pointer, only valid for END_GN
31 struct cmd_element *element;
32
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
37 };
38
39 /*
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.
43 *
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
47 * new child
48 */
49 extern struct graph_node *
50 add_node(struct graph_node *, struct graph_node *);
51
52 /*
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.
58 *
59 * @param[in] first node to compare
60 * @param[in] second node to compare
61 * @return 1 if equal, zero otherwise.
62 */
63 extern int
64 cmp_node(struct graph_node *, struct graph_node *);
65
66 /*
67 * Create a new node.
68 * Initializes all fields to default values and sets the node type.
69 *
70 * @param[in] node type
71 * @return pointer to the newly allocated node
72 */
73 extern struct graph_node *
74 new_node(enum graph_node_type);
75
76 /**
77 * Walks a command DFA, printing structure to stdout.
78 * For debugging.
79 *
80 * @param[in] start node of graph to walk
81 * @param[in] graph depth for recursion, caller passes 0
82 */
83 extern void
84 walk_graph(struct graph_node *, int);
85
86 /**
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
91 */
92 extern char *
93 describe_node(struct graph_node *, char *, unsigned int);
94 #endif