Extantiate params during module processing

This commit is contained in:
Tom Eastep 2010-12-25 14:48:14 -08:00
parent bdc3ca16a4
commit 758a50fa84
2 changed files with 39 additions and 1 deletions

View File

@ -96,6 +96,8 @@ our %EXPORT_TAGS = ( internal => [ qw( create_temp_script
close_file
push_open
pop_open
push_params
pop_params
read_a_line
validate_level
which
@ -274,6 +276,10 @@ our @openstack;
# From the params file
#
our %params;
#
# Action parameters
#
our %actparms;
our $currentline; # Current config file line image
our $currentfile; # File handle reference
@ -717,6 +723,8 @@ sub initialize( $ ) {
command => '',
files => '',
destination => '' );
%actparms = ();
}
my @abbr = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec );
@ -1781,6 +1789,27 @@ sub embedded_perl( $ ) {
}
}
#
# Push/pop action params
#
sub push_params( $ ) {
my @params = split /,/, $_[0];
my $oldparams = \%actparms;
%actparms = ();
for ( my $i = 1; $i <= @params; $i++ ) {
$actparms{$i} = $params[$i - 1];
}
$oldparams;
}
sub pop_params( $ ) {
my $oldparms = shift;
%actparms = %$oldparms;
}
#
# Read a line from the current include stack.
#
@ -1866,7 +1895,8 @@ sub read_a_line(;$) {
$params{$3} = $ENV{$3} if exists $ENV{$3};
}
my $val = $params{$3};
my $val = exists $params{$3} ? $params{$3} : $actparms{$3};
unless ( defined $val ) {
fatal_error "Undefined shell variable (\$$3)" unless exists $params{$3} || exists $ENV{$3};

View File

@ -278,6 +278,8 @@ sub process_action2( $ ) {
fatal_error "Actions nested too deeply" if ++$action_nest_level > MAX_ACTION_NEST_LEVEL;
push_open( $actionfile );
my $oldparms = push_params( $param );
while ( read_a_line ) {
@ -309,6 +311,8 @@ sub process_action2( $ ) {
pop_open;
--$action_nest_level;
pop_params( $oldparms );
}
sub process_actions1() {
@ -398,6 +402,8 @@ sub process_action3( $$$$$$ ) {
open_file $actionfile;
my $oldparms = push_params( $param );
while ( read_a_line ) {
my ($target, $source, $dest, $proto, $ports, $sports, $origdest, $rate, $user, $mark, $connlimit, $time, $headers );
@ -424,6 +430,8 @@ sub process_action3( $$$$$$ ) {
}
clear_comment;
pop_params( $oldparms );
}
#