]> git.proxmox.com Git - mirror_frr.git/blob - lib/command_graph.h
lib: Add matching and argv support
[mirror_frr.git] / lib / command_graph.h
1 #ifndef COMMAND_GRAPH_H
2 #define COMMAND_GRAPH_H
3
4 #include "command.h"
5
6 enum graph_node_type
7 {
8 WORD_GN,
9 IPV4_GN,
10 IPV4_PREFIX_GN,
11 IPV6_GN,
12 IPV6_PREFIX_GN,
13 VARIABLE_GN,
14 RANGE_GN,
15 NUMBER_GN,
16 SELECTOR_GN,
17 OPTION_GN,
18 NUL_GN,
19 END_GN
20 };
21
22 struct graph_node
23 {
24 enum graph_node_type type;// data type this node matches or holds
25 int is_start; // whether this node is a start node
26 vector children; // this node's children
27 struct graph_node * end; // pointer to end for SELECTOR_GN & OPTION_GN
28
29 char* text; // for WORD_GN and VARIABLE_GN
30 long value; // for NUMBER_GN
31 long min, max; // for RANGE_GN
32
33 /* cmd_element struct pointer, only valid for END_GN */
34 struct cmd_element *element;
35 /* used for passing arguments to command functions */
36 char *arg;
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
95 /**
96 * Frees the data associated with a graph_node.
97 * @param[out] pointer to graph_node to free
98 */
99 void
100 free_node(struct graph_node *);
101 #endif