]>
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|VTYSH_BABELD";
90 elsif ($file =~ /lib\/filter\
.c
$/) {
91 $protocol = "VTYSH_ALL";
93 elsif ($file =~ /lib\/agentx\
.c
$/) {
94 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
96 elsif ($file =~ /lib\/ns\
.c
$/) {
97 $protocol = "VTYSH_ZEBRA";
99 elsif ($file =~ /lib\/plist\
.c
$/) {
100 if ($defun_array[1] =~ m/ipv6/) {
101 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_BABELD";
103 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_BABELD";
106 elsif ($file =~ /lib\/distribute\
.c
$/) {
107 if ($defun_array[1] =~ m/ipv6/) {
108 $protocol = "VTYSH_RIPNGD";
110 $protocol = "VTYSH_RIPD";
113 elsif ($file =~ /lib\/if_rmap\
.c
$/) {
114 if ($defun_array[1] =~ m/ipv6/) {
115 $protocol = "VTYSH_RIPNGD";
117 $protocol = "VTYSH_RIPD";
120 elsif ($file =~ /lib\/vty\
.c
$/) {
121 $protocol = "VTYSH_ALL";
123 elsif ($file =~ /librfp\/.*\
.c
$/ || $file =~ /rfapi\
/.*\.c$/) {
124 $protocol = "VTYSH_BGPD";
127 ($protocol) = ($file =~ /^.*\/([a-z0-9
]+)\
/[a-zA-Z0-9_\-]+\.c$/);
128 $protocol = "VTYSH_" . uc $protocol;
131 # Append _vtysh to structure then build DEFUN again
132 $defun_array[1] = $cmd . "_vtysh";
133 $defun_body = join (", ", @defun_array);
135 # $cmd -> $str hash for lookup
136 if (exists($cmd2str{$cmd})) {
137 warn "Duplicate CLI Function: $cmd\n";
138 warn "\tFrom cli: $cmd2str{$cmd} to New cli: $str\n";
139 warn "\tOriginal Protocol: $cmd2proto{$cmd} to New Protocol: $protocol\n";
142 $cmd2str{$cmd} = $str;
143 $cmd2defun{$cmd} = $defun_body;
144 $cmd2proto{$cmd} = $protocol;
145 $cmd2hidden{$cmd} = $hidden;
148 # install_element() process
151 @element_array = split (/,/);
154 $enode = $element_array[0];
157 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
159 # VTY command structure.
160 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
165 if (defined ($cmd2str{$ecmd})) {
167 $key = $enode . "," . $cmd2str{$ecmd};
169 $odefun{$key} = $cmd2defun{$ecmd};
171 if ($cmd2hidden{$ecmd}) {
172 $defsh{$key} = "DEFSH_HIDDEN"
174 $defsh{$key} = "DEFSH"
176 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
181 # When we have cli commands that map to the same function name, we
182 # can introduce subtle bugs due to code not being called when
185 # If extract.pl fails with a error message and you've been
186 # modifying the cli, then go back and fix your code to
187 # not have cli command function collisions.
188 # please fix your code before submittal
190 warn "There are $cli_stomp command line stomps\n";
193 # Check finaly alive $cmd;
194 foreach (keys %odefun) {
195 my ($node, $str) = (split (/,/));
196 my ($cmd) = $ocmd{$_};
201 foreach (keys %live) {
205 $proto = join ("|", @{$oproto{$key}});
206 printf "$defsh{$key} ($proto$odefun{$key})\n\n";
209 # Output install_element
216 foreach (keys %odefun) {
217 my ($node, $str) = (split (/,/));
219 $cmd =~ s/_cmd/_cmd_vtysh/;
220 printf " install_element ($node, &$cmd);\n";