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