]> git.proxmox.com Git - mirror_frr.git/blame - vtysh/extract.pl.in
Merge pull request #1805 from donaldsharp/recursion
[mirror_frr.git] / vtysh / extract.pl.in
CommitLineData
fc9d0745 1#! @PERL@
718e3744 2##
b63dc1f3 3## @configure_input@
4##
718e3744 5## Virtual terminal interface shell command extractor.
6## Copyright (C) 2000 Kunihiro Ishiguro
7##
8## This file is part of GNU Zebra.
9##
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
13## later version.
14##
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.
19##
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
23## 02111-1307, USA.
24##
25
26print <<EOF;
27#include <zebra.h>
988225dd 28
718e3744 29#include "command.h"
988225dd
DL
30#include "linklist.h"
31
718e3744 32#include "vtysh.h"
33
34EOF
35
b623cda4
DS
36my $cli_stomp = 0;
37
718e3744 38foreach (@ARGV) {
39 $file = $_;
40
56c1f7d8 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 |");
718e3744 42 local $/; undef $/;
43 $line = <FH>;
44 close (FH);
45
abaaab4e
DW
46 # ?: makes a group non-capturing
47 @defun = ($line =~ /((?:DEFUN|DEFUN_HIDDEN|ALIAS|ALIAS_HIDDEN)\s*\(.+?\));?\s?\s?\n/sg);
0b42c708 48 @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
718e3744 49
718e3744 50 # DEFUN process
51 foreach (@defun) {
abaaab4e
DW
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.
8d9e99a6 55 $_ =~ /^(.*?)\s*\((.*)\)$/s;
abaaab4e
DW
56
57 my (@defun_array);
58 $defun_or_alias = $1;
59 @defun_array = split (/,/, $2);
60
61 if ($defun_or_alias =~ /_HIDDEN/) {
62 $hidden = 1;
63 } else {
64 $hidden = 0;
65 }
718e3744 66
abaaab4e 67 $defun_array[0] = '';
718e3744 68
abaaab4e
DW
69 # Actual input command string.
70 $str = "$defun_array[2]";
71 $str =~ s/^\s+//g;
72 $str =~ s/\s+$//g;
718e3744 73
abaaab4e
DW
74 # Get VTY command structure. This is needed for searching
75 # install_element() command.
76 $cmd = "$defun_array[1]";
77 $cmd =~ s/^\s+//g;
78 $cmd =~ s/\s+$//g;
718e3744 79
68980084 80 # $protocol is VTYSH_PROTO format for redirection of user input
844ee104
JT
81 if ($file =~ /lib\/keychain\.c$/) {
82 $protocol = "VTYSH_RIPD";
83 }
84 elsif ($file =~ /lib\/routemap\.c$/) {
1753f727 85 $protocol = "VTYSH_RMAP";
844ee104 86 }
abaaab4e 87 elsif ($file =~ /lib\/vrf\.c$/) {
6f2f0be8 88 $protocol = "VTYSH_ALL";
abaaab4e 89 }
f5d20fdb
PG
90 elsif ($file =~ /lib\/logicalrouter\.c$/) {
91 $protocol = "VTYSH_ALL";
92 }
844ee104
JT
93 elsif ($file =~ /lib\/filter\.c$/) {
94 $protocol = "VTYSH_ALL";
95 }
62ff928b
DS
96 elsif ($file =~ /lib\/agentx\.c$/) {
97 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
98 }
13460c44
FL
99 elsif ($file =~ /lib\/ns\.c$/) {
100 $protocol = "VTYSH_ZEBRA";
101 }
844ee104
JT
102 elsif ($file =~ /lib\/plist\.c$/) {
103 if ($defun_array[1] =~ m/ipv6/) {
1753f727 104 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_BABELD|VTYSH_ISISD";
844ee104 105 } else {
1753f727 106 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_ISISD";
844ee104
JT
107 }
108 }
109 elsif ($file =~ /lib\/distribute\.c$/) {
110 if ($defun_array[1] =~ m/ipv6/) {
111 $protocol = "VTYSH_RIPNGD";
112 } else {
113 $protocol = "VTYSH_RIPD";
114 }
115 }
116 elsif ($file =~ /lib\/if_rmap\.c$/) {
117 if ($defun_array[1] =~ m/ipv6/) {
118 $protocol = "VTYSH_RIPNGD";
119 } else {
120 $protocol = "VTYSH_RIPD";
121 }
122 }
123 elsif ($file =~ /lib\/vty\.c$/) {
124 $protocol = "VTYSH_ALL";
125 }
65efcfce
LB
126 elsif ($file =~ /librfp\/.*\.c$/ || $file =~ /rfapi\/.*\.c$/) {
127 $protocol = "VTYSH_BGPD";
128 }
abaaab4e 129 else {
0e82d0e1 130 ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/);
68980084 131 $protocol = "VTYSH_" . uc $protocol;
132 }
133
abaaab4e
DW
134 # Append _vtysh to structure then build DEFUN again
135 $defun_array[1] = $cmd . "_vtysh";
136 $defun_body = join (", ", @defun_array);
718e3744 137
b623cda4
DS
138 # $cmd -> $str hash for lookup
139 if (exists($cmd2str{$cmd})) {
140 warn "Duplicate CLI Function: $cmd\n";
141 warn "\tFrom cli: $cmd2str{$cmd} to New cli: $str\n";
142 warn "\tOriginal Protocol: $cmd2proto{$cmd} to New Protocol: $protocol\n";
143 $cli_stomp++;
144 }
abaaab4e
DW
145 $cmd2str{$cmd} = $str;
146 $cmd2defun{$cmd} = $defun_body;
147 $cmd2proto{$cmd} = $protocol;
148 $cmd2hidden{$cmd} = $hidden;
718e3744 149 }
150
151 # install_element() process
152 foreach (@install) {
abaaab4e
DW
153 my (@element_array);
154 @element_array = split (/,/);
155
156 # Install node
157 $enode = $element_array[0];
158 $enode =~ s/^\s+//g;
159 $enode =~ s/\s+$//g;
160 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
161
162 # VTY command structure.
163 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
164 $ecmd =~ s/^\s+//g;
165 $ecmd =~ s/\s+$//g;
166
167 # Register $ecmd
16807aab 168 if (defined ($cmd2str{$ecmd})) {
abaaab4e
DW
169 my ($key);
170 $key = $enode . "," . $cmd2str{$ecmd};
171 $ocmd{$key} = $ecmd;
172 $odefun{$key} = $cmd2defun{$ecmd};
173
174 if ($cmd2hidden{$ecmd}) {
175 $defsh{$key} = "DEFSH_HIDDEN"
176 } else {
177 $defsh{$key} = "DEFSH"
178 }
179 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
180 }
718e3744 181 }
182}
183
b623cda4
DS
184# When we have cli commands that map to the same function name, we
185# can introduce subtle bugs due to code not being called when
186# we think it is.
187#
188# If extract.pl fails with a error message and you've been
189# modifying the cli, then go back and fix your code to
190# not have cli command function collisions.
b623cda4 191# please fix your code before submittal
82f97584
DW
192if ($cli_stomp) {
193 warn "There are $cli_stomp command line stomps\n";
b623cda4
DS
194}
195
718e3744 196# Check finaly alive $cmd;
197foreach (keys %odefun) {
198 my ($node, $str) = (split (/,/));
199 my ($cmd) = $ocmd{$_};
200 $live{$cmd} = $_;
201}
202
203# Output DEFSH
74818bb1 204foreach (sort keys %live) {
718e3744 205 my ($proto);
206 my ($key);
207 $key = $live{$_};
208 $proto = join ("|", @{$oproto{$key}});
abaaab4e 209 printf "$defsh{$key} ($proto$odefun{$key})\n\n";
718e3744 210}
211
212# Output install_element
213print <<EOF;
214void
215vtysh_init_cmd ()
216{
217EOF
218
74818bb1 219foreach (sort keys %odefun) {
718e3744 220 my ($node, $str) = (split (/,/));
221 $cmd = $ocmd{$_};
222 $cmd =~ s/_cmd/_cmd_vtysh/;
223 printf " install_element ($node, &$cmd);\n";
224}
225
226print <<EOF
227}
228EOF