paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | #! /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 | |
| 24 | print <<EOF; |
| 25 | #include <zebra.h> |
| 26 | #include "command.h" |
| 27 | #include "vtysh.h" |
| 28 | |
| 29 | EOF |
| 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"; |
hasso | c25e458 | 2003-12-23 10:39:08 +0000 | [diff] [blame] | 40 | $ignore{'"router isis WORD"'} = "ignore"; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 41 | $ignore{'"address-family ipv4"'} = "ignore"; |
| 42 | $ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore"; |
| 43 | $ignore{'"address-family ipv6"'} = "ignore"; |
| 44 | $ignore{'"address-family ipv6 unicast"'} = "ignore"; |
| 45 | $ignore{'"address-family vpnv4"'} = "ignore"; |
| 46 | $ignore{'"address-family vpnv4 unicast"'} = "ignore"; |
| 47 | $ignore{'"address-family ipv4 vrf NAME"'} = "ignore"; |
| 48 | $ignore{'"exit-address-family"'} = "ignore"; |
| 49 | $ignore{'"key chain WORD"'} = "ignore"; |
| 50 | $ignore{'"key <0-2147483647>"'} = "ignore"; |
| 51 | $ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore"; |
| 52 | $ignore{'"show route-map"'} = "ignore"; |
| 53 | |
| 54 | foreach (@ARGV) { |
| 55 | $file = $_; |
| 56 | |
paul | 569c0f0 | 2003-03-02 21:19:26 +0000 | [diff] [blame] | 57 | open (FH, "cpp -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -DHAVE_IPV6 -I. -I.. -I../lib $file |"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 58 | local $/; undef $/; |
| 59 | $line = <FH>; |
| 60 | close (FH); |
| 61 | |
| 62 | @defun = ($line =~ /(?:DEFUN|ALIAS)\s*\((.+?)\);?\s?\s?\n/sg); |
| 63 | @install = ($line =~ /install_element \(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg); |
| 64 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 65 | # DEFUN process |
| 66 | foreach (@defun) { |
| 67 | my (@defun_array); |
| 68 | @defun_array = split (/,/); |
| 69 | $defun_array[0] = ''; |
| 70 | |
| 71 | |
| 72 | # Actual input command string. |
| 73 | $str = "$defun_array[2]"; |
| 74 | $str =~ s/^\s+//g; |
| 75 | $str =~ s/\s+$//g; |
| 76 | |
| 77 | # Get VTY command structure. This is needed for searching |
| 78 | # install_element() command. |
| 79 | $cmd = "$defun_array[1]"; |
| 80 | $cmd =~ s/^\s+//g; |
| 81 | $cmd =~ s/\s+$//g; |
| 82 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 83 | # $protocol is VTYSH_PROTO format for redirection of user input |
| 84 | if ($file =~ /lib/) { |
| 85 | if ($file =~ /keychain.c/) { |
| 86 | $protocol = "VTYSH_RIPD"; |
| 87 | } |
| 88 | if ($file =~ /routemap.c/) { |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 89 | $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD"; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 90 | } |
| 91 | if ($file =~ /filter.c/) { |
| 92 | if ($defun_array[1] =~ m/ipv6/) { |
| 93 | $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD"; |
| 94 | } else { |
| 95 | $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD"; |
| 96 | } |
| 97 | } |
| 98 | if ($file =~ /plist.c/) { |
| 99 | if ($defun_array[1] =~ m/ipv6/) { |
paul | a304c1a | 2003-05-21 17:18:09 +0000 | [diff] [blame] | 100 | $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD"; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 101 | } else { |
paul | a304c1a | 2003-05-21 17:18:09 +0000 | [diff] [blame] | 102 | $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD"; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 103 | } |
| 104 | } |
paul | ba23a69 | 2003-04-19 15:55:08 +0000 | [diff] [blame] | 105 | if ($file =~ /distribute.c/) { |
| 106 | if ($defun_array[1] =~ m/ipv6/) { |
| 107 | $protocol = "VTYSH_RIPNGD"; |
| 108 | } else { |
| 109 | $protocol = "VTYSH_RIPD"; |
| 110 | } |
| 111 | } |
hasso | 0750d21 | 2003-05-24 21:41:49 +0000 | [diff] [blame] | 112 | if ($file =~ /if_rmap.c/) { |
hasso | 4f84947 | 2003-05-25 15:13:49 +0000 | [diff] [blame] | 113 | if ($defun_array[1] =~ m/ipv6/) { |
| 114 | $protocol = "VTYSH_RIPNGD"; |
| 115 | } else { |
| 116 | $protocol = "VTYSH_RIPD"; |
| 117 | } |
hasso | 0750d21 | 2003-05-24 21:41:49 +0000 | [diff] [blame] | 118 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 119 | } else { |
| 120 | ($protocol) = ($file =~ /\/([a-z0-9]+)/); |
| 121 | $protocol = "VTYSH_" . uc $protocol; |
| 122 | } |
| 123 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 124 | # Append _vtysh to structure then build DEFUN again |
| 125 | $defun_array[1] = $cmd . "_vtysh"; |
| 126 | $defun_body = join (", ", @defun_array); |
| 127 | |
| 128 | # $cmd -> $str hash for lookup |
| 129 | $cmd2str{$cmd} = $str; |
| 130 | $cmd2defun{$cmd} = $defun_body; |
| 131 | $cmd2proto{$cmd} = $protocol; |
| 132 | } |
| 133 | |
| 134 | # install_element() process |
| 135 | foreach (@install) { |
| 136 | my (@element_array); |
| 137 | @element_array = split (/,/); |
| 138 | |
| 139 | # Install node |
| 140 | $enode = $element_array[0]; |
| 141 | $enode =~ s/^\s+//g; |
| 142 | $enode =~ s/\s+$//g; |
| 143 | ($enode) = ($enode =~ /([0-9A-Z_]+)$/); |
| 144 | |
| 145 | # VTY command structure. |
| 146 | ($ecmd) = ($element_array[1] =~ /&([^\)]+)/); |
| 147 | $ecmd =~ s/^\s+//g; |
| 148 | $ecmd =~ s/\s+$//g; |
| 149 | |
| 150 | # Register $ecmd |
| 151 | if (defined ($cmd2str{$ecmd}) |
| 152 | && ! defined ($ignore{$cmd2str{$ecmd}})) { |
| 153 | my ($key); |
| 154 | $key = $enode . "," . $cmd2str{$ecmd}; |
| 155 | $ocmd{$key} = $ecmd; |
| 156 | $odefun{$key} = $cmd2defun{$ecmd}; |
| 157 | push (@{$oproto{$key}}, $cmd2proto{$ecmd}); |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | # Check finaly alive $cmd; |
| 163 | foreach (keys %odefun) { |
| 164 | my ($node, $str) = (split (/,/)); |
| 165 | my ($cmd) = $ocmd{$_}; |
| 166 | $live{$cmd} = $_; |
| 167 | } |
| 168 | |
| 169 | # Output DEFSH |
| 170 | foreach (keys %live) { |
| 171 | my ($proto); |
| 172 | my ($key); |
| 173 | $key = $live{$_}; |
| 174 | $proto = join ("|", @{$oproto{$key}}); |
| 175 | printf "DEFSH ($proto$odefun{$key})\n\n"; |
| 176 | } |
| 177 | |
| 178 | # Output install_element |
| 179 | print <<EOF; |
| 180 | void |
| 181 | vtysh_init_cmd () |
| 182 | { |
| 183 | EOF |
| 184 | |
| 185 | foreach (keys %odefun) { |
| 186 | my ($node, $str) = (split (/,/)); |
| 187 | $cmd = $ocmd{$_}; |
| 188 | $cmd =~ s/_cmd/_cmd_vtysh/; |
| 189 | printf " install_element ($node, &$cmd);\n"; |
| 190 | } |
| 191 | |
| 192 | print <<EOF |
| 193 | } |
| 194 | EOF |