]> git.proxmox.com Git - mirror_frr.git/blame - lib/command_match.h
Merge pull request #345 from chiragshah6/pim_dev
[mirror_frr.git] / lib / command_match.h
CommitLineData
1ab84bf3
QY
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
9d0662e0 27
1eb5e8dc 28#include "graph.h"
18be0e59 29#include "linklist.h"
1eb5e8dc 30#include "command.h"
eceb1066 31
1ab84bf3
QY
32/* These definitions exist in command.c in the current engine but should be
33 * relocated here in the new engine
34 */
9d0662e0
QY
35enum filter_type
36{
37 FILTER_RELAXED,
38 FILTER_STRICT
39};
40
1ab84bf3 41/* matcher result value */
9d0662e0
QY
42enum matcher_rv
43{
9d0662e0 44 MATCHER_NO_MATCH,
6ce82b63 45 MATCHER_INCOMPLETE,
9d0662e0 46 MATCHER_AMBIGUOUS,
6ce82b63 47 MATCHER_OK,
9d0662e0
QY
48};
49
1ab84bf3 50/* completion match types */
18be0e59 51enum match_type
9d0662e0 52{
a78596c4
QY
53 trivial_match, // the input is null
54 no_match, // the input does not match
55 partly_match, // the input matches but is incomplete
56 exact_match // the input matches and is complete
9d0662e0 57};
eceb1066 58
1ab84bf3
QY
59/* Defines which matcher_rv values constitute an error. Should be used with
60 * matcher_rv return values to do basic error checking.
9d0662e0
QY
61 */
62#define MATCHER_ERROR(matcher_rv) \
63 ( (matcher_rv) == MATCHER_INCOMPLETE \
64 || (matcher_rv) == MATCHER_NO_MATCH \
65 || (matcher_rv) == MATCHER_AMBIGUOUS \
9d0662e0
QY
66 )
67
eceb1066
QY
68/**
69 * Attempt to find an exact command match for a line of user input.
70 *
1eb5e8dc 71 * @param[in] cmdgraph command graph to match against
1ab84bf3 72 * @param[in] vline vectorized input string
17aca20b
QY
73 * @param[out] argv pointer to argument list if successful match, NULL
74 * otherwise. The elements of this list are pointers to struct cmd_token
75 * and represent the sequence of tokens matched by the inpu. The ->arg
76 * field of each token points to a copy of the input matched on it. These
77 * may be safely deleted or modified.
78 * @param[out] element pointer to matched cmd_element if successful match,
79 * or NULL when MATCHER_ERROR(rv) is true. The cmd_element may *not* be
80 * safely deleted or modified; it is the instance initialized on startup.
1ab84bf3 81 * @return matcher status
eceb1066 82 */
6ce82b63 83enum matcher_rv
1eb5e8dc 84command_match (struct graph *cmdgraph,
1ab84bf3
QY
85 vector vline,
86 struct list **argv,
17aca20b 87 const struct cmd_element **element);
eceb1066
QY
88
89/**
1ab84bf3 90 * Compiles possible completions for a given line of user input.
eceb1066
QY
91 *
92 * @param[in] start the start node of the DFA to match against
1ab84bf3 93 * @param[in] vline vectorized input string
17aca20b
QY
94 * @param[out] completions pointer to list of cmd_token representing
95 * acceptable next inputs, or NULL when MATCHER_ERROR(rv) is true.
96 * The elements of this list are pointers to struct cmd_token and take on a
97 * variety of forms depending on the passed vline. If the last element in vline
98 * is NULL, all previous elements are considered to be complete words (the case
99 * when a space is the last token of the line) and completions are generated
100 * based on what could follow that input. If the last element in vline is not
101 * NULL and each sequential element matches the corresponding tokens of one or
102 * more commands exactly (e.g. 'encapv4' and not 'en') the same result is
103 * generated. If the last element is not NULL and the best possible match is a
104 * partial match, then the result generated will be all possible continuations
105 * of that element (e.g. 'encapv4', 'encapv6', etc for input 'en').
106 * @return matcher status
eceb1066 107 */
1ab84bf3 108enum matcher_rv
1eb5e8dc 109command_complete (struct graph *cmdgraph,
55589d30
QY
110 vector vline,
111 struct list **completions);
eceb1066 112
1ab84bf3 113#endif /* _ZEBRA_COMMAND_MATCH_H */