From 8f9d5a967bc4a2dfd30d27ec0e4a2376015aaf0f Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sun, 26 Dec 2010 11:07:00 -0800 Subject: [PATCH] Simplify variable substitution --- Shorewall/Perl/Shorewall/Config.pm | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index 4903b7d16..a41d4c603 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -1885,25 +1885,23 @@ sub read_a_line(;$) { # # Expand Shell Variables using %params and %ENV # - # $1 $2 $3 - $4 + # $1 $2 $3 - $4 while ( $currentline =~ m( ^(.*?) \$({)? (\w+) (?(2)}) (.*)$ )x ) { - unless ( exists $params{$3} ) { - # - # Given the way that getparams works, this should never help but better safe than sorry - # - $params{$3} = $ENV{$3} if exists $ENV{$3}; + my ( $first, $var, $rest ) = ( $1, $3, $4); + + my $val; + + if ( $var =~ /^\$\d+$/ ) { + fatal_error "Undefined parameter (\$$var)" unless exists $actparms{$var}; + $val = $actparms{$var}; + } else { + fatal_error "Undefined shell variable (\$$var)" unless exists $params{$var}; + $val = $params{$var}; } - - 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}; - $val = ''; - } - - $currentline = join( '', $1 , $val , $4 ); + $val = '' unless defined $val; + $currentline = join( '', $first , $val , $rest ); fatal_error "Variable Expansion Loop" if ++$count > 100; }