blob: 053b17e946a9f4dba3c8368dc8c336648c45e030 [file] [log] [blame]
gdtfc9d0742004-06-30 14:25:12 +00001#! @PERL@
paul718e3742002-12-13 20:15:29 +00002##
paulb63dc1f2004-09-13 12:59:08 +00003## @configure_input@
4##
paul718e3742002-12-13 20:15:29 +00005## 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>
28#include "command.h"
29#include "vtysh.h"
30
31EOF
32
33$ignore{'"interface IFNAME"'} = "ignore";
34$ignore{'"ip vrf NAME"'} = "ignore";
35$ignore{'"router rip"'} = "ignore";
36$ignore{'"router ripng"'} = "ignore";
37$ignore{'"router ospf"'} = "ignore";
38$ignore{'"router ospf <0-65535>"'} = "ignore";
39$ignore{'"router ospf6"'} = "ignore";
40$ignore{'"router bgp <1-65535>"'} = "ignore";
41$ignore{'"router bgp <1-65535> view WORD"'} = "ignore";
hassoc25e4582003-12-23 10:39:08 +000042$ignore{'"router isis WORD"'} = "ignore";
paul718e3742002-12-13 20:15:29 +000043$ignore{'"address-family ipv4"'} = "ignore";
44$ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore";
45$ignore{'"address-family ipv6"'} = "ignore";
46$ignore{'"address-family ipv6 unicast"'} = "ignore";
47$ignore{'"address-family vpnv4"'} = "ignore";
48$ignore{'"address-family vpnv4 unicast"'} = "ignore";
49$ignore{'"address-family ipv4 vrf NAME"'} = "ignore";
50$ignore{'"exit-address-family"'} = "ignore";
51$ignore{'"key chain WORD"'} = "ignore";
52$ignore{'"key <0-2147483647>"'} = "ignore";
53$ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore";
54$ignore{'"show route-map"'} = "ignore";
55
56foreach (@ARGV) {
57 $file = $_;
58
paulb63dc1f2004-09-13 12:59:08 +000059 open (FH, "cpp -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -DHAVE_IPV6 -I@top_builddir@ -I@srcdir@/ -I@srcdir@/.. -I@top_srcdir@/lib $file |");
paul718e3742002-12-13 20:15:29 +000060 local $/; undef $/;
61 $line = <FH>;
62 close (FH);
63
64 @defun = ($line =~ /(?:DEFUN|ALIAS)\s*\((.+?)\);?\s?\s?\n/sg);
65 @install = ($line =~ /install_element \(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
66
paul718e3742002-12-13 20:15:29 +000067 # DEFUN process
68 foreach (@defun) {
69 my (@defun_array);
70 @defun_array = split (/,/);
71 $defun_array[0] = '';
72
73
74 # Actual input command string.
75 $str = "$defun_array[2]";
76 $str =~ s/^\s+//g;
77 $str =~ s/\s+$//g;
78
79 # Get VTY command structure. This is needed for searching
80 # install_element() command.
81 $cmd = "$defun_array[1]";
82 $cmd =~ s/^\s+//g;
83 $cmd =~ s/\s+$//g;
84
paul68980082003-03-25 05:07:42 +000085 # $protocol is VTYSH_PROTO format for redirection of user input
86 if ($file =~ /lib/) {
87 if ($file =~ /keychain.c/) {
88 $protocol = "VTYSH_RIPD";
89 }
90 if ($file =~ /routemap.c/) {
paul73ffb252003-04-19 15:49:49 +000091 $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +000092 }
93 if ($file =~ /filter.c/) {
94 if ($defun_array[1] =~ m/ipv6/) {
hasso6c0f9a72004-06-20 09:30:57 +000095 $protocol = "VTYSH_ZEBRA|VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +000096 } else {
hasso6c0f9a72004-06-20 09:30:57 +000097 $protocol = "VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +000098 }
99 }
100 if ($file =~ /plist.c/) {
101 if ($defun_array[1] =~ m/ipv6/) {
paula304c1a2003-05-21 17:18:09 +0000102 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +0000103 } else {
paula304c1a2003-05-21 17:18:09 +0000104 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +0000105 }
106 }
paulba23a692003-04-19 15:55:08 +0000107 if ($file =~ /distribute.c/) {
108 if ($defun_array[1] =~ m/ipv6/) {
109 $protocol = "VTYSH_RIPNGD";
110 } else {
111 $protocol = "VTYSH_RIPD";
112 }
113 }
hasso0750d212003-05-24 21:41:49 +0000114 if ($file =~ /if_rmap.c/) {
hasso4f849472003-05-25 15:13:49 +0000115 if ($defun_array[1] =~ m/ipv6/) {
116 $protocol = "VTYSH_RIPNGD";
117 } else {
118 $protocol = "VTYSH_RIPD";
119 }
hasso0750d212003-05-24 21:41:49 +0000120 }
paul68980082003-03-25 05:07:42 +0000121 } else {
paul0e82d0e2004-09-13 05:00:18 +0000122 ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/);
paul68980082003-03-25 05:07:42 +0000123 $protocol = "VTYSH_" . uc $protocol;
124 }
125
paul718e3742002-12-13 20:15:29 +0000126 # Append _vtysh to structure then build DEFUN again
127 $defun_array[1] = $cmd . "_vtysh";
128 $defun_body = join (", ", @defun_array);
129
130 # $cmd -> $str hash for lookup
131 $cmd2str{$cmd} = $str;
132 $cmd2defun{$cmd} = $defun_body;
133 $cmd2proto{$cmd} = $protocol;
134 }
135
136 # install_element() process
137 foreach (@install) {
138 my (@element_array);
139 @element_array = split (/,/);
140
141 # Install node
142 $enode = $element_array[0];
143 $enode =~ s/^\s+//g;
144 $enode =~ s/\s+$//g;
145 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
146
147 # VTY command structure.
148 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
149 $ecmd =~ s/^\s+//g;
150 $ecmd =~ s/\s+$//g;
151
152 # Register $ecmd
153 if (defined ($cmd2str{$ecmd})
154 && ! defined ($ignore{$cmd2str{$ecmd}})) {
155 my ($key);
156 $key = $enode . "," . $cmd2str{$ecmd};
157 $ocmd{$key} = $ecmd;
158 $odefun{$key} = $cmd2defun{$ecmd};
159 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
160 }
161 }
162}
163
164# Check finaly alive $cmd;
165foreach (keys %odefun) {
166 my ($node, $str) = (split (/,/));
167 my ($cmd) = $ocmd{$_};
168 $live{$cmd} = $_;
169}
170
171# Output DEFSH
172foreach (keys %live) {
173 my ($proto);
174 my ($key);
175 $key = $live{$_};
176 $proto = join ("|", @{$oproto{$key}});
177 printf "DEFSH ($proto$odefun{$key})\n\n";
178}
179
180# Output install_element
181print <<EOF;
182void
183vtysh_init_cmd ()
184{
185EOF
186
187foreach (keys %odefun) {
188 my ($node, $str) = (split (/,/));
189 $cmd = $ocmd{$_};
190 $cmd =~ s/_cmd/_cmd_vtysh/;
191 printf " install_element ($node, &$cmd);\n";
192}
193
194print <<EOF
195}
196EOF