From 5ee554708c98673f6bad75a6ef7cd424cf7c13a5 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Tue, 10 Apr 2012 13:51:25 -0700 Subject: [PATCH] Control the proliferation of arguments to read_a_line() by using a bit-mapped single argument. Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Config.pm | 29 +++++++++++++++++++++-------- Shorewall/Perl/Shorewall/Misc.pm | 2 +- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index e385792c6..c0e3930e3 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -150,6 +150,11 @@ our %EXPORT_TAGS = ( internal => [ qw( create_temp_script MIN_VERBOSITY MAX_VERBOSITY + + EMBEDDED_ENABLED + EXPAND_VARIABLES + STRIP_COMMENTS + SUPPRESS_WHITESPACE ) ] ); Exporter::export_ok_tags('internal'); @@ -438,6 +443,13 @@ my $ifstack; # From .shorewallrc # our %shorewallrc; +# +# read_a_line flags +# +use constant { EMBEDDED_ENABLED => 1, + EXPAND_VARIABLES => 2, + STRIP_COMMENTS => 4, + SUPPRESS_WHITESPACE => 8 }; sub process_shorewallrc($); # @@ -1943,7 +1955,7 @@ sub first_entry( $ ) { } } -sub read_a_line(;$$$$); +sub read_a_line(;$); sub embedded_shell( $ ) { my $multiline = shift; @@ -1960,7 +1972,7 @@ sub embedded_shell( $ ) { my $last = 0; - while ( read_a_line( 0, 0, 0, 0 ) ) { + while ( read_a_line( 0 ) ) { last if $last = $currentline =~ s/^\s*END(\s+SHELL)?\s*;?//; $command .= "$currentline\n"; } @@ -1994,7 +2006,7 @@ sub embedded_perl( $ ) { my $last = 0; - while ( read_a_line( 0, 0, 0, 0 ) ) { + while ( read_a_line( 0 ) ) { last if $last = $currentline =~ s/^\s*END(\s+PERL)?\s*;?//; $command .= "$currentline\n"; } @@ -2161,11 +2173,12 @@ sub handle_first_entry() { # - Handle ?IF, ?ELSE, ?ENDIF # -sub read_a_line(;$$$$) { - my $embedded_enabled = defined $_[0] ? shift : 1; - my $expand_variables = defined $_[0] ? shift : 1; - my $strip_comments = defined $_[0] ? shift : 1; - my $suppress_whitespace = defined $_[0] ? shift : 1; +sub read_a_line(;$) { + my $flags = defined $_[0] ? $_[0] : 0xffff; + my $embedded_enabled = $flags & EMBEDDED_ENABLED; + my $expand_variables = $flags & EXPAND_VARIABLES; + my $strip_comments = $flags & STRIP_COMMENTS; + my $suppress_whitespace = $flags & SUPPRESS_WHITESPACE; while ( $currentfile ) { diff --git a/Shorewall/Perl/Shorewall/Misc.pm b/Shorewall/Perl/Shorewall/Misc.pm index aff43ad81..e48315c9e 100644 --- a/Shorewall/Perl/Shorewall/Misc.pm +++ b/Shorewall/Perl/Shorewall/Misc.pm @@ -346,7 +346,7 @@ sub remove_blacklist( $ ) { open $newfile, '>', "$fn.new" or fatal_error "Unable to open $fn.new for output: $!"; - while ( read_a_line(1,1,0) ) { + while ( read_a_line( EMBEDDED_ENABLED + EXPAND_VARIABLES ) ) { my ( $rule, $comment ) = split '#', $currentline, 2; if ( $rule =~ /blacklist/ ) {