blob: ca88cf7bb1dc600fd16fe065621694b24ed1c758 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001#! /usr/bin/perl
2##
3## Virtual terminal interface shell command extractor.
4## Copyright (C) 2000 Kunihiro Ishiguro
5##
6## This file is part of GNU Zebra.
7##
8## GNU Zebra is free software; you can redistribute it and/or modify it
9## under the terms of the GNU General Public License as published by the
10## Free Software Foundation; either version 2, or (at your option) any
11## later version.
12##
13## GNU Zebra is distributed in the hope that it will be useful, but
14## WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16## General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with GNU Zebra; see the file COPYING. If not, write to the Free
20## Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21## 02111-1307, USA.
22##
23
24print <<EOF;
25#include <zebra.h>
26#include "command.h"
27#include "vtysh.h"
28
29EOF
30
31$ignore{'"interface IFNAME"'} = "ignore";
32$ignore{'"ip vrf NAME"'} = "ignore";
33$ignore{'"router rip"'} = "ignore";
34$ignore{'"router ripng"'} = "ignore";
35$ignore{'"router ospf"'} = "ignore";
36$ignore{'"router ospf <0-65535>"'} = "ignore";
37$ignore{'"router ospf6"'} = "ignore";
38$ignore{'"router bgp <1-65535>"'} = "ignore";
39$ignore{'"router bgp <1-65535> view WORD"'} = "ignore";
40$ignore{'"address-family ipv4"'} = "ignore";
41$ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore";
42$ignore{'"address-family ipv6"'} = "ignore";
43$ignore{'"address-family ipv6 unicast"'} = "ignore";
44$ignore{'"address-family vpnv4"'} = "ignore";
45$ignore{'"address-family vpnv4 unicast"'} = "ignore";
46$ignore{'"address-family ipv4 vrf NAME"'} = "ignore";
47$ignore{'"exit-address-family"'} = "ignore";
48$ignore{'"key chain WORD"'} = "ignore";
49$ignore{'"key <0-2147483647>"'} = "ignore";
50$ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore";
51$ignore{'"show route-map"'} = "ignore";
52
53foreach (@ARGV) {
54 $file = $_;
55
paul569c0f02003-03-02 21:19:26 +000056 open (FH, "cpp -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -DHAVE_IPV6 -I. -I.. -I../lib $file |");
paul718e3742002-12-13 20:15:29 +000057 local $/; undef $/;
58 $line = <FH>;
59 close (FH);
60
61 @defun = ($line =~ /(?:DEFUN|ALIAS)\s*\((.+?)\);?\s?\s?\n/sg);
62 @install = ($line =~ /install_element \(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
63
paul718e3742002-12-13 20:15:29 +000064 # DEFUN process
65 foreach (@defun) {
66 my (@defun_array);
67 @defun_array = split (/,/);
68 $defun_array[0] = '';
69
70
71 # Actual input command string.
72 $str = "$defun_array[2]";
73 $str =~ s/^\s+//g;
74 $str =~ s/\s+$//g;
75
76 # Get VTY command structure. This is needed for searching
77 # install_element() command.
78 $cmd = "$defun_array[1]";
79 $cmd =~ s/^\s+//g;
80 $cmd =~ s/\s+$//g;
81
paul68980082003-03-25 05:07:42 +000082 # $protocol is VTYSH_PROTO format for redirection of user input
83 if ($file =~ /lib/) {
84 if ($file =~ /keychain.c/) {
85 $protocol = "VTYSH_RIPD";
86 }
87 if ($file =~ /routemap.c/) {
paul73ffb252003-04-19 15:49:49 +000088 $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +000089 }
90 if ($file =~ /filter.c/) {
91 if ($defun_array[1] =~ m/ipv6/) {
92 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD";
93 } else {
94 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD";
95 }
96 }
97 if ($file =~ /plist.c/) {
98 if ($defun_array[1] =~ m/ipv6/) {
paula304c1a2003-05-21 17:18:09 +000099 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +0000100 } else {
paula304c1a2003-05-21 17:18:09 +0000101 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD";
paul68980082003-03-25 05:07:42 +0000102 }
103 }
paulba23a692003-04-19 15:55:08 +0000104 if ($file =~ /distribute.c/) {
105 if ($defun_array[1] =~ m/ipv6/) {
106 $protocol = "VTYSH_RIPNGD";
107 } else {
108 $protocol = "VTYSH_RIPD";
109 }
110 }
hasso0750d212003-05-24 21:41:49 +0000111 if ($file =~ /if_rmap.c/) {
112 $protocol = "VTYSH_RIPNGD";
113 }
paul68980082003-03-25 05:07:42 +0000114 } else {
115 ($protocol) = ($file =~ /\/([a-z0-9]+)/);
116 $protocol = "VTYSH_" . uc $protocol;
117 }
118
paul718e3742002-12-13 20:15:29 +0000119 # Append _vtysh to structure then build DEFUN again
120 $defun_array[1] = $cmd . "_vtysh";
121 $defun_body = join (", ", @defun_array);
122
123 # $cmd -> $str hash for lookup
124 $cmd2str{$cmd} = $str;
125 $cmd2defun{$cmd} = $defun_body;
126 $cmd2proto{$cmd} = $protocol;
127 }
128
129 # install_element() process
130 foreach (@install) {
131 my (@element_array);
132 @element_array = split (/,/);
133
134 # Install node
135 $enode = $element_array[0];
136 $enode =~ s/^\s+//g;
137 $enode =~ s/\s+$//g;
138 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
139
140 # VTY command structure.
141 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
142 $ecmd =~ s/^\s+//g;
143 $ecmd =~ s/\s+$//g;
144
145 # Register $ecmd
146 if (defined ($cmd2str{$ecmd})
147 && ! defined ($ignore{$cmd2str{$ecmd}})) {
148 my ($key);
149 $key = $enode . "," . $cmd2str{$ecmd};
150 $ocmd{$key} = $ecmd;
151 $odefun{$key} = $cmd2defun{$ecmd};
152 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
153 }
154 }
155}
156
157# Check finaly alive $cmd;
158foreach (keys %odefun) {
159 my ($node, $str) = (split (/,/));
160 my ($cmd) = $ocmd{$_};
161 $live{$cmd} = $_;
162}
163
164# Output DEFSH
165foreach (keys %live) {
166 my ($proto);
167 my ($key);
168 $key = $live{$_};
169 $proto = join ("|", @{$oproto{$key}});
170 printf "DEFSH ($proto$odefun{$key})\n\n";
171}
172
173# Output install_element
174print <<EOF;
175void
176vtysh_init_cmd ()
177{
178EOF
179
180foreach (keys %odefun) {
181 my ($node, $str) = (split (/,/));
182 $cmd = $ocmd{$_};
183 $cmd =~ s/_cmd/_cmd_vtysh/;
184 printf " install_element ($node, &$cmd);\n";
185}
186
187print <<EOF
188}
189EOF