From 9869420106927a2466b250f8126d98bd1912d85e Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sun, 3 Jun 2012 08:43:48 -0700 Subject: [PATCH] Check for conditional directives prior to continuation Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Config.pm | 42 +++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index b0bf81323..8e5e68b7c 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -1652,8 +1652,14 @@ sub have_capability( $ ); sub process_conditional( $$$ ) { my ( $omitting, $line, $linenumber ) = @_; + # + # Save/set $currentlinenumber so that fatal_error will report correct line number + # + my $save_currentlinenumber = $currentlinenumber; - print "CD===> $currentline\n" if $debug; + $currentlinenumber = $linenumber; + + print "CD===> $line\n" if $debug; fatal_error "Invalid compiler directive ($line)" unless $line =~ /^\s*\?(IF\s+|ELSE|ENDIF)(.*)$/; @@ -1705,6 +1711,10 @@ sub process_conditional( $$$ ) { $omitting = $prioromit; pop @ifstack; } + # + # Restore $currentlinenumber + # + $currentlinenumber = $save_currentlinenumber; $omitting; } @@ -2264,10 +2274,21 @@ sub read_a_line($) { $currentlinenumber = 0; while ( <$currentfile> ) { + chomp; + # + # Handle conditionals + # + if ( /^\s*\?(?:IF|ELSE|ENDIF)/ ) { + $omitting = process_conditional( $omitting, $_, $. ); + next; + } + + if ( $omitting ) { + print "OMIT=> $_\n" if $debug; + next; + } $currentlinenumber = $. unless $currentlinenumber; - - chomp; # # Suppress leading whitespace in certain continuation lines # @@ -2282,21 +2303,6 @@ sub read_a_line($) { # chop $currentline, next if ($currentline .= $_) =~ /\\$/; # - # Handle conditionals - # - if ( $currentline =~ /^\s*\?(?:IF|ELSE|ENDIF)/ ) { - $omitting = process_conditional( $omitting, $currentline, $currentlinenumber ); - $currentline=''; - next; - } - - if ( $omitting ) { - print "OMIT=> $currentline\n" if $debug; - $currentline=''; - $currentlinenumber = 0; - next; - } - # # Must check for shell/perl before doing variable expansion # if ( $options & EMBEDDED_ENABLED ) {