mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-15 05:18: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 = \
|
libzebra_la_SOURCES = \
|
||||||
network.c pid_output.c getopt.c getopt1.c daemon.c \
|
network.c pid_output.c getopt.c getopt1.c daemon.c \
|
||||||
checksum.c vector.c linklist.c vty.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 \
|
command.c \
|
||||||
sockunion.c prefix.c thread.c if.c memory.c buffer.c table.c hash.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 \
|
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 = \
|
pkginclude_HEADERS = \
|
||||||
buffer.h checksum.h filter.h getopt.h hash.h \
|
buffer.h checksum.h filter.h getopt.h hash.h \
|
||||||
if.h linklist.h log.h \
|
if.h linklist.h log.h \
|
||||||
graph.h command_match.h grammar_sandbox.h \
|
graph.h command_match.h \
|
||||||
command.h \
|
command.h \
|
||||||
memory.h network.h prefix.h routemap.h distribute.h sockunion.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 \
|
str.h stream.h table.h thread.h vector.h version.h vty.h zebra.h \
|
||||||
|
2949
lib/command.c
2949
lib/command.c
File diff suppressed because it is too large
Load Diff
411
lib/command.h
411
lib/command.h
@ -8,7 +8,7 @@
|
|||||||
* it under the terms of the GNU General Public License as published
|
* it under the terms of the GNU General Public License as published
|
||||||
* by the Free Software Foundation; either version 2, or (at your
|
* by the Free Software Foundation; either version 2, or (at your
|
||||||
* option) any later version.
|
* option) any later version.
|
||||||
*
|
*
|
||||||
* GNU Zebra is distributed in the hope that it will be useful, but
|
* GNU Zebra is distributed in the hope that it will be useful, but
|
||||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
@ -26,6 +26,7 @@
|
|||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "vty.h"
|
#include "vty.h"
|
||||||
#include "lib/route_types.h"
|
#include "lib/route_types.h"
|
||||||
|
#include "graph.h"
|
||||||
|
|
||||||
/* Host configuration variable */
|
/* Host configuration variable */
|
||||||
struct host
|
struct host
|
||||||
@ -60,74 +61,118 @@ struct host
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* There are some command levels which called from command node. */
|
/* There are some command levels which called from command node. */
|
||||||
enum node_type
|
enum node_type
|
||||||
{
|
{
|
||||||
AUTH_NODE, /* Authentication mode of vty interface. */
|
AUTH_NODE, /* Authentication mode of vty interface. */
|
||||||
RESTRICTED_NODE, /* Restricted view mode */
|
RESTRICTED_NODE, /* Restricted view mode */
|
||||||
VIEW_NODE, /* View node. Default mode of vty interface. */
|
VIEW_NODE, /* View node. Default mode of vty interface. */
|
||||||
AUTH_ENABLE_NODE, /* Authentication mode for change enable. */
|
AUTH_ENABLE_NODE, /* Authentication mode for change enable. */
|
||||||
ENABLE_NODE, /* Enable node. */
|
ENABLE_NODE, /* Enable node. */
|
||||||
CONFIG_NODE, /* Config node. Default mode of config file. */
|
CONFIG_NODE, /* Config node. Default mode of config file. */
|
||||||
SERVICE_NODE, /* Service node. */
|
SERVICE_NODE, /* Service node. */
|
||||||
DEBUG_NODE, /* Debug node. */
|
DEBUG_NODE, /* Debug node. */
|
||||||
VRF_DEBUG_NODE, /* Vrf Debug node. */
|
VRF_DEBUG_NODE, /* Vrf Debug node. */
|
||||||
AAA_NODE, /* AAA node. */
|
AAA_NODE, /* AAA node. */
|
||||||
KEYCHAIN_NODE, /* Key-chain node. */
|
KEYCHAIN_NODE, /* Key-chain node. */
|
||||||
KEYCHAIN_KEY_NODE, /* Key-chain key node. */
|
KEYCHAIN_KEY_NODE, /* Key-chain key node. */
|
||||||
VRF_NODE, /* VRF mode node. */
|
VRF_NODE, /* VRF mode node. */
|
||||||
INTERFACE_NODE, /* Interface mode node. */
|
INTERFACE_NODE, /* Interface mode node. */
|
||||||
ZEBRA_NODE, /* zebra connection node. */
|
ZEBRA_NODE, /* zebra connection node. */
|
||||||
TABLE_NODE, /* rtm_table selection node. */
|
TABLE_NODE, /* rtm_table selection node. */
|
||||||
RIP_NODE, /* RIP protocol mode node. */
|
RIP_NODE, /* RIP protocol mode node. */
|
||||||
RIPNG_NODE, /* RIPng protocol mode node. */
|
RIPNG_NODE, /* RIPng protocol mode node. */
|
||||||
BGP_NODE, /* BGP protocol mode which includes BGP4+ */
|
BGP_NODE, /* BGP protocol mode which includes BGP4+ */
|
||||||
BGP_VPNV4_NODE, /* BGP MPLS-VPN PE exchange. */
|
BGP_VPNV4_NODE, /* BGP MPLS-VPN PE exchange. */
|
||||||
BGP_VPNV6_NODE, /* BGP MPLS-VPN PE exchange. */
|
BGP_VPNV6_NODE, /* BGP MPLS-VPN PE exchange. */
|
||||||
BGP_IPV4_NODE, /* BGP IPv4 unicast address family. */
|
BGP_IPV4_NODE, /* BGP IPv4 unicast address family. */
|
||||||
BGP_IPV4M_NODE, /* BGP IPv4 multicast address family. */
|
BGP_IPV4M_NODE, /* BGP IPv4 multicast address family. */
|
||||||
BGP_IPV6_NODE, /* BGP IPv6 address family */
|
BGP_IPV6_NODE, /* BGP IPv6 address family */
|
||||||
BGP_IPV6M_NODE, /* BGP IPv6 multicast address family. */
|
BGP_IPV6M_NODE, /* BGP IPv6 multicast address family. */
|
||||||
BGP_ENCAP_NODE, /* BGP ENCAP SAFI */
|
BGP_ENCAP_NODE, /* BGP ENCAP SAFI */
|
||||||
BGP_ENCAPV6_NODE, /* BGP ENCAP SAFI */
|
BGP_ENCAPV6_NODE, /* BGP ENCAP SAFI */
|
||||||
OSPF_NODE, /* OSPF protocol mode */
|
OSPF_NODE, /* OSPF protocol mode */
|
||||||
OSPF6_NODE, /* OSPF protocol for IPv6 mode */
|
OSPF6_NODE, /* OSPF protocol for IPv6 mode */
|
||||||
ISIS_NODE, /* ISIS protocol mode */
|
ISIS_NODE, /* ISIS protocol mode */
|
||||||
PIM_NODE, /* PIM protocol mode */
|
PIM_NODE, /* PIM protocol mode */
|
||||||
MASC_NODE, /* MASC for multicast. */
|
MASC_NODE, /* MASC for multicast. */
|
||||||
IRDP_NODE, /* ICMP Router Discovery Protocol mode. */
|
IRDP_NODE, /* ICMP Router Discovery Protocol mode. */
|
||||||
IP_NODE, /* Static ip route node. */
|
IP_NODE, /* Static ip route node. */
|
||||||
ACCESS_NODE, /* Access list node. */
|
ACCESS_NODE, /* Access list node. */
|
||||||
PREFIX_NODE, /* Prefix list node. */
|
PREFIX_NODE, /* Prefix list node. */
|
||||||
ACCESS_IPV6_NODE, /* Access list node. */
|
ACCESS_IPV6_NODE, /* Access list node. */
|
||||||
PREFIX_IPV6_NODE, /* Prefix list node. */
|
PREFIX_IPV6_NODE, /* Prefix list node. */
|
||||||
AS_LIST_NODE, /* AS list node. */
|
AS_LIST_NODE, /* AS list node. */
|
||||||
COMMUNITY_LIST_NODE, /* Community list node. */
|
COMMUNITY_LIST_NODE, /* Community list node. */
|
||||||
RMAP_NODE, /* Route map node. */
|
RMAP_NODE, /* Route map node. */
|
||||||
SMUX_NODE, /* SNMP configuration node. */
|
SMUX_NODE, /* SNMP configuration node. */
|
||||||
DUMP_NODE, /* Packet dump node. */
|
DUMP_NODE, /* Packet dump node. */
|
||||||
FORWARDING_NODE, /* IP forwarding node. */
|
FORWARDING_NODE, /* IP forwarding node. */
|
||||||
PROTOCOL_NODE, /* protocol filtering node */
|
PROTOCOL_NODE, /* protocol filtering node */
|
||||||
VTY_NODE, /* Vty node. */
|
VTY_NODE, /* Vty node. */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Node which has some commands and prompt string and configuration
|
/* Node which has some commands and prompt string and configuration
|
||||||
function pointer . */
|
function pointer . */
|
||||||
struct cmd_node
|
struct cmd_node
|
||||||
{
|
{
|
||||||
/* Node index. */
|
/* Node index. */
|
||||||
enum node_type node;
|
enum node_type node;
|
||||||
|
|
||||||
/* Prompt character at vty interface. */
|
/* Prompt character at vty interface. */
|
||||||
const char *prompt;
|
const char *prompt;
|
||||||
|
|
||||||
/* Is this node's configuration goes to vtysh ? */
|
/* Is this node's configuration goes to vtysh ? */
|
||||||
int vtysh;
|
int vtysh;
|
||||||
|
|
||||||
/* Node's configuration write function */
|
/* Node's configuration write function */
|
||||||
int (*func) (struct vty *);
|
int (*func) (struct vty *);
|
||||||
|
|
||||||
|
/* Node's command graph */
|
||||||
|
struct graph *cmdgraph;
|
||||||
|
|
||||||
/* Vector of this node's command list. */
|
/* Vector of this node's command list. */
|
||||||
vector cmd_vector;
|
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
|
enum
|
||||||
@ -137,56 +182,15 @@ enum
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* Structure of command element. */
|
/* Structure of command element. */
|
||||||
struct cmd_element
|
struct cmd_element
|
||||||
{
|
{
|
||||||
const char *string; /* Command specification by string. */
|
const char *string; /* Command specification by string. */
|
||||||
int (*func) (struct cmd_element *, struct vty *, int, const char *[]);
|
const char *doc; /* Documentation of this command. */
|
||||||
const char *doc; /* Documentation of this command. */
|
|
||||||
int daemon; /* Daemon to which this command belong. */
|
int daemon; /* Daemon to which this command belong. */
|
||||||
vector tokens; /* Vector of cmd_tokens */
|
u_char attr; /* Command attributes */
|
||||||
u_char attr; /* Command attributes */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
/* handler function for command */
|
||||||
enum cmd_token_type
|
int (*func) (struct cmd_element *, struct vty *, int, struct cmd_token *[]);
|
||||||
{
|
|
||||||
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. */
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Return value of the commands. */
|
/* Return value of the commands. */
|
||||||
@ -207,7 +211,7 @@ struct cmd_token
|
|||||||
#define CMD_ARGC_MAX 25
|
#define CMD_ARGC_MAX 25
|
||||||
|
|
||||||
/* Turn off these macros when uisng cpp with extract.pl */
|
/* Turn off these macros when uisng cpp with extract.pl */
|
||||||
#ifndef VTYSH_EXTRACT_PL
|
#ifndef VTYSH_EXTRACT_PL
|
||||||
|
|
||||||
/* helper defines for end-user DEFUN* macros */
|
/* helper defines for end-user DEFUN* macros */
|
||||||
#define DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attrs, dnum) \
|
#define DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, attrs, dnum) \
|
||||||
@ -221,179 +225,15 @@ struct cmd_token
|
|||||||
};
|
};
|
||||||
|
|
||||||
#define DEFUN_CMD_FUNC_DECL(funcname) \
|
#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) \
|
#define DEFUN_CMD_FUNC_TEXT(funcname) \
|
||||||
static int funcname \
|
static int funcname \
|
||||||
(struct cmd_element *self __attribute__ ((unused)), \
|
(struct cmd_element *self __attribute__ ((unused)), \
|
||||||
struct vty *vty __attribute__ ((unused)), \
|
struct vty *vty __attribute__ ((unused)), \
|
||||||
int argc __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) \
|
#define DEFUN(funcname, cmdname, cmdstr, helpstr) \
|
||||||
DEFUN_CMD_FUNC_DECL(funcname) \
|
DEFUN_CMD_FUNC_DECL(funcname) \
|
||||||
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \
|
DEFUN_CMD_ELEMENT(funcname, cmdname, cmdstr, helpstr, 0, 0) \
|
||||||
@ -506,41 +346,41 @@ struct cmd_token
|
|||||||
#define IP6_STR "IPv6 Information\n"
|
#define IP6_STR "IPv6 Information\n"
|
||||||
#define OSPF6_STR "Open Shortest Path First (OSPF) for IPv6\n"
|
#define OSPF6_STR "Open Shortest Path First (OSPF) for IPv6\n"
|
||||||
#define OSPF6_ROUTER_STR "Enable a routing process\n"
|
#define OSPF6_ROUTER_STR "Enable a routing process\n"
|
||||||
#define OSPF6_INSTANCE_STR "<1-65535> Instance ID\n"
|
#define OSPF6_INSTANCE_STR "(1-65535) Instance ID\n"
|
||||||
#define SECONDS_STR "<1-65535> Seconds\n"
|
#define SECONDS_STR "(1-65535) Seconds\n"
|
||||||
#define ROUTE_STR "Routing Table\n"
|
#define ROUTE_STR "Routing Table\n"
|
||||||
#define PREFIX_LIST_STR "Build a prefix list\n"
|
#define PREFIX_LIST_STR "Build a prefix list\n"
|
||||||
#define OSPF6_DUMP_TYPE_LIST \
|
#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 ISIS_STR "IS-IS information\n"
|
||||||
#define AREA_TAG_STR "[area tag]\n"
|
#define AREA_TAG_STR "[area tag]\n"
|
||||||
#define COMMUNITY_AANN_STR "Community number where AA and NN are <0-65535>\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_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"
|
#define CONF_BACKUP_EXT ".sav"
|
||||||
|
|
||||||
/* IPv4 only machine should not accept IPv6 address for peer's IP
|
/* IPv4 only machine should not accept IPv6 address for peer's IP
|
||||||
address. So we replace VTY command string like below. */
|
address. So we replace VTY command string like below. */
|
||||||
#ifdef HAVE_IPV6
|
#ifdef HAVE_IPV6
|
||||||
#define NEIGHBOR_CMD "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 NO_NEIGHBOR_CMD "no neighbor <A.B.C.D|X:X::X:X> "
|
||||||
#define NEIGHBOR_ADDR_STR "Neighbor address\nIPv6 address\n"
|
#define NEIGHBOR_ADDR_STR "Neighbor address\nIPv6 address\n"
|
||||||
#define NEIGHBOR_CMD2 "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 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_STR2 "Neighbor address\nNeighbor IPv6 address\nInterface name or neighbor tag\n"
|
||||||
#define NEIGHBOR_ADDR_STR3 "Neighbor address\nIPv6 address\nInterface name\n"
|
#define NEIGHBOR_ADDR_STR3 "Neighbor address\nIPv6 address\nInterface name\n"
|
||||||
#else
|
#else
|
||||||
#define NEIGHBOR_CMD "neighbor A.B.C.D "
|
#define NEIGHBOR_CMD "neighbor A.B.C.D "
|
||||||
#define NO_NEIGHBOR_CMD "no neighbor A.B.C.D "
|
#define NO_NEIGHBOR_CMD "no neighbor A.B.C.D "
|
||||||
#define NEIGHBOR_ADDR_STR "Neighbor address\n"
|
#define NEIGHBOR_ADDR_STR "Neighbor address\n"
|
||||||
#define NEIGHBOR_CMD2 "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 NO_NEIGHBOR_CMD2 "no neighbor <A.B.C.D|WORD> "
|
||||||
#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor tag\n"
|
#define NEIGHBOR_ADDR_STR2 "Neighbor address\nNeighbor tag\n"
|
||||||
#endif /* HAVE_IPV6 */
|
#endif /* HAVE_IPV6 */
|
||||||
|
|
||||||
/* Dynamic neighbor (listen range) configuration */
|
/* Dynamic neighbor (listen range) configuration */
|
||||||
#ifdef HAVE_IPV6
|
#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"
|
#define LISTEN_RANGE_ADDR_STR "Neighbor address\nNeighbor IPv6 address\n"
|
||||||
#else
|
#else
|
||||||
#define LISTEN_RANGE_CMD "bgp listen range A.B.C.D/M "
|
#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
|
/* Concatenates argv[shift] through argv[argc-1] into a single NUL-terminated
|
||||||
string with a space between each element (allocated using
|
string with a space between each element (allocated using
|
||||||
XMALLOC(MTYPE_TMP)). Returns NULL if shift >= argc. */
|
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 vector cmd_make_strvec (const char *);
|
||||||
extern void cmd_free_strvec (vector);
|
extern void cmd_free_strvec (vector);
|
||||||
@ -577,6 +417,14 @@ del_cmd_element(struct cmd_element *);
|
|||||||
struct cmd_element *
|
struct cmd_element *
|
||||||
copy_cmd_element(struct cmd_element *cmd);
|
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. */
|
/* Export typical functions. */
|
||||||
extern struct cmd_element config_end_cmd;
|
extern struct cmd_element config_end_cmd;
|
||||||
extern struct cmd_element config_exit_cmd;
|
extern struct cmd_element config_exit_cmd;
|
||||||
@ -591,8 +439,9 @@ extern void print_version (const char *);
|
|||||||
extern int cmd_banner_motd_file (const char *);
|
extern int cmd_banner_motd_file (const char *);
|
||||||
|
|
||||||
/* struct host global, ick */
|
/* struct host global, ick */
|
||||||
extern struct host host;
|
extern struct host host;
|
||||||
|
|
||||||
|
/* text for <cr> command */
|
||||||
|
#define CMD_CR_TEXT "<cr>"
|
||||||
|
|
||||||
/* "<cr>" global */
|
|
||||||
extern char *command_cr;
|
|
||||||
#endif /* _ZEBRA_COMMAND_H */
|
#endif /* _ZEBRA_COMMAND_H */
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
#include <zebra.h>
|
#include <zebra.h>
|
||||||
#include "command_match.h"
|
#include "command_match.h"
|
||||||
#include "command_parse.h"
|
#include "command_parse.h"
|
||||||
#include "grammar_sandbox.h"
|
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
|
||||||
/* matcher helper prototypes */
|
/* matcher helper prototypes */
|
||||||
@ -36,16 +35,16 @@ static struct list *
|
|||||||
command_match_r (struct graph_node *, vector, unsigned int);
|
command_match_r (struct graph_node *, vector, unsigned int);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
score_precedence (enum cmd_token_type_t);
|
score_precedence (enum cmd_token_type);
|
||||||
|
|
||||||
static enum match_type
|
static enum match_type
|
||||||
min_match_level (enum cmd_token_type_t);
|
min_match_level (enum cmd_token_type);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
del_arglist (struct list *);
|
del_arglist (struct list *);
|
||||||
|
|
||||||
static struct cmd_token_t *
|
static struct cmd_token *
|
||||||
disambiguate_tokens (struct cmd_token_t *, struct cmd_token_t *, char *);
|
disambiguate_tokens (struct cmd_token *, struct cmd_token *, char *);
|
||||||
|
|
||||||
static struct list *
|
static struct list *
|
||||||
disambiguate (struct list *, struct list *, vector, unsigned int);
|
disambiguate (struct list *, struct list *, vector, unsigned int);
|
||||||
@ -55,7 +54,7 @@ compare_completions (const void *, const void *);
|
|||||||
|
|
||||||
/* token matcher prototypes */
|
/* token matcher prototypes */
|
||||||
static enum match_type
|
static enum match_type
|
||||||
match_token (struct cmd_token_t *, char *);
|
match_token (struct cmd_token *, char *);
|
||||||
|
|
||||||
static enum match_type
|
static enum match_type
|
||||||
match_ipv4 (const char *);
|
match_ipv4 (const char *);
|
||||||
@ -70,16 +69,16 @@ static enum match_type
|
|||||||
match_ipv6_prefix (const char *);
|
match_ipv6_prefix (const char *);
|
||||||
|
|
||||||
static enum match_type
|
static enum match_type
|
||||||
match_range (struct cmd_token_t *, const char *);
|
match_range (struct cmd_token *, const char *);
|
||||||
|
|
||||||
static enum match_type
|
static enum match_type
|
||||||
match_word (struct cmd_token_t *, const char *);
|
match_word (struct cmd_token *, const char *);
|
||||||
|
|
||||||
static enum match_type
|
static enum match_type
|
||||||
match_number (struct cmd_token_t *, const char *);
|
match_number (struct cmd_token *, const char *);
|
||||||
|
|
||||||
static enum match_type
|
static enum match_type
|
||||||
match_variable (struct cmd_token_t *, const char *);
|
match_variable (struct cmd_token *, const char *);
|
||||||
|
|
||||||
/* matching functions */
|
/* matching functions */
|
||||||
static enum matcher_rv matcher_rv;
|
static enum matcher_rv matcher_rv;
|
||||||
@ -105,7 +104,7 @@ command_match (struct graph *cmdgraph,
|
|||||||
struct listnode *tail = listtail (*argv);
|
struct listnode *tail = listtail (*argv);
|
||||||
|
|
||||||
// delete dummy start node
|
// 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);
|
list_delete_node (*argv, head);
|
||||||
|
|
||||||
// get cmd_element out of list tail
|
// 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));
|
assert (n < vector_active (vline));
|
||||||
|
|
||||||
// get the minimum match level that can count as a full match
|
// 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);
|
enum match_type minmatch = min_match_level (token->type);
|
||||||
|
|
||||||
// get the current operating input token
|
// 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 we've matched all input we're looking for END_TKN
|
||||||
if (n+1 == vector_active (vline))
|
if (n+1 == vector_active (vline))
|
||||||
{
|
{
|
||||||
struct cmd_token_t *tok = gn->data;
|
struct cmd_token *tok = gn->data;
|
||||||
if (tok->type == END_TKN)
|
if (tok->type == END_TKN)
|
||||||
{
|
{
|
||||||
currbest = list_new();
|
currbest = list_new();
|
||||||
@ -255,8 +254,8 @@ command_match_r (struct graph_node *start, vector vline, unsigned int n)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// copy token, set arg and prepend to currbest
|
// copy token, set arg and prepend to currbest
|
||||||
struct cmd_token_t *token = start->data;
|
struct cmd_token *token = start->data;
|
||||||
struct cmd_token_t *copy = copy_cmd_token (token);
|
struct cmd_token *copy = copy_cmd_token (token);
|
||||||
copy->arg = XSTRDUP (MTYPE_CMD_TOKENS, input_token);
|
copy->arg = XSTRDUP (MTYPE_CMD_TOKENS, input_token);
|
||||||
list_add_node_prev (currbest, currbest->head, copy);
|
list_add_node_prev (currbest, currbest->head, copy);
|
||||||
matcher_rv = MATCHER_OK;
|
matcher_rv = MATCHER_OK;
|
||||||
@ -301,7 +300,7 @@ command_complete (struct graph *graph,
|
|||||||
|
|
||||||
for (ALL_LIST_ELEMENTS_RO (current,node,gn))
|
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))
|
switch (match_token (token, input_token))
|
||||||
{
|
{
|
||||||
case partly_match:
|
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++)
|
for (unsigned int i = 0; i < vector_active (node->to); i++)
|
||||||
{
|
{
|
||||||
child = vector_slot (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)
|
switch (token->type)
|
||||||
{
|
{
|
||||||
case OPTION_TKN:
|
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
|
* @return minimum match level needed to for a token to fully match
|
||||||
*/
|
*/
|
||||||
static enum match_type
|
static enum match_type
|
||||||
min_match_level (enum cmd_token_type_t type)
|
min_match_level (enum cmd_token_type type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
@ -406,7 +405,7 @@ min_match_level (enum cmd_token_type_t type)
|
|||||||
* @return precedence score
|
* @return precedence score
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
score_precedence (enum cmd_token_type_t type)
|
score_precedence (enum cmd_token_type type)
|
||||||
{
|
{
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
@ -437,9 +436,9 @@ score_precedence (enum cmd_token_type_t type)
|
|||||||
* @param[in] token the token being matched
|
* @param[in] token the token being matched
|
||||||
* @return the best-matching node, or NULL if the two are entirely ambiguous
|
* @return the best-matching node, or NULL if the two are entirely ambiguous
|
||||||
*/
|
*/
|
||||||
static struct cmd_token_t *
|
static struct cmd_token *
|
||||||
disambiguate_tokens (struct cmd_token_t *first,
|
disambiguate_tokens (struct cmd_token *first,
|
||||||
struct cmd_token_t *second,
|
struct cmd_token *second,
|
||||||
char *input_token)
|
char *input_token)
|
||||||
{
|
{
|
||||||
// if the types are different, simply go off of type precedence
|
// 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.
|
* Picks the better of two possible matches for an input line.
|
||||||
*
|
*
|
||||||
* @param[in] first 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_t matching vline
|
* @param[in] second candidate list of cmd_token matching vline
|
||||||
* @param[in] vline the input line being matched
|
* @param[in] vline the input line being matched
|
||||||
* @param[in] n index into vline to start comparing at
|
* @param[in] n index into vline to start comparing at
|
||||||
* @return the best-matching list, or NULL if the two are entirely ambiguous
|
* @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),
|
struct listnode *fnode = listhead (first),
|
||||||
*snode = listhead (second);
|
*snode = listhead (second);
|
||||||
struct cmd_token_t *ftok = listgetdata (fnode),
|
struct cmd_token *ftok = listgetdata (fnode),
|
||||||
*stok = listgetdata (snode),
|
*stok = listgetdata (snode),
|
||||||
*best = NULL;
|
*best = NULL;
|
||||||
|
|
||||||
@ -527,7 +526,7 @@ del_arglist (struct list *list)
|
|||||||
/*---------- token level matching functions ----------*/
|
/*---------- token level matching functions ----------*/
|
||||||
|
|
||||||
static enum match_type
|
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) {
|
switch (token->type) {
|
||||||
case WORD_TKN:
|
case WORD_TKN:
|
||||||
@ -761,7 +760,7 @@ match_ipv6_prefix (const char *str)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
static enum match_type
|
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);
|
assert (token->type == RANGE_TKN);
|
||||||
|
|
||||||
@ -782,7 +781,7 @@ match_range (struct cmd_token_t *token, const char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static enum match_type
|
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);
|
assert (token->type == WORD_TKN);
|
||||||
|
|
||||||
@ -804,7 +803,7 @@ match_word (struct cmd_token_t *token, const char *word)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static enum match_type
|
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);
|
assert (token->type == NUMBER_TKN);
|
||||||
|
|
||||||
@ -819,7 +818,7 @@ match_number (struct cmd_token_t *token, const char *word)
|
|||||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890:"
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890:"
|
||||||
|
|
||||||
static enum match_type
|
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);
|
assert (token->type == VARIABLE_TKN);
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@
|
|||||||
#include "command.h"
|
#include "command.h"
|
||||||
#include "graph.h"
|
#include "graph.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
#include "grammar_sandbox.h"
|
|
||||||
|
|
||||||
extern int
|
extern int
|
||||||
yylex (void);
|
yylex (void);
|
||||||
@ -115,11 +114,11 @@
|
|||||||
add_edge_dedup (struct graph_node *, struct graph_node *);
|
add_edge_dedup (struct graph_node *, struct graph_node *);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cmp_token (struct cmd_token_t *, struct cmd_token_t *);
|
cmp_token (struct cmd_token *, struct cmd_token *);
|
||||||
|
|
||||||
static struct graph_node *
|
static struct graph_node *
|
||||||
new_token_node (struct graph *,
|
new_token_node (struct graph *,
|
||||||
enum cmd_token_type_t type,
|
enum cmd_token_type type,
|
||||||
char *text, char *doc);
|
char *text, char *doc);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -250,7 +249,7 @@ placeholder_token:
|
|||||||
| RANGE
|
| RANGE
|
||||||
{
|
{
|
||||||
$$ = new_token_node (graph, RANGE_TKN, XSTRDUP(MTYPE_CMD_TOKENS, $1), doc_next());
|
$$ = 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
|
// get the numbers out
|
||||||
yylval.string++;
|
yylval.string++;
|
||||||
@ -263,7 +262,6 @@ placeholder_token:
|
|||||||
|
|
||||||
free ($1);
|
free ($1);
|
||||||
}
|
}
|
||||||
;
|
|
||||||
|
|
||||||
/* <selector|set> productions */
|
/* <selector|set> productions */
|
||||||
selector: '<' selector_seq_seq '>'
|
selector: '<' selector_seq_seq '>'
|
||||||
@ -453,9 +451,9 @@ doc_next()
|
|||||||
}
|
}
|
||||||
|
|
||||||
static struct graph_node *
|
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);
|
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++)
|
for (unsigned int i = 0; i < vector_active (first->to); i++)
|
||||||
{
|
{
|
||||||
adj = vector_slot (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;
|
*stok = second->data;
|
||||||
if (cmp_token (ftok, stok))
|
if (cmp_token (ftok, stok))
|
||||||
return adj;
|
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.
|
* for parsing purposes and determines overall graph structure.
|
||||||
*/
|
*/
|
||||||
static int
|
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
|
// compare types
|
||||||
if (first->type != second->type) return 0;
|
if (first->type != second->type) return 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user