2016-07-19 23:14:27 +02:00
|
|
|
#ifndef COMMAND_MATCH_H
|
|
|
|
#define COMMAND_MATCH_H
|
|
|
|
|
2016-07-27 03:35:46 +02:00
|
|
|
#include "command.h"
|
2016-07-19 23:14:27 +02:00
|
|
|
#include "command_graph.h"
|
2016-07-21 23:38:03 +02:00
|
|
|
#include "linklist.h"
|
2016-07-19 23:14:27 +02:00
|
|
|
|
2016-07-27 03:35:46 +02:00
|
|
|
|
|
|
|
/** These definitions exist in command.c in
|
|
|
|
* the current engine but will be relocated
|
|
|
|
* here in the new engine*/
|
2016-07-19 23:14:27 +02:00
|
|
|
enum filter_type
|
|
|
|
{
|
|
|
|
FILTER_RELAXED,
|
|
|
|
FILTER_STRICT
|
|
|
|
};
|
|
|
|
|
2016-07-27 03:35:46 +02:00
|
|
|
/* matcher result value. */
|
2016-07-19 23:14:27 +02:00
|
|
|
enum matcher_rv
|
|
|
|
{
|
|
|
|
MATCHER_NO_MATCH,
|
2016-08-03 21:22:27 +02:00
|
|
|
MATCHER_INCOMPLETE,
|
2016-07-19 23:14:27 +02:00
|
|
|
MATCHER_AMBIGUOUS,
|
2016-08-03 21:22:27 +02:00
|
|
|
MATCHER_OK,
|
2016-07-19 23:14:27 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Completion match types. */
|
2016-07-21 23:38:03 +02:00
|
|
|
enum match_type
|
2016-07-19 23:14:27 +02:00
|
|
|
{
|
|
|
|
no_match,
|
|
|
|
partly_match,
|
2016-07-21 23:38:03 +02:00
|
|
|
exact_match
|
2016-07-19 23:14:27 +02:00
|
|
|
};
|
2016-07-27 03:35:46 +02:00
|
|
|
|
|
|
|
/* Defines which matcher_rv values constitute
|
2016-07-19 23:14:27 +02:00
|
|
|
* an error. Should be used against matcher_rv
|
|
|
|
* return values to do basic error checking.
|
|
|
|
*/
|
|
|
|
#define MATCHER_ERROR(matcher_rv) \
|
|
|
|
( (matcher_rv) == MATCHER_INCOMPLETE \
|
|
|
|
|| (matcher_rv) == MATCHER_NO_MATCH \
|
|
|
|
|| (matcher_rv) == MATCHER_AMBIGUOUS \
|
|
|
|
)
|
|
|
|
|
2016-07-27 03:35:46 +02:00
|
|
|
/**
|
|
|
|
* Attempt to find an exact command match for a line of user input.
|
|
|
|
*
|
2016-07-29 17:54:03 +02:00
|
|
|
* @param DFA to match against
|
|
|
|
* @param input string
|
2016-08-03 21:22:27 +02:00
|
|
|
* @param pointer which will be pointed at argv upon match
|
|
|
|
* @param pointer which will be pointed at matching cmd_element upon match
|
|
|
|
* @return result of matcher run
|
2016-07-27 03:35:46 +02:00
|
|
|
*/
|
2016-08-03 21:22:27 +02:00
|
|
|
enum matcher_rv
|
|
|
|
match_command (struct graph_node *, const char *, struct list **, struct cmd_element **);
|
2016-07-27 03:35:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Compiles next-hops for a given line of user input.
|
|
|
|
*
|
|
|
|
* Given a string of input and a start node for a matching DFA, runs the input
|
|
|
|
* against the DFA until the input is exhausted or a mismatch is encountered.
|
|
|
|
*
|
|
|
|
* This function returns all valid next hops away from the current node.
|
|
|
|
* - If the input is a valid prefix to a longer command(s), the set of next
|
|
|
|
* hops determines what tokens are valid to follow the prefix. In other words,
|
|
|
|
* the returned list is a list of possible completions.
|
|
|
|
* - If the input matched a full command, exactly one of the next hops will be
|
|
|
|
* a node of type END_GN and its function pointer will be set.
|
|
|
|
* - If the input did not match any valid token sequence, the returned list
|
|
|
|
* will be empty (there are no transitions away from a nonexistent state).
|
|
|
|
*
|
|
|
|
* @param[in] start the start node of the DFA to match against
|
|
|
|
* @param[in] filter the filtering method
|
|
|
|
* @param[in] input the input string
|
|
|
|
* @return pointer to linked list with all possible next hops from the last
|
|
|
|
* matched token. If this is empty, the input did not match any command.
|
|
|
|
*/
|
|
|
|
struct list *
|
2016-08-01 22:30:14 +02:00
|
|
|
match_command_complete (struct graph_node *, const char *);
|
2016-07-27 03:35:46 +02:00
|
|
|
|
2016-07-19 23:14:27 +02:00
|
|
|
#endif
|