summaryrefslogtreecommitdiff
path: root/tools/xml2cli.pl
diff options
context:
space:
mode:
Diffstat (limited to 'tools/xml2cli.pl')
-rwxr-xr-xtools/xml2cli.pl34
1 files changed, 22 insertions, 12 deletions
diff --git a/tools/xml2cli.pl b/tools/xml2cli.pl
index 43789131c3..40f905bcde 100755
--- a/tools/xml2cli.pl
+++ b/tools/xml2cli.pl
@@ -41,17 +41,19 @@ use XML::LibXML;
"ipv4m" => "A.B.C.D/M",
"ipv6" => "X:X::X:X",
"ipv6m" => "X:X::X:X/M",
- "mtu" => "<1500-9180>",
+ "mtu" => "(1500-9180)",
+ "acl_range" => "(1-199)",
+ "acl_expanded_range" => "(1300-2699)",
# BGP specific
"rd" => "ASN:nn_or_IP-address:nn",
- "asn" => "<1-4294967295>",
+ "asn" => "(1-4294967295)",
"community" => "AA:NN",
- "clist" => "<1-500>",
+ "clist" => "(1-500)",
# LDP specific
- "disc_time" => "<1-65535>",
- "session_time" => "<15-65535>",
- "pwid" => "<1-4294967295>",
- "hops" => "<1-254>"
+ "disc_time" => "(1-65535)",
+ "session_time" => "(15-65535)",
+ "pwid" => "(1-4294967295)",
+ "hops" => "(1-254)"
);
# parse options node and store the corresponding information
@@ -91,7 +93,7 @@ sub parse_options {
push (@cmdstr, $name);
$::options{$options_name}{'help'} .= "\n \"" . $help . "\\n\"";
}
- $::options{$options_name}{'cmdstr'} = "(" . join('|', @cmdstr) . ")";
+ $::options{$options_name}{'cmdstr'} = "<" . join('|', @cmdstr) . ">";
}
# given a subtree, replace all the corresponding include nodes by
@@ -122,7 +124,7 @@ sub generate_arguments {
my @nodes = @_;
my $arguments;
my $no_args = 1;
- my $argc = 0;
+ my $argc = -1;
$arguments .= " struct vty_arg *args[] =\n";
$arguments .= " {\n";
@@ -130,6 +132,7 @@ sub generate_arguments {
my %node = %{$nodes[$i]};
my $arg_value;
+ $argc++;
if (not $node{'arg'}) {
next;
}
@@ -139,7 +142,9 @@ sub generate_arguments {
# argv[] element. for the other types of nodes, the value of the
# argument is the name of the node
if ($node{'input'} or $node{'type'} eq "select") {
- $arg_value = "argv[" . $argc++ . "]";
+ $arg_value = "argv[" . $argc . "]->arg";
+ } elsif ($node{'optional'}) {
+ $arg_value = "(argc > " . $argc . " ? argv[" . $argc. "]->arg : NULL)";
} else {
$arg_value = '"' . $node{'name'} . '"';
}
@@ -195,12 +200,16 @@ sub generate_code {
$helpstr .= $::options{$options_name}{'help'};
} else {
$funcname .= $node{'name'} . " ";
- $cmdstr .= $node{'name'} . " ";
+ if ($node{'optional'}) {
+ $cmdstr .= "[" . $node{'name'} . "] ";
+ } else {
+ $cmdstr .= $node{'name'} . " ";
+ }
$helpstr .= "\n \"" . $node{'help'} . "\\n\"";
}
# update the command string
- if ($node{'function'} ne "inherited") {
+ if ($node{'function'} ne "inherited" and $node{'function'}) {
$function = $node{'function'};
}
}
@@ -278,6 +287,7 @@ sub parse_tree {
$node{'help'} = $xml_node->findvalue('./@help');
$node{'function'} = $xml_node->findvalue('./@function');
$node{'ifdef'} = $xml_node->findvalue('./@ifdef');
+ $node{'optional'} = $xml_node->findvalue('./@optional');
# push node to stack
push (@nodes, \%node);