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