From 575020c8517e0b553e050251262558fb6545d529 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Mon, 24 Dec 2012 13:35:42 -0800 Subject: [PATCH] More comment handling Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Config.pm | 37 +++++++++++++++++++++++------- Shorewall/Perl/Shorewall/Rules.pm | 8 ++++--- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index fd1af773c..80b059224 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -2006,6 +2006,7 @@ sub do_open_file( $ ) { $currentfilename = $fname; } + sub open_file( $;$$$ ) { my ( $fname, $mf, $ca, $nc ) = @_; @@ -2018,7 +2019,7 @@ sub open_file( $;$$$ ) { $file_format = 1; $max_format = supplied $mf ? $mf : 1; $comments_allowed = supplied $ca ? $ca : 0; - $nocomment++ if supplied( $ca ) && no_comment; + $nocomment = $nc; do_open_file $fname;; } else { $ifstack = @ifstack; @@ -2026,6 +2027,20 @@ sub open_file( $;$$$ ) { } } +# +# Push open-specific globals onto the include stack +# +sub push_include() { + push @includestack, [ $currentfile, + $currentfilename, + $currentlinenumber, + $ifstack, + $file_format, + $max_format, + $comment, + $nocomment ]; +} + # # Pop the include stack # @@ -2039,8 +2054,14 @@ sub pop_include() { } if ( $arrayref ) { - ( $currentfile, $currentfilename, $currentlinenumber, $ifstack, $file_format, $max_format, $nocomment ) = @$arrayref; - $comment = '' unless @openstack; + ( $currentfile, + $currentfilename, + $currentlinenumber, + $ifstack, + $file_format, + $max_format, + $comment, + $nocomment ) = @$arrayref; } else { $currentfile = undef; $currentlinenumber = 'EOF'; @@ -2433,7 +2454,7 @@ sub copy1( $ ) { fatal_error "Directory ($filename) not allowed in INCLUDE" if -d _; if ( -s _ ) { - push @includestack, [ $currentfile, $currentfilename, $currentlinenumber, $ifstack, $file_format, $max_format, $nocomment ]; + push_include; $currentfile = undef; do_open_file $filename; } else { @@ -2571,7 +2592,7 @@ EOF # sub push_open( $;$$$ ) { my ( $file, $max , $ca, $nc ) = @_; - push @includestack, [ $currentfile, $currentfilename, $currentlinenumber, $ifstack, $file_format, $max_format, $nocomment ] if $currentfile; + push_include; my @a = @includestack; push @openstack, \@a; @includestack = (); @@ -2654,7 +2675,7 @@ sub embedded_shell( $ ) { $command .= q('); - push @includestack, [ $currentfile, $currentfilename, $currentlinenumber, $ifstack , $file_format, $max_format, $nocomment ]; + push_include; $currentfile = undef; open $currentfile , '-|', $command or fatal_error qq(Shell Command failed); $currentfilename = "SHELL\@$currentfilename:$currentlinenumber"; @@ -2716,7 +2737,7 @@ sub embedded_perl( $ ) { $perlscript = undef; - push @includestack, [ $currentfile, $currentfilename, $currentlinenumber , $ifstack , $file_format, $max_format, $nocomment ]; + push_include; $currentfile = undef; open $currentfile, '<', $perlscriptname or fatal_error "Unable to open Perl Script $perlscriptname"; @@ -3003,7 +3024,7 @@ sub read_a_line($) { fatal_error "Directory ($filename) not allowed in INCLUDE" if -d _; if ( -s _ ) { - push @includestack, [ $currentfile, $currentfilename, $currentlinenumber, $ifstack , $file_format, $max_format, $nocomment ]; + push_include; $currentfile = undef; do_open_file $filename; } else { diff --git a/Shorewall/Perl/Shorewall/Rules.pm b/Shorewall/Perl/Shorewall/Rules.pm index db967fd31..909deca36 100644 --- a/Shorewall/Perl/Shorewall/Rules.pm +++ b/Shorewall/Perl/Shorewall/Rules.pm @@ -1639,7 +1639,7 @@ sub process_macro ($$$$$$$$$$$$$$$$$$$) { progress_message "..Expanding Macro $macrofile..."; - push_open $macrofile, 2, 1, 1; + push_open $macrofile, 2, 1, no_comment; macro_comment $macro; @@ -1767,9 +1767,9 @@ sub process_inline ($$$$$$$$$$$$$$$$$$$$) { progress_message "..Expanding inline action $inlinefile..."; - push_open $inlinefile, 2, 1, 1; + push_open $inlinefile, 2, 1; - macro_comment $inline; + push_comment(''); while ( read_a_line( NORMAL_READ ) ) { my ( $mtarget, @@ -1855,6 +1855,8 @@ sub process_inline ($$$$$$$$$$$$$$$$$$$$) { progress_message " Rule \"$currentline\" $done"; } + pop_comment; + pop_open; progress_message "..End inline action $inlinefile";