]>
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_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD|VTYSH_EIGRPD";
87 elsif ($file =~ /lib\/vrf\
.c
$/) {
88 $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_EIGRPD";
90 elsif ($file =~ /lib\/filter\
.c
$/) {
91 $protocol = "VTYSH_ALL";
93 elsif ($file =~ /lib\/ns\
.c
$/) {
94 $protocol = "VTYSH_ZEBRA";
96 elsif ($file =~ /lib\/plist\
.c
$/) {
97 if ($defun_array[1] =~ m/ipv6/) {
98 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
100 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD|VTYSH_EIGRPD";
103 elsif ($file =~ /lib\/distribute\
.c
$/) {
104 if ($defun_array[1] =~ m/ipv6/) {
105 $protocol = "VTYSH_RIPNGD";
107 $protocol = "VTYSH_RIPD";
110 elsif ($file =~ /lib\/if_rmap\
.c
$/) {
111 if ($defun_array[1] =~ m/ipv6/) {
112 $protocol = "VTYSH_RIPNGD";
114 $protocol = "VTYSH_RIPD";
117 elsif ($file =~ /lib\/vty\
.c
$/) {
118 $protocol = "VTYSH_ALL";
120 elsif ($file =~ /librfp\/.*\
.c
$/ || $file =~ /rfapi\
/.*\.c$/) {
121 $protocol = "VTYSH_BGPD";
124 ($protocol) = ($file =~ /^.*\/([a-z0-9
]+)\
/[a-zA-Z0-9_\-]+\.c$/);
125 $protocol = "VTYSH_" . uc $protocol;
128 # Append _vtysh to structure then build DEFUN again
129 $defun_array[1] = $cmd . "_vtysh";
130 $defun_body = join (", ", @defun_array);
132 # $cmd -> $str hash for lookup
133 if (exists($cmd2str{$cmd})) {
134 warn "Duplicate CLI Function: $cmd\n";
135 warn "\tFrom cli: $cmd2str{$cmd} to New cli: $str\n";
136 warn "\tOriginal Protocol: $cmd2proto{$cmd} to New Protocol: $protocol\n";
139 $cmd2str{$cmd} = $str;
140 $cmd2defun{$cmd} = $defun_body;
141 $cmd2proto{$cmd} = $protocol;
142 $cmd2hidden{$cmd} = $hidden;
145 # install_element() process
148 @element_array = split (/,/);
151 $enode = $element_array[0];
154 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
156 # VTY command structure.
157 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
162 if (defined ($cmd2str{$ecmd})) {
164 $key = $enode . "," . $cmd2str{$ecmd};
166 $odefun{$key} = $cmd2defun{$ecmd};
168 if ($cmd2hidden{$ecmd}) {
169 $defsh{$key} = "DEFSH_HIDDEN"
171 $defsh{$key} = "DEFSH"
173 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
178 # When we have cli commands that map to the same function name, we
179 # can introduce subtle bugs due to code not being called when
182 # If extract.pl fails with a error message and you've been
183 # modifying the cli, then go back and fix your code to
184 # not have cli command function collisions.
185 # please fix your code before submittal
187 warn "There are $cli_stomp command line stomps\n";
190 # Check finaly alive $cmd;
191 foreach (keys %odefun) {
192 my ($node, $str) = (split (/,/));
193 my ($cmd) = $ocmd{$_};
198 foreach (keys %live) {
202 $proto = join ("|", @{$oproto{$key}});
203 printf "$defsh{$key} ($proto$odefun{$key})\n\n";
206 # Output install_element
213 foreach (keys %odefun) {
214 my ($node, $str) = (split (/,/));
216 $cmd =~ s/_cmd/_cmd_vtysh/;
217 printf " install_element ($node, &$cmd);\n";