]> git.proxmox.com Git - mirror_frr.git/blame - vtysh/extract.pl.in
Merge pull request #3814 from opensourcerouting/6.0/doc-pager-theme
[mirror_frr.git] / vtysh / extract.pl.in
CommitLineData
fc9d0745 1#! @PERL@
718e3744 2##
b63dc1f3 3## @configure_input@
4##
718e3744 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
26print <<EOF;
27#include <zebra.h>
988225dd 28
718e3744 29#include "command.h"
988225dd
DL
30#include "linklist.h"
31
6ea061a2 32#include "vtysh/vtysh.h"
718e3744 33
34EOF
35
b623cda4
DS
36my $cli_stomp = 0;
37
718e3744 38foreach (@ARGV) {
39 $file = $_;
40
6ea061a2 41 open (FH, "@CPP@ -DHAVE_CONFIG_H -DVTYSH_EXTRACT_PL -Ivtysh/@top_builddir@ -Ivtysh/@top_srcdir@ -Ivtysh/@top_srcdir@/lib -Ivtysh/@top_builddir@/lib -Ivtysh/@top_srcdir@/bgpd -Ivtysh/@top_srcdir@/bgpd/rfapi @CPPFLAGS@ $file |");
718e3744 42 local $/; undef $/;
43 $line = <FH>;
44 close (FH);
45
abaaab4e
DW
46 # ?: makes a group non-capturing
47 @defun = ($line =~ /((?:DEFUN|DEFUN_HIDDEN|ALIAS|ALIAS_HIDDEN)\s*\(.+?\));?\s?\s?\n/sg);
0b42c708 48 @install = ($line =~ /install_element\s*\(\s*[0-9A-Z_]+,\s*&[^;]*;\s*\n/sg);
718e3744 49
718e3744 50 # DEFUN process
51 foreach (@defun) {
abaaab4e
DW
52 # $_ will contain the entire string including the DEFUN, ALIAS, etc.
53 # We need to extract the DEFUN/ALIAS from everything in ()s.
54 # The /s at the end tells the regex to allow . to match newlines.
8d9e99a6 55 $_ =~ /^(.*?)\s*\((.*)\)$/s;
abaaab4e
DW
56
57 my (@defun_array);
58 $defun_or_alias = $1;
59 @defun_array = split (/,/, $2);
60
61 if ($defun_or_alias =~ /_HIDDEN/) {
62 $hidden = 1;
63 } else {
64 $hidden = 0;
65 }
718e3744 66
abaaab4e 67 $defun_array[0] = '';
718e3744 68
abaaab4e
DW
69 # Actual input command string.
70 $str = "$defun_array[2]";
71 $str =~ s/^\s+//g;
72 $str =~ s/\s+$//g;
718e3744 73
abaaab4e
DW
74 # Get VTY command structure. This is needed for searching
75 # install_element() command.
76 $cmd = "$defun_array[1]";
77 $cmd =~ s/^\s+//g;
78 $cmd =~ s/\s+$//g;
718e3744 79
68980084 80 # $protocol is VTYSH_PROTO format for redirection of user input
844ee104
JT
81 if ($file =~ /lib\/keychain\.c$/) {
82 $protocol = "VTYSH_RIPD";
83 }
84 elsif ($file =~ /lib\/routemap\.c$/) {
1753f727 85 $protocol = "VTYSH_RMAP";
844ee104 86 }
abaaab4e 87 elsif ($file =~ /lib\/vrf\.c$/) {
34c46274 88 $protocol = "VTYSH_VRF";
abaaab4e 89 }
91e5b43a
RW
90 elsif ($file =~ /lib\/if\.c$/) {
91 $protocol = "VTYSH_INTERFACE";
92 }
f5d20fdb
PG
93 elsif ($file =~ /lib\/logicalrouter\.c$/) {
94 $protocol = "VTYSH_ALL";
95 }
844ee104
JT
96 elsif ($file =~ /lib\/filter\.c$/) {
97 $protocol = "VTYSH_ALL";
98 }
62ff928b
DS
99 elsif ($file =~ /lib\/agentx\.c$/) {
100 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA";
101 }
13460c44
FL
102 elsif ($file =~ /lib\/ns\.c$/) {
103 $protocol = "VTYSH_ZEBRA";
104 }
e5c83d9b
DS
105 elsif ($file =~ /lib\/nexthop_group\.c$/) {
106 $protocol = "VTYSH_PBRD";
107 }
844ee104
JT
108 elsif ($file =~ /lib\/plist\.c$/) {
109 if ($defun_array[1] =~ m/ipv6/) {
1753f727 110 $protocol = "VTYSH_RIPNGD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_BABELD|VTYSH_ISISD";
844ee104 111 } else {
1753f727 112 $protocol = "VTYSH_RIPD|VTYSH_OSPFD|VTYSH_BGPD|VTYSH_ZEBRA|VTYSH_PIMD|VTYSH_EIGRPD|VTYSH_BABELD|VTYSH_ISISD";
844ee104
JT
113 }
114 }
115 elsif ($file =~ /lib\/distribute\.c$/) {
116 if ($defun_array[1] =~ m/ipv6/) {
117 $protocol = "VTYSH_RIPNGD";
118 } else {
119 $protocol = "VTYSH_RIPD";
120 }
121 }
122 elsif ($file =~ /lib\/if_rmap\.c$/) {
123 if ($defun_array[1] =~ m/ipv6/) {
124 $protocol = "VTYSH_RIPNGD";
125 } else {
126 $protocol = "VTYSH_RIPD";
127 }
128 }
129 elsif ($file =~ /lib\/vty\.c$/) {
130 $protocol = "VTYSH_ALL";
131 }
65efcfce
LB
132 elsif ($file =~ /librfp\/.*\.c$/ || $file =~ /rfapi\/.*\.c$/) {
133 $protocol = "VTYSH_BGPD";
134 }
abaaab4e 135 else {
0e82d0e1 136 ($protocol) = ($file =~ /^.*\/([a-z0-9]+)\/[a-zA-Z0-9_\-]+\.c$/);
68980084 137 $protocol = "VTYSH_" . uc $protocol;
138 }
139
abaaab4e
DW
140 # Append _vtysh to structure then build DEFUN again
141 $defun_array[1] = $cmd . "_vtysh";
142 $defun_body = join (", ", @defun_array);
718e3744 143
b623cda4
DS
144 # $cmd -> $str hash for lookup
145 if (exists($cmd2str{$cmd})) {
146 warn "Duplicate CLI Function: $cmd\n";
147 warn "\tFrom cli: $cmd2str{$cmd} to New cli: $str\n";
148 warn "\tOriginal Protocol: $cmd2proto{$cmd} to New Protocol: $protocol\n";
149 $cli_stomp++;
150 }
abaaab4e
DW
151 $cmd2str{$cmd} = $str;
152 $cmd2defun{$cmd} = $defun_body;
153 $cmd2proto{$cmd} = $protocol;
154 $cmd2hidden{$cmd} = $hidden;
718e3744 155 }
156
157 # install_element() process
158 foreach (@install) {
abaaab4e
DW
159 my (@element_array);
160 @element_array = split (/,/);
161
162 # Install node
163 $enode = $element_array[0];
164 $enode =~ s/^\s+//g;
165 $enode =~ s/\s+$//g;
166 ($enode) = ($enode =~ /([0-9A-Z_]+)$/);
167
168 # VTY command structure.
169 ($ecmd) = ($element_array[1] =~ /&([^\)]+)/);
170 $ecmd =~ s/^\s+//g;
171 $ecmd =~ s/\s+$//g;
172
173 # Register $ecmd
16807aab 174 if (defined ($cmd2str{$ecmd})) {
abaaab4e
DW
175 my ($key);
176 $key = $enode . "," . $cmd2str{$ecmd};
177 $ocmd{$key} = $ecmd;
178 $odefun{$key} = $cmd2defun{$ecmd};
179
180 if ($cmd2hidden{$ecmd}) {
181 $defsh{$key} = "DEFSH_HIDDEN"
182 } else {
183 $defsh{$key} = "DEFSH"
184 }
185 push (@{$oproto{$key}}, $cmd2proto{$ecmd});
186 }
718e3744 187 }
188}
189
b623cda4
DS
190# When we have cli commands that map to the same function name, we
191# can introduce subtle bugs due to code not being called when
192# we think it is.
193#
194# If extract.pl fails with a error message and you've been
195# modifying the cli, then go back and fix your code to
196# not have cli command function collisions.
b623cda4 197# please fix your code before submittal
82f97584
DW
198if ($cli_stomp) {
199 warn "There are $cli_stomp command line stomps\n";
b623cda4
DS
200}
201
718e3744 202# Check finaly alive $cmd;
203foreach (keys %odefun) {
204 my ($node, $str) = (split (/,/));
205 my ($cmd) = $ocmd{$_};
206 $live{$cmd} = $_;
207}
208
209# Output DEFSH
74818bb1 210foreach (sort keys %live) {
718e3744 211 my ($proto);
212 my ($key);
213 $key = $live{$_};
214 $proto = join ("|", @{$oproto{$key}});
abaaab4e 215 printf "$defsh{$key} ($proto$odefun{$key})\n\n";
718e3744 216}
217
218# Output install_element
219print <<EOF;
220void
221vtysh_init_cmd ()
222{
223EOF
224
74818bb1 225foreach (sort keys %odefun) {
718e3744 226 my ($node, $str) = (split (/,/));
227 $cmd = $ocmd{$_};
228 $cmd =~ s/_cmd/_cmd_vtysh/;
229 printf " install_element ($node, &$cmd);\n";
230}
231
232print <<EOF
233}
234EOF