]>
git.proxmox.com Git - mirror_frr.git/blob - vtysh/extract.pl.in
5 ## Virtual terminal interface shell command extractor.
6 ## Copyright (C) 2000 Kunihiro Ishiguro
8 ## This file is part of GNU Zebra.
10 ## GNU Zebra is free software; you can redistribute it and/or modify it
11 ## under the terms of the GNU General Public License as published by the
12 ## Free Software Foundation; either version 2, or (at your option) any
15 ## GNU Zebra is distributed in the hope that it will be useful, but
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ## General Public License for more details.
20 ## You should have received a copy of the GNU General Public License
21 ## along with GNU Zebra; see the file COPYING. If not, write to the Free
22 ## Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
41 open (FH
, "@CPP@ -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -I@top_builddir@ -I@srcdir@/ -I@srcdir@/.. -I@top_srcdir@/lib -I@top_builddir@/lib -I@top_srcdir@/bgpd -I@top_srcdir@/@LIBRFP@ -I@top_srcdir@/bgpd/rfapi @CPPFLAGS@ $file |");
46 # ?: makes a group non-capturing
47 @defun = ($line =~ /((?:DEFUN|DEFUN_HIDDEN|ALIAS|ALIAS_HIDDEN)\s*\(.+?\));?\s?\s?\n/sg);
48 @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
52 # $_ will contain the entire string including the DEFUN, ALIAS, etc.
53 # We need to extract the DEFUN/ALIAS from everything in ()s.
54 # The /s at the end tells the regex to allow . to match newlines.
55 $_ =~ /^(.*?)\s*\((.*)\)$/s;
59 @defun_array = split (/,/, $2);
61 if ($defun_or_alias =~ /_HIDDEN/) {
69 # Actual input command string.
70 $str = "$defun_array[2]";
74 # Get VTY command structure. This is needed for searching
75 # install_element() command.
76 $cmd = "$defun_array[1]";
80 # $protocol is VTYSH_PROTO format for redirection of user input
81 if ($file =~ /lib\/keychain\
.c
$/) {
82 $protocol = "VTYSH_RIPD";
84 elsif ($file =~ /lib\/routemap\
.c
$/) {
85 $protocol = "VTYSH_RMAP";
87 elsif ($file =~ /lib\/vrf\
.c
$/) {
88 $protocol = "VTYSH_VRF";
90 elsif ($file =~ /lib\/if\
.c
$/) {
91 $protocol = "VTYSH_INTERFACE";
93 elsif ($file =~ /lib\/logicalrouter\
.c
$/) {
94 $protocol = "VTYSH_ALL";
96 elsif ($file =~ /lib\/filter\
.c
$/) {
97 $protocol = "VTYSH_ALL";
99 elsif ($file =~ /lib\/agentx\
.c
$/) {
100 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
102 elsif ($file =~ /lib\/ns\
.c
$/) {
103 $protocol = "VTYSH_ZEBRA";
105 elsif ($file =~ /lib\/nexthop_group\
.c
$/) {
106 $protocol = "VTYSH_PBRD";
108 elsif ($file =~ /lib\/plist\
.c
$/) {
109 if ($defun_array[1] =~ m/ipv6/) {
110 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_BABELD|VTYSH_ISISD";
112 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_ISISD";
115 elsif ($file =~ /lib\/distribute\
.c
$/) {
116 if ($defun_array[1] =~ m/ipv6/) {
117 $protocol = "VTYSH_RIPNGD";
119 $protocol = "VTYSH_RIPD";
122 elsif ($file =~ /lib\/if_rmap\
.c
$/) {
123 if ($defun_array[1] =~ m/ipv6/) {
124 $protocol = "VTYSH_RIPNGD";
126 $protocol = "VTYSH_RIPD";
129 elsif ($file =~ /lib\/vty\
.c
$/) {
130 $protocol = "VTYSH_ALL";
132 elsif ($file =~ /librfp\/.*\
.c
$/ || $file =~ /rfapi\
/.*\.c$/) {
133 $protocol = "VTYSH_BGPD";
136 ($protocol) = ($file =~ /^.*\/([a-z0-9
]+)\
/[a-zA-Z0-9_\-]+\.c$/);
137 $protocol = "VTYSH_" . uc $protocol;
140 # Append _vtysh to structure then build DEFUN again
141 $defun_array[1] = $cmd . "_vtysh";
142 $defun_body = join (", ", @defun_array);
144 # $cmd -> $str hash for lookup
145 if (exists($cmd2str{$cmd})) {
146 warn "Duplicate CLI Function: $cmd\n";
147 warn "\tFrom cli: $cmd2str{$cmd} to New cli: $str\n";
148 warn "\tOriginal Protocol: $cmd2proto{$cmd} to New Protocol: $protocol\n";
151 $cmd2str{$cmd} = $str;
152 $cmd2defun{$cmd} = $defun_body;
153 $cmd2proto{$cmd} = $protocol;
154 $cmd2hidden{$cmd} = $hidden;
157 # install_element() process
160 @element_array = split (/,/);
163 $enode = $element_array[0];
166 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
168 # VTY command structure.
169 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
174 if (defined ($cmd2str{$ecmd})) {
176 $key = $enode . "," . $cmd2str{$ecmd};
178 $odefun{$key} = $cmd2defun{$ecmd};
180 if ($cmd2hidden{$ecmd}) {
181 $defsh{$key} = "DEFSH_HIDDEN"
183 $defsh{$key} = "DEFSH"
185 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
190 # When we have cli commands that map to the same function name, we
191 # can introduce subtle bugs due to code not being called when
194 # If extract.pl fails with a error message and you've been
195 # modifying the cli, then go back and fix your code to
196 # not have cli command function collisions.
197 # please fix your code before submittal
199 warn "There are $cli_stomp command line stomps\n";
202 # Check finaly alive $cmd;
203 foreach (keys %odefun) {
204 my ($node, $str) = (split (/,/));
205 my ($cmd) = $ocmd{$_};
210 foreach (sort keys %live) {
214 $proto = join ("|", @{$oproto{$key}});
215 printf "$defsh{$key} ($proto$odefun{$key})\n\n";
218 # Output install_element
225 foreach (sort keys %odefun) {
226 my ($node, $str) = (split (/,/));
228 $cmd =~ s/_cmd/_cmd_vtysh/;
229 printf " install_element ($node, &$cmd);\n";