summaryrefslogtreecommitdiff
path: root/lib/cmdtree.h
blob: e9a10d7ec56878c002365b49ad6bd960bbe06ae1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "vty.h"
#include "vector.h"

enum graph_node_type
{
  WORD_GN,
  IPV4_GN,
  IPV4_PREFIX_GN,
  IPV6_GN,
  IPV6_PREFIX_GN,
  VARIABLE_GN,
  RANGE_GN,
  NUMBER_GN,
  SELECTOR_GN,
  OPTION_GN,
  NUL_GN
};

struct graph_node
{
  enum graph_node_type type;
  vector children;
  int is_root;      // true if first token in command
  int is_leaf;      // true if last token in command

  int (*func)(struct vty *, int, const char *[]);

  /* various data fields for nodes */
  char* text;       // for words and variables
  int value;        // for numbers
  int start, end;   // for ranges
};

/*
 * Adds a child to a node. If the node already has the exact same
 * child, nothing is done.
 * @param[in] parent node
 * @param[in] child node
 * @return the new child, or the existing child if the parent already has the
 *         new child
 */
extern struct graph_node *
add_node(struct graph_node *, struct graph_node *);

/*
 * Compares two nodes for equivalence.
 * What exactly constitutes two nodes being equal depends on the
 * node type.
 * @return 0 if equal, nonzero otherwise.
 */
extern int
cmp_node(struct graph_node *first, struct graph_node *second);

extern struct graph_node *
new_node(enum graph_node_type type);