mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-15 11:15:47 +00:00
lib: Initial refactor pass on CLI backend
Shotgun commit: * Remove shim sources from Makefile.am * Move new types to command.c / command.h * Rewrite command.c / command.h * Refactor shim types to real types in matcher and parser * Initial refactor pass on vty.c Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
This commit is contained in:
parent
9286efabb9
commit
d0bfb22c22
@ -11,7 +11,7 @@ libzebra_la_LDFLAGS = -version-info 0:0:0
|
||||
libzebra_la_SOURCES = \
|
||||
network.c pid_output.c getopt.c getopt1.c daemon.c \
|
||||
checksum.c vector.c linklist.c vty.c \
|
||||
graph.c command_parse.y command_lex.l command_match.c grammar_sandbox.c \
|
||||
graph.c command_parse.y command_lex.l command_match.c \
|
||||
command.c \
|
||||
sockunion.c prefix.c thread.c if.c memory.c buffer.c table.c hash.c \
|
||||
filter.c routemap.c distribute.c stream.c str.c log.c plist.c \
|
||||
@ -28,7 +28,7 @@ libzebra_la_LIBADD = @LIB_REGEX@ @LIBCAP@
|
||||
pkginclude_HEADERS = \
|
||||
buffer.h checksum.h filter.h getopt.h hash.h \
|
||||
if.h linklist.h log.h \
|
||||
graph.h command_match.h grammar_sandbox.h \
|
||||
graph.h command_match.h \
|
||||
command.h \
|
||||
memory.h network.h prefix.h routemap.h distribute.h sockunion.h \
|
||||
str.h stream.h table.h thread.h vector.h version.h vty.h zebra.h \
|
||||
|
2603
lib/command.c
2603
lib/command.c
File diff suppressed because it is too large
Load Diff
297
lib/command.h
297
lib/command.h
@ -26,6 +26,7 @@
|
||||
#include "vector.h"
|
||||
#include "vty.h"
|
||||
#include "lib/route_types.h"
|
||||
#include "graph.h"
|
||||
|
||||
/* Host configuration variable */
|
||||
struct host
|
||||
@ -126,10 +127,54 @@ struct cmd_node
|
||||
/* Node's configuration write function */
|
||||
int (*func) (struct vty *);
|
||||
|
||||
/* Node's command graph */
|
||||
struct graph *cmdgraph;
|
||||
|
||||
/* Vector of this node's command list. */
|
||||
vector cmd_vector;
|
||||
};
|
||||
|
||||
/**
|
||||
* Types for tokens.
|
||||
*
|
||||
* The type determines what kind of data the token can match (in the
|
||||
* matching use case) or hold (in the argv use case).
|
||||
*/
|
||||
enum cmd_token_type
|
||||
{
|
||||
WORD_TKN, // words
|
||||
NUMBER_TKN, // integral numbers
|
||||
VARIABLE_TKN, // almost anything
|
||||
RANGE_TKN, // integer range
|
||||
IPV4_TKN, // IPV4 addresses
|
||||
IPV4_PREFIX_TKN, // IPV4 network prefixes
|
||||
IPV6_TKN, // IPV6 prefixes
|
||||
IPV6_PREFIX_TKN, // IPV6 network prefixes
|
||||
|
||||
/* plumbing types */
|
||||
SELECTOR_TKN, // marks beginning of selector
|
||||
OPTION_TKN, // marks beginning of option
|
||||
NUL_TKN, // dummy token
|
||||
START_TKN, // first token in line
|
||||
END_TKN, // last token in line
|
||||
};
|
||||
|
||||
/**
|
||||
* Token struct.
|
||||
*/
|
||||
struct cmd_token
|
||||
{
|
||||
enum cmd_token_type type; // token type
|
||||
|
||||
char *text; // token text
|
||||
char *desc; // token description
|
||||
|
||||
long long value; // for numeric types
|
||||
long long min, max; // for ranges
|
||||
|
||||
char *arg; // user input that matches this token
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
CMD_ATTR_DEPRECATED = 1,
|
||||
@ -140,53 +185,12 @@ enum
|
||||
struct cmd_element
|
||||
{
|
||||
const char *string; /* Command specification by string. */
|
||||
int (*func) (struct cmd_element *, struct vty *, int, const char *[]);
|
||||
const char *doc; /* Documentation of this command. */
|
||||
int daemon; /* Daemon to which this command belong. */
|
||||
vector tokens; /* Vector of cmd_tokens */
|
||||
u_char attr; /* Command attributes */
|
||||
};
|
||||
|
||||
|
||||
enum cmd_token_type
|
||||
{
|
||||
TOKEN_TERMINAL = 0,
|
||||
TOKEN_MULTIPLE,
|
||||
TOKEN_KEYWORD,
|
||||
};
|
||||
|
||||
enum cmd_terminal_type
|
||||
{
|
||||
_TERMINAL_BUG = 0,
|
||||
TERMINAL_LITERAL,
|
||||
TERMINAL_OPTION,
|
||||
TERMINAL_VARIABLE,
|
||||
TERMINAL_VARARG,
|
||||
TERMINAL_RANGE,
|
||||
TERMINAL_IPV4,
|
||||
TERMINAL_IPV4_PREFIX,
|
||||
TERMINAL_IPV6,
|
||||
TERMINAL_IPV6_PREFIX,
|
||||
};
|
||||
|
||||
/* argument to be recorded on argv[] if it's not a literal */
|
||||
#define TERMINAL_RECORD(t) ((t) >= TERMINAL_OPTION)
|
||||
|
||||
/* Command description structure. */
|
||||
struct cmd_token
|
||||
{
|
||||
enum cmd_token_type type;
|
||||
enum cmd_terminal_type terminal;
|
||||
|
||||
/* Used for type == MULTIPLE */
|
||||
vector multiple; /* vector of cmd_token, type == FINAL */
|
||||
|
||||
/* Used for type == KEYWORD */
|
||||
vector keyword; /* vector of vector of cmd_tokens */
|
||||
|
||||
/* Used for type == TERMINAL */
|
||||
char *cmd; /* Command string. */
|
||||
char *desc; /* Command's description. */
|
||||
/* handler function for command */
|
||||
int (*func) (struct cmd_element *, struct vty *, int, struct cmd_token *[]);
|
||||
};
|
||||
|
||||
/* Return value of the commands. */
|
||||
@ -221,179 +225,15 @@ struct cmd_token
|
||||
};
|
||||
|
||||
#define DEFUN_CMD_FUNC_DECL(funcname) \
|
||||
static int funcname (struct cmd_element *, struct vty *, int, const char *[]);
|
||||
static int funcname (struct cmd_element *, struct vty *, int, struct cmd_token *[]);
|
||||
|
||||
#define DEFUN_CMD_FUNC_TEXT(funcname) \
|
||||
static int funcname \
|
||||
(struct cmd_element *self __attribute__ ((unused)), \
|
||||
struct vty *vty __attribute__ ((unused)), \
|
||||
int argc __attribute__ ((unused)), \
|
||||
const char *argv[] __attribute__ ((unused)) )
|
||||
struct cmd_token *argv[] __attribute__ ((unused)) )
|
||||
|
||||
/* DEFUN for vty command interafce. Little bit hacky ;-).
|
||||
*
|
||||
* DEFUN(funcname, cmdname, cmdstr, helpstr)
|
||||
*
|
||||
* funcname
|
||||
* ========
|
||||
*
|
||||
* Name of the function that will be defined.
|
||||
*
|
||||
* cmdname
|
||||
* =======
|
||||
*
|
||||
* Name of the struct that will be defined for the command.
|
||||
*
|
||||
* cmdstr
|
||||
* ======
|
||||
*
|
||||
* The cmdstr defines the command syntax. It is used by the vty subsystem
|
||||
* and vtysh to perform matching and completion in the cli. So you have to take
|
||||
* care to construct it adhering to the following grammar. The names used
|
||||
* for the production rules losely represent the names used in lib/command.c
|
||||
*
|
||||
* cmdstr = cmd_token , { " " , cmd_token } ;
|
||||
*
|
||||
* cmd_token = cmd_terminal
|
||||
* | cmd_multiple
|
||||
* | cmd_keyword ;
|
||||
*
|
||||
* cmd_terminal_fixed = fixed_string
|
||||
* | variable
|
||||
* | range
|
||||
* | ipv4
|
||||
* | ipv4_prefix
|
||||
* | ipv6
|
||||
* | ipv6_prefix ;
|
||||
*
|
||||
* cmd_terminal = cmd_terminal_fixed
|
||||
* | option
|
||||
* | vararg ;
|
||||
*
|
||||
* multiple_part = cmd_terminal_fixed ;
|
||||
* cmd_multiple = "(" , multiple_part , ( "|" | { "|" , multiple_part } ) , ")" ;
|
||||
*
|
||||
* keyword_part = fixed_string , { " " , ( cmd_terminal_fixed | cmd_multiple ) } ;
|
||||
* cmd_keyword = "{" , keyword_part , { "|" , keyword_part } , "}" ;
|
||||
*
|
||||
* lowercase = "a" | ... | "z" ;
|
||||
* uppercase = "A" | ... | "Z" ;
|
||||
* digit = "0" | ... | "9" ;
|
||||
* number = digit , { digit } ;
|
||||
*
|
||||
* fixed_string = (lowercase | digit) , { lowercase | digit | uppercase | "-" | "_" } ;
|
||||
* variable = uppercase , { uppercase | "_" } ;
|
||||
* range = "<" , number , "-" , number , ">" ;
|
||||
* ipv4 = "A.B.C.D" ;
|
||||
* ipv4_prefix = "A.B.C.D/M" ;
|
||||
* ipv6 = "X:X::X:X" ;
|
||||
* ipv6_prefix = "X:X::X:X/M" ;
|
||||
* option = "[" , variable , "]" ;
|
||||
* vararg = "." , variable ;
|
||||
*
|
||||
* To put that all in a textual description: A cmdstr is a sequence of tokens,
|
||||
* separated by spaces.
|
||||
*
|
||||
* Terminal Tokens:
|
||||
*
|
||||
* A very simple cmdstring would be something like: "show ip bgp". It consists
|
||||
* of three Terminal Tokens, each containing a fixed string. When this command
|
||||
* is called, no arguments will be passed down to the function implementing it,
|
||||
* as it only consists of fixed strings.
|
||||
*
|
||||
* Apart from fixed strings, Terminal Tokens can also contain variables:
|
||||
* An example would be "show ip bgp A.B.C.D". This command expects an IPv4
|
||||
* as argument. As this is a variable, the IP address entered by the user will
|
||||
* be passed down as an argument. Apart from two exceptions, the other options
|
||||
* for Terminal Tokens behave exactly as we just discussed and only make a
|
||||
* difference for the CLI. The two exceptions will be discussed in the next
|
||||
* paragraphs.
|
||||
*
|
||||
* A Terminal Token can contain a so called option match. This is a simple
|
||||
* string variable that the user may omit. An example would be:
|
||||
* "show interface [IFNAME]". If the user calls this without an interface as
|
||||
* argument, no arguments will be passed down to the function implementing
|
||||
* this command. Otherwise, the interface name will be provided to the function
|
||||
* as a regular argument.
|
||||
|
||||
* Also, a Terminal Token can contain a so called vararg. This is used e.g. in
|
||||
* "show ip bgp regexp .LINE". The last token is a vararg match and will
|
||||
* consume all the arguments the user inputs on the command line and append
|
||||
* those to the list of arguments passed down to the function implementing this
|
||||
* command. (Therefore, it doesn't make much sense to have any tokens after a
|
||||
* vararg because the vararg will already consume all the words the user entered
|
||||
* in the CLI)
|
||||
*
|
||||
* Multiple Tokens:
|
||||
*
|
||||
* The Multiple Token type can be used if there are multiple possibilities what
|
||||
* arguments may be used for a command, but it should map to the same function
|
||||
* nonetheless. An example would be "ip route A.B.C.D/M (reject|blackhole)"
|
||||
* In that case both "reject" and "blackhole" would be acceptable as last
|
||||
* arguments. The words matched by Multiple Tokens are always added to the
|
||||
* argument list, even if they are matched by fixed strings. Such a Multiple
|
||||
* Token can contain almost any type of token that would also be acceptable
|
||||
* for a Terminal Token, the exception are optional variables and varag.
|
||||
*
|
||||
* There is one special case that is used in some places of Quagga that should be
|
||||
* pointed out here shortly. An example would be "password (8|) WORD". This
|
||||
* construct is used to have fixed strings communicated as arguments. (The "8"
|
||||
* will be passed down as an argument in this case) It does not mean that
|
||||
* the "8" is optional. Another historic and possibly surprising property of
|
||||
* this construct is that it consumes two parts of helpstr. (Help
|
||||
* strings will be explained later)
|
||||
*
|
||||
* Keyword Tokens:
|
||||
*
|
||||
* There are commands that take a lot of different and possibly optional arguments.
|
||||
* An example from ospf would be the "default-information originate" command. This
|
||||
* command takes a lot of optional arguments that may be provided in any order.
|
||||
* To accomodate such commands, the Keyword Token has been implemented.
|
||||
* Using the keyword token, the "default-information originate" command and all
|
||||
* its possible options can be represented using this single cmdstr:
|
||||
* "default-information originate \
|
||||
* {always|metric <0-16777214>|metric-type (1|2)|route-map WORD}"
|
||||
*
|
||||
* Keywords always start with a fixed string and may be followed by arguments.
|
||||
* Except optional variables and vararg, everything is permitted here.
|
||||
*
|
||||
* For the special case of a keyword without arguments, either NULL or the
|
||||
* keyword itself will be pushed as an argument, depending on whether the
|
||||
* keyword is present.
|
||||
* For the other keywords, arguments will be only pushed for
|
||||
* variables/Multiple Tokens. If the keyword is not present, the arguments that
|
||||
* would have been pushed will be substituted by NULL.
|
||||
*
|
||||
* A few examples:
|
||||
* "default information originate metric-type 1 metric 1000"
|
||||
* would yield the following arguments:
|
||||
* { NULL, "1000", "1", NULL }
|
||||
*
|
||||
* "default information originate always route-map RMAP-DEFAULT"
|
||||
* would yield the following arguments:
|
||||
* { "always", NULL, NULL, "RMAP-DEFAULT" }
|
||||
*
|
||||
* helpstr
|
||||
* =======
|
||||
*
|
||||
* The helpstr is used to show a short explantion for the commands that
|
||||
* are available when the user presses '?' on the CLI. It is the concatenation
|
||||
* of the helpstrings for all the tokens that make up the command.
|
||||
*
|
||||
* There should be one helpstring for each token in the cmdstr except those
|
||||
* containing other tokens, like Multiple or Keyword Tokens. For those, there
|
||||
* will only be the helpstrings of the contained tokens.
|
||||
*
|
||||
* The individual helpstrings are expected to be in the same order as their
|
||||
* respective Tokens appear in the cmdstr. They should each be terminated with
|
||||
* a linefeed. The last helpstring should be terminated with a linefeed as well.
|
||||
*
|
||||
* Care should also be taken to avoid having similar tokens with different
|
||||
* helpstrings. Imagine e.g. the commands "show ip ospf" and "show ip bgp".
|
||||
* they both contain a helpstring for "show", but only one will be displayed
|
||||
* when the user enters "sh?". If those two helpstrings differ, it is not
|
||||
* defined which one will be shown and the behavior is therefore unpredictable.
|
||||
*/
|
||||
#define DEFUN(funcname, cmdname, cmdstr, helpstr) \
|
||||
DEFUN_CMD_FUNC_DECL(funcname) \
|
||||
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \
|
||||
@ -506,41 +346,41 @@ struct cmd_token
|
||||
#define IP6_STR "IPv6 Information\n"
|
||||
#define OSPF6_STR "Open Shortest Path First (OSPF) for IPv6\n"
|
||||
#define OSPF6_ROUTER_STR "Enable a routing process\n"
|
||||
#define OSPF6_INSTANCE_STR "<1-65535> Instance ID\n"
|
||||
#define SECONDS_STR "<1-65535> Seconds\n"
|
||||
#define OSPF6_INSTANCE_STR "(1-65535) Instance ID\n"
|
||||
#define SECONDS_STR "(1-65535) Seconds\n"
|
||||
#define ROUTE_STR "Routing Table\n"
|
||||
#define PREFIX_LIST_STR "Build a prefix list\n"
|
||||
#define OSPF6_DUMP_TYPE_LIST \
|
||||
"(neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute|hook|asbr|prefix|abr)"
|
||||
"<neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute|hook|asbr|prefix|abr>"
|
||||
#define ISIS_STR "IS-IS information\n"
|
||||
#define AREA_TAG_STR "[area tag]\n"
|
||||
#define COMMUNITY_AANN_STR "Community number where AA and NN are <0-65535>\n"
|
||||
#define COMMUNITY_VAL_STR "Community number in AA:NN format (where AA and NN are <0-65535>) or local-AS|no-advertise|no-export|internet or additive\n"
|
||||
#define COMMUNITY_AANN_STR "Community number where AA and NN are (0-65535)\n"
|
||||
#define COMMUNITY_VAL_STR "Community number in AA:NN format (where AA and NN are (0-65535)) or local-AS|no-advertise|no-export|internet or additive\n"
|
||||
|
||||
#define CONF_BACKUP_EXT ".sav"
|
||||
|
||||
/* IPv4 only machine should not accept IPv6 address for peer's IP
|
||||
address. So we replace VTY command string like below. */
|
||||
#ifdef HAVE_IPV6
|
||||
#define NEIGHBOR_CMD "neighbor (A.B.C.D|X:X::X:X) "
|
||||
#define NO_NEIGHBOR_CMD "no neighbor (A.B.C.D|X:X::X:X) "
|
||||
#define NEIGHBOR_CMD "neighbor <A.B.C.D|X:X::X:X> "
|
||||
#define NO_NEIGHBOR_CMD "no neighbor <A.B.C.D|X:X::X:X> "
|
||||
#define NEIGHBOR_ADDR_STR "Neighbor address\nIPv6 address\n"
|
||||
#define NEIGHBOR_CMD2 "neighbor (A.B.C.D|X:X::X:X|WORD) "
|
||||
#define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|X:X::X:X|WORD) "
|
||||
#define NEIGHBOR_CMD2 "neighbor <A.B.C.D|X:X::X:X|WORD> "
|
||||
#define NO_NEIGHBOR_CMD2 "no neighbor <A.B.C.D|X:X::X:X|WORD> "
|
||||
#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor IPv6 address\nInterface name or neighbor tag\n"
|
||||
#define NEIGHBOR_ADDR_STR3 "Neighbor address\nIPv6 address\nInterface name\n"
|
||||
#else
|
||||
#define NEIGHBOR_CMD "neighbor A.B.C.D "
|
||||
#define NO_NEIGHBOR_CMD "no neighbor A.B.C.D "
|
||||
#define NEIGHBOR_ADDR_STR "Neighbor address\n"
|
||||
#define NEIGHBOR_CMD2 "neighbor (A.B.C.D|WORD) "
|
||||
#define NO_NEIGHBOR_CMD2 "no neighbor (A.B.C.D|WORD) "
|
||||
#define NEIGHBOR_CMD2 "neighbor <A.B.C.D|WORD> "
|
||||
#define NO_NEIGHBOR_CMD2 "no neighbor <A.B.C.D|WORD> "
|
||||
#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor tag\n"
|
||||
#endif /* HAVE_IPV6 */
|
||||
|
||||
/* Dynamic neighbor (listen range) configuration */
|
||||
#ifdef HAVE_IPV6
|
||||
#define LISTEN_RANGE_CMD "bgp listen range (A.B.C.D/M|X:X::X:X/M) "
|
||||
#define LISTEN_RANGE_CMD "bgp listen range <A.B.C.D/M|X:X::X:X/M> "
|
||||
#define LISTEN_RANGE_ADDR_STR "Neighbor address\nNeighbor IPv6 address\n"
|
||||
#else
|
||||
#define LISTEN_RANGE_CMD "bgp listen range A.B.C.D/M "
|
||||
@ -555,7 +395,7 @@ extern void install_element (enum node_type, struct cmd_element *);
|
||||
/* Concatenates argv[shift] through argv[argc-1] into a single NUL-terminated
|
||||
string with a space between each element (allocated using
|
||||
XMALLOC(MTYPE_TMP)). Returns NULL if shift >= argc. */
|
||||
extern char *argv_concat (const char **argv, int argc, int shift);
|
||||
extern char *argv_concat (struct cmd_token **argv, int argc, int shift);
|
||||
|
||||
extern vector cmd_make_strvec (const char *);
|
||||
extern void cmd_free_strvec (vector);
|
||||
@ -577,6 +417,14 @@ del_cmd_element(struct cmd_element *);
|
||||
struct cmd_element *
|
||||
copy_cmd_element(struct cmd_element *cmd);
|
||||
|
||||
/* memory management for cmd_token */
|
||||
struct cmd_token *
|
||||
new_cmd_token (enum cmd_token_type, char *, char *);
|
||||
void
|
||||
del_cmd_token (struct cmd_token *);
|
||||
struct cmd_token *
|
||||
copy_cmd_token (struct cmd_token *);
|
||||
|
||||
/* Export typical functions. */
|
||||
extern struct cmd_element config_end_cmd;
|
||||
extern struct cmd_element config_exit_cmd;
|
||||
@ -593,6 +441,7 @@ extern int cmd_banner_motd_file (const char *);
|
||||
/* struct host global, ick */
|
||||
extern struct host host;
|
||||
|
||||
/* "<cr>" global */
|
||||
extern char *command_cr;
|
||||
/* text for <cr> command */
|
||||
#define CMD_CR_TEXT "<cr>"
|
||||
|
||||
#endif /* _ZEBRA_COMMAND_H */
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include <zebra.h>
|
||||
#include "command_match.h"
|
||||
#include "command_parse.h"
|
||||
#include "grammar_sandbox.h"
|
||||
#include "memory.h"
|
||||
|
||||
/* matcher helper prototypes */
|
||||
@ -36,16 +35,16 @@ static struct list *
|
||||
command_match_r (struct graph_node *, vector, unsigned int);
|
||||
|
||||
static int
|
||||
score_precedence (enum cmd_token_type_t);
|
||||
score_precedence (enum cmd_token_type);
|
||||
|
||||
static enum match_type
|
||||
min_match_level (enum cmd_token_type_t);
|
||||
min_match_level (enum cmd_token_type);
|
||||
|
||||
static void
|
||||
del_arglist (struct list *);
|
||||
|
||||
static struct cmd_token_t *
|
||||
disambiguate_tokens (struct cmd_token_t *, struct cmd_token_t *, char *);
|
||||
static struct cmd_token *
|
||||
disambiguate_tokens (struct cmd_token *, struct cmd_token *, char *);
|
||||
|
||||
static struct list *
|
||||
disambiguate (struct list *, struct list *, vector, unsigned int);
|
||||
@ -55,7 +54,7 @@ compare_completions (const void *, const void *);
|
||||
|
||||
/* token matcher prototypes */
|
||||
static enum match_type
|
||||
match_token (struct cmd_token_t *, char *);
|
||||
match_token (struct cmd_token *, char *);
|
||||
|
||||
static enum match_type
|
||||
match_ipv4 (const char *);
|
||||
@ -70,16 +69,16 @@ static enum match_type
|
||||
match_ipv6_prefix (const char *);
|
||||
|
||||
static enum match_type
|
||||
match_range (struct cmd_token_t *, const char *);
|
||||
match_range (struct cmd_token *, const char *);
|
||||
|
||||
static enum match_type
|
||||
match_word (struct cmd_token_t *, const char *);
|
||||
match_word (struct cmd_token *, const char *);
|
||||
|
||||
static enum match_type
|
||||
match_number (struct cmd_token_t *, const char *);
|
||||
match_number (struct cmd_token *, const char *);
|
||||
|
||||
static enum match_type
|
||||
match_variable (struct cmd_token_t *, const char *);
|
||||
match_variable (struct cmd_token *, const char *);
|
||||
|
||||
/* matching functions */
|
||||
static enum matcher_rv matcher_rv;
|
||||
@ -105,7 +104,7 @@ command_match (struct graph *cmdgraph,
|
||||
struct listnode *tail = listtail (*argv);
|
||||
|
||||
// delete dummy start node
|
||||
del_cmd_token ((struct cmd_token_t *) head->data);
|
||||
del_cmd_token ((struct cmd_token *) head->data);
|
||||
list_delete_node (*argv, head);
|
||||
|
||||
// get cmd_element out of list tail
|
||||
@ -179,7 +178,7 @@ command_match_r (struct graph_node *start, vector vline, unsigned int n)
|
||||
assert (n < vector_active (vline));
|
||||
|
||||
// get the minimum match level that can count as a full match
|
||||
struct cmd_token_t *token = start->data;
|
||||
struct cmd_token *token = start->data;
|
||||
enum match_type minmatch = min_match_level (token->type);
|
||||
|
||||
// get the current operating input token
|
||||
@ -205,7 +204,7 @@ command_match_r (struct graph_node *start, vector vline, unsigned int n)
|
||||
// if we've matched all input we're looking for END_TKN
|
||||
if (n+1 == vector_active (vline))
|
||||
{
|
||||
struct cmd_token_t *tok = gn->data;
|
||||
struct cmd_token *tok = gn->data;
|
||||
if (tok->type == END_TKN)
|
||||
{
|
||||
currbest = list_new();
|
||||
@ -255,8 +254,8 @@ command_match_r (struct graph_node *start, vector vline, unsigned int n)
|
||||
else
|
||||
{
|
||||
// copy token, set arg and prepend to currbest
|
||||
struct cmd_token_t *token = start->data;
|
||||
struct cmd_token_t *copy = copy_cmd_token (token);
|
||||
struct cmd_token *token = start->data;
|
||||
struct cmd_token *copy = copy_cmd_token (token);
|
||||
copy->arg = XSTRDUP (MTYPE_CMD_TOKENS, input_token);
|
||||
list_add_node_prev (currbest, currbest->head, copy);
|
||||
matcher_rv = MATCHER_OK;
|
||||
@ -301,7 +300,7 @@ command_complete (struct graph *graph,
|
||||
|
||||
for (ALL_LIST_ELEMENTS_RO (current,node,gn))
|
||||
{
|
||||
struct cmd_token_t *token = gn->data;
|
||||
struct cmd_token *token = gn->data;
|
||||
switch (match_token (token, input_token))
|
||||
{
|
||||
case partly_match:
|
||||
@ -359,7 +358,7 @@ add_nexthops (struct list *list, struct graph_node *node)
|
||||
for (unsigned int i = 0; i < vector_active (node->to); i++)
|
||||
{
|
||||
child = vector_slot (node->to, i);
|
||||
struct cmd_token_t *token = child->data;
|
||||
struct cmd_token *token = child->data;
|
||||
switch (token->type)
|
||||
{
|
||||
case OPTION_TKN:
|
||||
@ -384,7 +383,7 @@ add_nexthops (struct list *list, struct graph_node *node)
|
||||
* @return minimum match level needed to for a token to fully match
|
||||
*/
|
||||
static enum match_type
|
||||
min_match_level (enum cmd_token_type_t type)
|
||||
min_match_level (enum cmd_token_type type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
@ -406,7 +405,7 @@ min_match_level (enum cmd_token_type_t type)
|
||||
* @return precedence score
|
||||
*/
|
||||
static int
|
||||
score_precedence (enum cmd_token_type_t type)
|
||||
score_precedence (enum cmd_token_type type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
@ -437,9 +436,9 @@ score_precedence (enum cmd_token_type_t type)
|
||||
* @param[in] token the token being matched
|
||||
* @return the best-matching node, or NULL if the two are entirely ambiguous
|
||||
*/
|
||||
static struct cmd_token_t *
|
||||
disambiguate_tokens (struct cmd_token_t *first,
|
||||
struct cmd_token_t *second,
|
||||
static struct cmd_token *
|
||||
disambiguate_tokens (struct cmd_token *first,
|
||||
struct cmd_token *second,
|
||||
char *input_token)
|
||||
{
|
||||
// if the types are different, simply go off of type precedence
|
||||
@ -465,8 +464,8 @@ disambiguate_tokens (struct cmd_token_t *first,
|
||||
/**
|
||||
* Picks the better of two possible matches for an input line.
|
||||
*
|
||||
* @param[in] first candidate list of cmd_token_t matching vline
|
||||
* @param[in] second candidate list of cmd_token_t matching vline
|
||||
* @param[in] first candidate list of cmd_token matching vline
|
||||
* @param[in] second candidate list of cmd_token matching vline
|
||||
* @param[in] vline the input line being matched
|
||||
* @param[in] n index into vline to start comparing at
|
||||
* @return the best-matching list, or NULL if the two are entirely ambiguous
|
||||
@ -483,7 +482,7 @@ disambiguate (struct list *first,
|
||||
|
||||
struct listnode *fnode = listhead (first),
|
||||
*snode = listhead (second);
|
||||
struct cmd_token_t *ftok = listgetdata (fnode),
|
||||
struct cmd_token *ftok = listgetdata (fnode),
|
||||
*stok = listgetdata (snode),
|
||||
*best = NULL;
|
||||
|
||||
@ -527,7 +526,7 @@ del_arglist (struct list *list)
|
||||
/*---------- token level matching functions ----------*/
|
||||
|
||||
static enum match_type
|
||||
match_token (struct cmd_token_t *token, char *input_token)
|
||||
match_token (struct cmd_token *token, char *input_token)
|
||||
{
|
||||
switch (token->type) {
|
||||
case WORD_TKN:
|
||||
@ -761,7 +760,7 @@ match_ipv6_prefix (const char *str)
|
||||
#endif
|
||||
|
||||
static enum match_type
|
||||
match_range (struct cmd_token_t *token, const char *str)
|
||||
match_range (struct cmd_token *token, const char *str)
|
||||
{
|
||||
assert (token->type == RANGE_TKN);
|
||||
|
||||
@ -782,7 +781,7 @@ match_range (struct cmd_token_t *token, const char *str)
|
||||
}
|
||||
|
||||
static enum match_type
|
||||
match_word (struct cmd_token_t *token, const char *word)
|
||||
match_word (struct cmd_token *token, const char *word)
|
||||
{
|
||||
assert (token->type == WORD_TKN);
|
||||
|
||||
@ -804,7 +803,7 @@ match_word (struct cmd_token_t *token, const char *word)
|
||||
}
|
||||
|
||||
static enum match_type
|
||||
match_number (struct cmd_token_t *token, const char *word)
|
||||
match_number (struct cmd_token *token, const char *word)
|
||||
{
|
||||
assert (token->type == NUMBER_TKN);
|
||||
|
||||
@ -819,7 +818,7 @@ match_number (struct cmd_token_t *token, const char *word)
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890:"
|
||||
|
||||
static enum match_type
|
||||
match_variable (struct cmd_token_t *token, const char *word)
|
||||
match_variable (struct cmd_token *token, const char *word)
|
||||
{
|
||||
assert (token->type == VARIABLE_TKN);
|
||||
|
||||
|
@ -36,7 +36,6 @@
|
||||
#include "command.h"
|
||||
#include "graph.h"
|
||||
#include "memory.h"
|
||||
#include "grammar_sandbox.h"
|
||||
|
||||
extern int
|
||||
yylex (void);
|
||||
@ -115,11 +114,11 @@
|
||||
add_edge_dedup (struct graph_node *, struct graph_node *);
|
||||
|
||||
static int
|
||||
cmp_token (struct cmd_token_t *, struct cmd_token_t *);
|
||||
cmp_token (struct cmd_token *, struct cmd_token *);
|
||||
|
||||
static struct graph_node *
|
||||
new_token_node (struct graph *,
|
||||
enum cmd_token_type_t type,
|
||||
enum cmd_token_type type,
|
||||
char *text, char *doc);
|
||||
|
||||
static void
|
||||
@ -250,7 +249,7 @@ placeholder_token:
|
||||
| RANGE
|
||||
{
|
||||
$$ = new_token_node (graph, RANGE_TKN, XSTRDUP(MTYPE_CMD_TOKENS, $1), doc_next());
|
||||
struct cmd_token_t *token = $$->data;
|
||||
struct cmd_token *token = $$->data;
|
||||
|
||||
// get the numbers out
|
||||
yylval.string++;
|
||||
@ -263,7 +262,6 @@ placeholder_token:
|
||||
|
||||
free ($1);
|
||||
}
|
||||
;
|
||||
|
||||
/* <selector|set> productions */
|
||||
selector: '<' selector_seq_seq '>'
|
||||
@ -453,9 +451,9 @@ doc_next()
|
||||
}
|
||||
|
||||
static struct graph_node *
|
||||
new_token_node (struct graph *graph, enum cmd_token_type_t type, char *text, char *doc)
|
||||
new_token_node (struct graph *graph, enum cmd_token_type type, char *text, char *doc)
|
||||
{
|
||||
struct cmd_token_t *token = new_cmd_token (type, text, doc);
|
||||
struct cmd_token *token = new_cmd_token (type, text, doc);
|
||||
return graph_new_node (graph, token, (void (*)(void *)) &del_cmd_token);
|
||||
}
|
||||
|
||||
@ -469,7 +467,7 @@ node_adjacent (struct graph_node *first, struct graph_node *second)
|
||||
for (unsigned int i = 0; i < vector_active (first->to); i++)
|
||||
{
|
||||
adj = vector_slot (first->to, i);
|
||||
struct cmd_token_t *ftok = adj->data,
|
||||
struct cmd_token *ftok = adj->data,
|
||||
*stok = second->data;
|
||||
if (cmp_token (ftok, stok))
|
||||
return adj;
|
||||
@ -503,7 +501,7 @@ add_edge_dedup (struct graph_node *from, struct graph_node *to)
|
||||
* for parsing purposes and determines overall graph structure.
|
||||
*/
|
||||
static int
|
||||
cmp_token (struct cmd_token_t *first, struct cmd_token_t *second)
|
||||
cmp_token (struct cmd_token *first, struct cmd_token *second)
|
||||
{
|
||||
// compare types
|
||||
if (first->type != second->type) return 0;
|
||||
|
20
lib/vty.c
20
lib/vty.c
@ -979,8 +979,6 @@ vty_describe_fold (struct vty *vty, int cmd_width,
|
||||
const char *cmd, *p;
|
||||
int pos;
|
||||
|
||||
cmd = token->cmd[0] == '.' ? token->cmd + 1 : token->cmd;
|
||||
|
||||
if (desc_width <= 0)
|
||||
{
|
||||
vty_out (vty, " %-*s %s%s", cmd_width, cmd, token->desc, VTY_NEWLINE);
|
||||
@ -1056,12 +1054,10 @@ vty_describe_command (struct vty *vty)
|
||||
{
|
||||
unsigned int len;
|
||||
|
||||
if (token->cmd[0] == '\0')
|
||||
if (token->text[0] == '\0')
|
||||
continue;
|
||||
|
||||
len = strlen (token->cmd);
|
||||
if (token->cmd[0] == '.')
|
||||
len--;
|
||||
len = strlen (token->text);
|
||||
|
||||
if (width < len)
|
||||
width = len;
|
||||
@ -1074,10 +1070,10 @@ vty_describe_command (struct vty *vty)
|
||||
for (i = 0; i < vector_active (describe); i++)
|
||||
if ((token = vector_slot (describe, i)) != NULL)
|
||||
{
|
||||
if (token->cmd[0] == '\0')
|
||||
if (token->text[0] == '\0')
|
||||
continue;
|
||||
|
||||
if (strcmp (token->cmd, command_cr) == 0)
|
||||
if (strcmp (token->text, CMD_CR_TEXT) == 0)
|
||||
{
|
||||
token_cr = token;
|
||||
continue;
|
||||
@ -1085,11 +1081,11 @@ vty_describe_command (struct vty *vty)
|
||||
|
||||
if (!token->desc)
|
||||
vty_out (vty, " %-s%s",
|
||||
token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
|
||||
token->text,
|
||||
VTY_NEWLINE);
|
||||
else if (desc_width >= strlen (token->desc))
|
||||
vty_out (vty, " %-*s %s%s", width,
|
||||
token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
|
||||
token->text,
|
||||
token->desc, VTY_NEWLINE);
|
||||
else
|
||||
vty_describe_fold (vty, width, desc_width, token);
|
||||
@ -1105,11 +1101,11 @@ vty_describe_command (struct vty *vty)
|
||||
{
|
||||
if (!token->desc)
|
||||
vty_out (vty, " %-s%s",
|
||||
token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
|
||||
token->text,
|
||||
VTY_NEWLINE);
|
||||
else if (desc_width >= strlen (token->desc))
|
||||
vty_out (vty, " %-*s %s%s", width,
|
||||
token->cmd[0] == '.' ? token->cmd + 1 : token->cmd,
|
||||
token->text,
|
||||
token->desc, VTY_NEWLINE);
|
||||
else
|
||||
vty_describe_fold (vty, width, desc_width, token);
|
||||
|
Loading…
Reference in New Issue
Block a user