]> git.proxmox.com Git - mirror_frr.git/blob - lib/command_match.h
24cd1287e6bccf1ef81d97a03fa8dd340fd319b2
[mirror_frr.git] / lib / command_match.h
1 #ifndef COMMAND_MATCH_H
2 #define COMMAND_MATCH_H
3
4 #include "command.h"
5 #include "command_graph.h"
6 #include "linklist.h"
7
8
9 /** These definitions exist in command.c in
10 * the current engine but will be relocated
11 * here in the new engine*/
12 enum filter_type
13 {
14 FILTER_RELAXED,
15 FILTER_STRICT
16 };
17
18 /* matcher result value. */
19 enum matcher_rv
20 {
21 MATCHER_OK,
22 MATCHER_COMPLETE,
23 MATCHER_INCOMPLETE,
24 MATCHER_NO_MATCH,
25 MATCHER_AMBIGUOUS,
26 MATCHER_EXCEED_ARGC_MAX
27 };
28
29 /* Completion match types. */
30 enum match_type
31 {
32 no_match,
33 partly_match,
34 exact_match
35 };
36
37 /* Defines which matcher_rv values constitute
38 * an error. Should be used against matcher_rv
39 * return values to do basic error checking.
40 */
41 #define MATCHER_ERROR(matcher_rv) \
42 ( (matcher_rv) == MATCHER_INCOMPLETE \
43 || (matcher_rv) == MATCHER_NO_MATCH \
44 || (matcher_rv) == MATCHER_AMBIGUOUS \
45 || (matcher_rv) == MATCHER_EXCEED_ARGC_MAX \
46 )
47
48 /**
49 * Attempt to find an exact command match for a line of user input.
50 *
51 * @return cmd_element found, or NULL if there is no match.
52 */
53 struct cmd_element *
54 match_command (struct graph_node *, const char *, enum filter_type);
55
56 /**
57 * Compiles next-hops for a given line of user input.
58 *
59 * Given a string of input and a start node for a matching DFA, runs the input
60 * against the DFA until the input is exhausted or a mismatch is encountered.
61 *
62 * This function returns all valid next hops away from the current node.
63 * - If the input is a valid prefix to a longer command(s), the set of next
64 * hops determines what tokens are valid to follow the prefix. In other words,
65 * the returned list is a list of possible completions.
66 * - If the input matched a full command, exactly one of the next hops will be
67 * a node of type END_GN and its function pointer will be set.
68 * - If the input did not match any valid token sequence, the returned list
69 * will be empty (there are no transitions away from a nonexistent state).
70 *
71 * @param[in] start the start node of the DFA to match against
72 * @param[in] filter the filtering method
73 * @param[in] input the input string
74 * @return pointer to linked list with all possible next hops from the last
75 * matched token. If this is empty, the input did not match any command.
76 */
77 struct list *
78 match_command_complete (struct graph_node *, const char *, enum filter_type);
79
80 /**
81 * Builds an argument list given a cmd_element and a matching input line.
82 *
83 * @param[in] input line
84 * @param[in] cmd_element struct
85 * @return pointer to argument linked list
86 */
87 struct list *
88 match_build_argv (const char *, struct cmd_element *);
89
90 #endif