From 8803cd8d3bb46383a166a16065f365d097e8dab6 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Mon, 19 Mar 2012 12:51:22 -0700 Subject: [PATCH] ?IF improvements - Pass line number to make process_conditional more general - Add debugging output - Do first_line processing prior to looking for ? Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Config.pm | 36 ++++++++++++++++-------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index 6f45e8249..280b382fc 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -1525,8 +1525,10 @@ sub close_file() { } } -sub process_conditional( $$ ) { - my ( $omitting, $line ) = @_; +sub process_conditional( $$$ ) { + my ( $omitting, $line, $linenumber ) = @_; + + print "CD===> $currentline\n" if $debug; fatal_error "Invalid compiler directive ($line)" unless $line =~ /^\s*\?(IF\s+|ELSE|ENDIF)(.*)$/; @@ -1542,7 +1544,7 @@ sub process_conditional( $$ ) { fatal_error "Invalid IF variable ($rest)" unless ($rest =~ s/^\$// || $rest =~ /^__/ ) && $rest =~ /^\w+$/; - push @ifstack, [ 'IF', $lastomit, $omitting, $currentlinenumber ]; + push @ifstack, [ 'IF', $lastomit, $omitting, $linenumber ]; if ( $rest eq '__IPV6' ) { $omitting = $family == F_IPV4; @@ -2094,20 +2096,6 @@ sub read_a_line(;$$$) { # $currentline = '', $currentlinenumber = 0, next if $currentline =~ /^\s*$/; # - # Line not blank -- Handle conditionals - # - if ( $currentline =~ /^\s*\?/ ) { - $omitting = process_conditional( $omitting, $currentline); - $currentline=''; - next; - } - - if ( $omitting ) { - progress_message " OMITTED: $currentline"; - $currentline=''; - next; - } - # # Line not blank -- Handle any first-entry message/capabilities check # if ( $first_entry ) { @@ -2119,6 +2107,20 @@ sub read_a_line(;$$$) { $first_entry = 0; } # + # Handle conditionals + # + if ( $currentline =~ /^\s*\?/ ) { + $omitting = process_conditional( $omitting, $currentline, $currentlinenumber ); + $currentline=''; + next; + } + + if ( $omitting ) { + print "OMIT=> $currentline\n" if $debug; + $currentline=''; + next; + } + # # Must check for shell/perl before doing variable expansion # if ( $embedded_enabled ) {