]> git.proxmox.com Git - mirror_frr.git/blob - lib/command_match.h
lib: Code cleanup, formatting, & headers
[mirror_frr.git] / lib / command_match.h
1 /*
2 * Input matching routines for CLI backend.
3 *
4 * --
5 * Copyright (C) 2016 Cumulus Networks, Inc.
6 *
7 * This file is part of GNU Zebra.
8 *
9 * GNU Zebra is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
12 * later version.
13 *
14 * GNU Zebra is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with GNU Zebra; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22 * 02111-1307, USA.
23 */
24
25 #ifndef _ZEBRA_COMMAND_MATCH_H
26 #define _ZEBRA_COMMAND_MATCH_H
27
28 #include "command.h"
29 #include "command_graph.h"
30 #include "linklist.h"
31
32
33 /* These definitions exist in command.c in the current engine but should be
34 * relocated here in the new engine
35 */
36 enum filter_type
37 {
38 FILTER_RELAXED,
39 FILTER_STRICT
40 };
41
42 /* matcher result value */
43 enum matcher_rv
44 {
45 MATCHER_NO_MATCH,
46 MATCHER_INCOMPLETE,
47 MATCHER_AMBIGUOUS,
48 MATCHER_OK,
49 };
50
51 /* completion match types */
52 enum match_type
53 {
54 no_match,
55 partly_match,
56 exact_match
57 };
58
59 /* Defines which matcher_rv values constitute an error. Should be used with
60 * matcher_rv return values to do basic error checking.
61 */
62 #define MATCHER_ERROR(matcher_rv) \
63 ( (matcher_rv) == MATCHER_INCOMPLETE \
64 || (matcher_rv) == MATCHER_NO_MATCH \
65 || (matcher_rv) == MATCHER_AMBIGUOUS \
66 )
67
68 /**
69 * Attempt to find an exact command match for a line of user input.
70 *
71 * @param[in] start start node of command graph to match against
72 * @param[in] vline vectorized input string
73 * @param[out] argv pointer to argument list if successful match
74 * @param[out] element pointer to matched cmd_element if successful match
75 * @return matcher status
76 */
77 enum matcher_rv
78 match_command (struct graph_node *start,
79 vector vline,
80 struct list **argv,
81 struct cmd_element **element);
82
83 /**
84 * Compiles possible completions for a given line of user input.
85 *
86 * @param[in] start the start node of the DFA to match against
87 * @param[in] vline vectorized input string
88 * @param[in] completions pointer to possible completions
89 * @return matcher status
90 */
91 enum matcher_rv
92 match_command_complete (struct graph_node *start,
93 vector vline,
94 struct list **completions);
95
96 #endif /* _ZEBRA_COMMAND_MATCH_H */