]> git.proxmox.com Git - mirror_frr.git/blob - lib/command_graph.h
lib: Add docstring 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 IPV4_GN,
9 IPV4_PREFIX_GN,
10 IPV6_GN,
11 IPV6_PREFIX_GN,
12 WORD_GN,
13 RANGE_GN,
14 NUMBER_GN,
15 VARIABLE_GN,
16 SELECTOR_GN,
17 OPTION_GN,
18 NUL_GN,
19 START_GN,
20 END_GN
21 };
22
23 struct graph_node
24 {
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
29
30 char *text; // original format text
31 char *doc; // docstring for this node
32 long long value; // for NUMBER_GN
33 long long min, max; // for RANGE_GN
34
35 /* cmd_element struct pointer, only valid for END_GN */
36 struct cmd_element *element;
37 /* used for passing arguments to command functions */
38 char *arg;
39
40 /* refcount for node parents */
41 unsigned int refs;
42 };
43
44 /*
45 * Adds a node as a child of another node.
46 *
47 * @param[in] parent node
48 * @param[in] child node
49 * @return child node, for convenience
50 */
51 struct graph_node *
52 add_node(struct graph_node *, struct graph_node *);
53
54 /*
55 * Compares two nodes for parsing equivalence.
56 * Equivalence in this case means that a single user input token
57 * should be able to unambiguously match one of the two nodes.
58 * For example, two nodes which have all fields equal except their
59 * function pointers would be considered equal.
60 *
61 * @param[in] first node to compare
62 * @param[in] second node to compare
63 * @return 1 if equal, zero otherwise.
64 */
65 int
66 cmp_node(struct graph_node *, struct graph_node *);
67
68 /*
69 * Create a new node.
70 * Initializes all fields to default values and sets the node type.
71 *
72 * @param[in] node type
73 * @return pointer to the newly allocated node
74 */
75 struct graph_node *
76 new_node(enum graph_node_type);
77
78 /**
79 * Frees the data associated with a graph_node.
80 * @param[out] pointer to graph_node to free
81 */
82 void
83 free_node(struct graph_node *);
84
85 /**
86 * Recursively calls free_node on a graph node
87 * and all its children.
88 * @param[out] graph to free
89 */
90 void
91 free_graph(struct graph_node *);
92
93 /**
94 * Walks a command DFA, printing structure to stdout.
95 * For debugging.
96 *
97 * @param[in] start node of graph to walk
98 * @param[in] graph depth for recursion, caller passes 0
99 */
100 void
101 walk_graph(struct graph_node *, int);
102
103 /**
104 * Returns a string representation of the given node.
105 * @param[in] the node to describe
106 * @param[out] the buffer to write the description into
107 * @return pointer to description string
108 */
109 char *
110 describe_node(struct graph_node *, char *, unsigned int);
111
112 void
113 dump_node (struct graph_node *);
114 #endif