Don't strip comments until after embedded Perl or Shell have been handled.

Signed-off-by: Tom Eastep <teastep@shorewall.net>
This commit is contained in:
Tom Eastep 2012-04-09 15:12:13 -07:00
parent 94097e2561
commit 7b511f449f

View File

@ -1559,8 +1559,12 @@ sub process_conditional( $$$ ) {
my ($keyword, $rest) = ( $1, $2 ); my ($keyword, $rest) = ( $1, $2 );
$rest = '' unless supplied $rest; if ( supplied $rest ) {
$rest =~ s/\s*$//; $rest =~ s/#.*//;
$rest =~ s/\s*$//;
} else {
$rest = '';
}
my ( $lastkeyword, $prioromit, $lastomit, $lastlinenumber ) = @ifstack ? @{$ifstack[-1]} : ('', 0, 0, 0 ); my ( $lastkeyword, $prioromit, $lastomit, $lastlinenumber ) = @ifstack ? @{$ifstack[-1]} : ('', 0, 0, 0 );
@ -2133,6 +2137,18 @@ sub expand_variables( \$ ) {
} }
} }
#
# Handle first-entry processing
#
sub handle_first_entry() {
#
# $first_entry can contain either a function reference or a message. If it
# contains a reference, call the function -- otherwise issue the message
#
reftype( $first_entry ) ? $first_entry->() : progress_message2( $first_entry );
$first_entry = 0;
}
# #
# Read a line from the current include stack. # Read a line from the current include stack.
# #
@ -2169,31 +2185,16 @@ sub read_a_line(;$$$$) {
# If this isn't a continued line, remove trailing comments. Note that # If this isn't a continued line, remove trailing comments. Note that
# the result may now end in '\'. # the result may now end in '\'.
# #
s/\s*#.*$// if $strip_comments && ! /\\$/; s/\s*#.*$// if $strip_comments && /[\\]\s*#.*$/;
# #
# Continuation # Continuation
# #
chop $currentline, next if substr( ( $currentline .= $_ ), -1, 1 ) eq '\\'; chop $currentline, next if substr( ( $currentline .= $_ ), -1, 1 ) eq '\\';
# #
# Now remove concatinated comments
#
$currentline =~ s/#.*$// if $strip_comments;
#
# Ignore ( concatenated ) Blank Lines # Ignore ( concatenated ) Blank Lines
# #
$currentline = '', $currentlinenumber = 0, next if $currentline =~ /^\s*$/ && $suppress_whitespace; $currentline = '', $currentlinenumber = 0, next if $currentline =~ /^\s*$/ && $suppress_whitespace;
# #
# Line not blank -- Handle any first-entry message/capabilities check
#
if ( $first_entry ) {
#
# $first_entry can contain either a function reference or a message. If it
# contains a reference, call the function -- otherwise issue the message
#
reftype( $first_entry ) ? $first_entry->() : progress_message2( $first_entry );
$first_entry = 0;
}
#
# Handle conditionals # Handle conditionals
# #
if ( $currentline =~ /^\s*\?(?:IF|ELSE|ENDIF)/ ) { if ( $currentline =~ /^\s*\?(?:IF|ELSE|ENDIF)/ ) {
@ -2205,6 +2206,7 @@ sub read_a_line(;$$$$) {
if ( $omitting ) { if ( $omitting ) {
print "OMIT=> $currentline\n" if $debug; print "OMIT=> $currentline\n" if $debug;
$currentline=''; $currentline='';
$currentlinenumber = 0;
next; next;
} }
# #
@ -2212,15 +2214,29 @@ sub read_a_line(;$$$$) {
# #
if ( $embedded_enabled ) { if ( $embedded_enabled ) {
if ( $currentline =~ s/^\s*(BEGIN\s+)?SHELL\s*;?// ) { if ( $currentline =~ s/^\s*(BEGIN\s+)?SHELL\s*;?// ) {
handle_first_entry if $first_entry;
embedded_shell( $1 ); embedded_shell( $1 );
next; next;
} }
if ( $currentline =~ s/^\s*(BEGIN\s+)?PERL\s*\;?// ) { if ( $currentline =~ s/^\s*(BEGIN\s+)?PERL\s*\;?// ) {
handle_first_entry if $first_entry;
embedded_perl( $1 ); embedded_perl( $1 );
next; next;
} }
} }
#
# Now remove concatinated comments
#
$currentline =~ s/\s*#.*$// if $strip_comments;
#
# Ignore ( concatenated ) Blank Lines after comments are removed.
#
$currentline = '', $currentlinenumber = 0, next if $currentline =~ /^\s*$/ && $suppress_whitespace;
#
# Line not blank -- Handle any first-entry message/capabilities check
#
handle_first_entry if $first_entry;
my $count = 0; my $count = 0;
# #