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"; |
| 55 | |
| 56 | foreach (@ARGV) { |
| 57 | $file = $_; |
| 58 | |
paul | b63dc1f | 2004-09-13 12:59:08 +0000 | [diff] [blame] | 59 | open (FH, "cpp -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -DHAVE_IPV6 -I@top_builddir@ -I@srcdir@/ -I@srcdir@/.. -I@top_srcdir@/lib $file |"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 60 | 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 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 67 | # 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 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 85 | # $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/) { |
paul | 73ffb25 | 2003-04-19 15:49:49 +0000 | [diff] [blame] | 91 | $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD"; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 92 | } |
| 93 | if ($file =~ /filter.c/) { |
| 94 | if ($defun_array[1] =~ m/ipv6/) { |
hasso | 6c0f9a7 | 2004-06-20 09:30:57 +0000 | [diff] [blame] | 95 | $protocol = "VTYSH_ZEBRA|VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD"; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 96 | } else { |
hasso | 6c0f9a7 | 2004-06-20 09:30:57 +0000 | [diff] [blame] | 97 | $protocol = "VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD"; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 98 | } |
| 99 | } |
| 100 | if ($file =~ /plist.c/) { |
| 101 | if ($defun_array[1] =~ m/ipv6/) { |
paul | a304c1a | 2003-05-21 17:18:09 +0000 | [diff] [blame] | 102 | $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD"; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 103 | } else { |
paul | a304c1a | 2003-05-21 17:18:09 +0000 | [diff] [blame] | 104 | $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD"; |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 105 | } |
| 106 | } |
paul | ba23a69 | 2003-04-19 15:55:08 +0000 | [diff] [blame] | 107 | if ($file =~ /distribute.c/) { |
| 108 | if ($defun_array[1] =~ m/ipv6/) { |
| 109 | $protocol = "VTYSH_RIPNGD"; |
| 110 | } else { |
| 111 | $protocol = "VTYSH_RIPD"; |
| 112 | } |
| 113 | } |
hasso | 0750d21 | 2003-05-24 21:41:49 +0000 | [diff] [blame] | 114 | if ($file =~ /if_rmap.c/) { |
hasso | 4f84947 | 2003-05-25 15:13:49 +0000 | [diff] [blame] | 115 | if ($defun_array[1] =~ m/ipv6/) { |
| 116 | $protocol = "VTYSH_RIPNGD"; |
| 117 | } else { |
| 118 | $protocol = "VTYSH_RIPD"; |
| 119 | } |
hasso | 0750d21 | 2003-05-24 21:41:49 +0000 | [diff] [blame] | 120 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 121 | } else { |
paul | 0e82d0e | 2004-09-13 05:00:18 +0000 | [diff] [blame] | 122 | ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 123 | $protocol = "VTYSH_" . uc $protocol; |
| 124 | } |
| 125 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 126 | # 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; |
| 165 | foreach (keys %odefun) { |
| 166 | my ($node, $str) = (split (/,/)); |
| 167 | my ($cmd) = $ocmd{$_}; |
| 168 | $live{$cmd} = $_; |
| 169 | } |
| 170 | |
| 171 | # Output DEFSH |
| 172 | foreach (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 |
| 181 | print <<EOF; |
| 182 | void |
| 183 | vtysh_init_cmd () |
| 184 | { |
| 185 | EOF |
| 186 | |
| 187 | foreach (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 | |
| 194 | print <<EOF |
| 195 | } |
| 196 | EOF |