Annotation of embedaddon/quagga/vtysh/extract.pl, revision 1.1.1.3

1.1.1.2   misho       1: #! /usr/bin/perl
1.1       misho       2: ##
                      3: ## vtysh/extract.pl.  Generated from extract.pl.in by configure.
                      4: ##
                      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";
1.1.1.2   misho      40: $ignore{'"router babel"'} = "ignore";
1.1       misho      41: $ignore{'"router bgp " "<1-4294967295>"'} = "ignore";
                     42: $ignore{'"router bgp " "<1-4294967295>" " view WORD"'} = "ignore";
                     43: $ignore{'"router isis WORD"'} = "ignore";
                     44: $ignore{'"router zebra"'} = "ignore";
                     45: $ignore{'"address-family ipv4"'} = "ignore";
                     46: $ignore{'"address-family ipv4 (unicast|multicast)"'} = "ignore";
                     47: $ignore{'"address-family ipv6"'} = "ignore";
                     48: $ignore{'"address-family ipv6 unicast"'} = "ignore";
                     49: $ignore{'"address-family vpnv4"'} = "ignore";
                     50: $ignore{'"address-family vpnv4 unicast"'} = "ignore";
                     51: $ignore{'"address-family ipv4 vrf NAME"'} = "ignore";
                     52: $ignore{'"exit-address-family"'} = "ignore";
                     53: $ignore{'"key chain WORD"'} = "ignore";
                     54: $ignore{'"key <0-2147483647>"'} = "ignore";
                     55: $ignore{'"route-map WORD (deny|permit) <1-65535>"'} = "ignore";
                     56: $ignore{'"show route-map"'} = "ignore";
                     57: $ignore{'"line vty"'} = "ignore";
                     58: $ignore{'"who"'} = "ignore";
                     59: $ignore{'"terminal monitor"'} = "ignore";
                     60: $ignore{'"terminal no monitor"'} = "ignore";
                     61: $ignore{'"show history"'} = "ignore";
                     62: 
                     63: foreach (@ARGV) {
                     64:     $file = $_;
                     65: 
1.1.1.3 ! misho      66:     open (FH, "gcc -E -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -DHAVE_IPV6 -I.. -I./ -I./.. -I../lib -I../lib -I../isisd/topology  $file |");
1.1       misho      67:     local $/; undef $/;
                     68:     $line = <FH>;
                     69:     close (FH);
                     70: 
                     71:     @defun = ($line =~ /(?:DEFUN|ALIAS)\s*\((.+?)\);?\s?\s?\n/sg);
1.1.1.2   misho      72:     @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
1.1       misho      73: 
                     74:     # DEFUN process
                     75:     foreach (@defun) {
                     76:        my (@defun_array);
                     77:        @defun_array = split (/,/);
                     78:        $defun_array[0] = '';
                     79: 
                     80: 
                     81:        # Actual input command string.
                     82:        $str = "$defun_array[2]";
                     83:        $str =~ s/^\s+//g;
                     84:        $str =~ s/\s+$//g;
                     85: 
                     86:        # Get VTY command structure.  This is needed for searching
                     87:        # install_element() command.
                     88:        $cmd = "$defun_array[1]";
                     89:        $cmd =~ s/^\s+//g;
                     90:        $cmd =~ s/\s+$//g;
                     91: 
                     92:         # $protocol is VTYSH_PROTO format for redirection of user input
                     93:        if ($file =~ /lib/) {
                     94:            if ($file =~ /keychain.c/) {
                     95:               $protocol = "VTYSH_RIPD";
                     96:            }
                     97:            if ($file =~ /routemap.c/) {
                     98:               $protocol = "VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
                     99:            }
                    100:            if ($file =~ /filter.c/) {
                    101:               $protocol = "VTYSH_ALL";
                    102:            }
                    103:            if ($file =~ /plist.c/) {
                    104:              if ($defun_array[1] =~ m/ipv6/) {
                    105:                  $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
                    106:               } else {
                    107:                  $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA";
                    108:               }
                    109:            }
                    110:            if ($file =~ /distribute.c/) {
                    111:               if ($defun_array[1] =~ m/ipv6/) {
                    112:                  $protocol = "VTYSH_RIPNGD";
                    113:               } else {
                    114:                  $protocol = "VTYSH_RIPD";
                    115:               }
                    116:            }
                    117:            if ($file =~ /if_rmap.c/) {
                    118:               if ($defun_array[1] =~ m/ipv6/) {
                    119:                  $protocol = "VTYSH_RIPNGD";
                    120:               } else {
                    121:                  $protocol = "VTYSH_RIPD";
                    122:               }
                    123:            }
                    124:           if ($file =~ /vty.c/) {
                    125:              $protocol = "VTYSH_ALL";
                    126:           }
                    127:         } else {
                    128:            ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/);
                    129:            $protocol = "VTYSH_" . uc $protocol;
                    130:         }
                    131: 
                    132:        # Append _vtysh to structure then build DEFUN again
                    133:        $defun_array[1] = $cmd . "_vtysh";
                    134:        $defun_body = join (", ", @defun_array);
                    135: 
                    136:        # $cmd -> $str hash for lookup
                    137:        $cmd2str{$cmd} = $str;
                    138:        $cmd2defun{$cmd} = $defun_body;
                    139:        $cmd2proto{$cmd} = $protocol;
                    140:     }
                    141: 
                    142:     # install_element() process
                    143:     foreach (@install) {
                    144:        my (@element_array);
                    145:        @element_array = split (/,/);
                    146: 
                    147:        # Install node
                    148:        $enode = $element_array[0];
                    149:        $enode =~ s/^\s+//g;
                    150:        $enode =~ s/\s+$//g;
                    151:        ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
                    152: 
                    153:        # VTY command structure.
                    154:        ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
                    155:        $ecmd =~ s/^\s+//g;
                    156:        $ecmd =~ s/\s+$//g;
                    157: 
                    158:        # Register $ecmd
                    159:        if (defined ($cmd2str{$ecmd})
                    160:            && ! defined ($ignore{$cmd2str{$ecmd}})) {
                    161:            my ($key);
                    162:            $key = $enode . "," . $cmd2str{$ecmd};
                    163:            $ocmd{$key} = $ecmd;
                    164:            $odefun{$key} = $cmd2defun{$ecmd};
                    165:            push (@{$oproto{$key}}, $cmd2proto{$ecmd});
                    166:        }
                    167:     }
                    168: }
                    169: 
                    170: # Check finaly alive $cmd;
                    171: foreach (keys %odefun) {
                    172:     my ($node, $str) = (split (/,/));
                    173:     my ($cmd) = $ocmd{$_};
                    174:     $live{$cmd} = $_;
                    175: }
                    176: 
                    177: # Output DEFSH
                    178: foreach (keys %live) {
                    179:     my ($proto);
                    180:     my ($key);
                    181:     $key = $live{$_};
                    182:     $proto = join ("|", @{$oproto{$key}});
                    183:     printf "DEFSH ($proto$odefun{$key})\n\n";
                    184: }
                    185: 
                    186: # Output install_element
                    187: print <<EOF;
                    188: void
                    189: vtysh_init_cmd ()
                    190: {
                    191: EOF
                    192: 
                    193: foreach (keys %odefun) {
                    194:     my ($node, $str) = (split (/,/));
                    195:     $cmd = $ocmd{$_};
                    196:     $cmd =~ s/_cmd/_cmd_vtysh/;
                    197:     printf "  install_element ($node, &$cmd);\n";
                    198: }
                    199: 
                    200: print <<EOF
                    201: }
                    202: EOF

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>