From fe089ddc36f3f7d57501dd7e5635077158f03f9b Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sat, 6 Mar 2010 07:40:43 -0800 Subject: [PATCH] Don't copy headers in imported libraries Signed-off-by: Tom Eastep --- Shorewall/Perl/Shorewall/Compiler.pm | 13 +------ Shorewall/Perl/Shorewall/Config.pm | 57 ++++++++++++++++++++++++++++ Shorewall/lib.common | 4 -- Shorewall6/lib.common | 4 -- 4 files changed, 59 insertions(+), 19 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Compiler.pm b/Shorewall/Perl/Shorewall/Compiler.pm index 135fffee5..32e5edb49 100644 --- a/Shorewall/Perl/Shorewall/Compiler.pm +++ b/Shorewall/Perl/Shorewall/Compiler.pm @@ -93,21 +93,12 @@ sub generate_script_1() { copy $globals{SHAREDIRPL} . 'prog.header6'; } - copy $globals{SHAREDIR} . '/lib.common'; + copy2 $globals{SHAREDIR} . '/lib.common'; } my $lib = find_file 'lib.private'; - if ( -f $lib ) { - emit <<'EOF'; -################################################################################ -# Functions imported from lib.private -################################################################################ -EOF - - copy1 $lib; - emit "\n"; - } + copy2 $lib if -f $lib; emit <<'EOF'; ################################################################################ diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index af716d50c..6ed4e05d9 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -81,6 +81,7 @@ our %EXPORT_TAGS = ( internal => [ qw( create_temp_script pop_indent copy copy1 + copy2 create_temp_aux_config finalize_aux_config set_shorewall_dir @@ -1199,6 +1200,62 @@ sub copy1( $ ) { $result; } +# +# This one drops header comments and replaces them with a three-line banner +# +sub copy2( $ ) { + assert( $script_enabled ); + + if ( $script ) { + my $file = $_[0]; + my $first = 1; + + open IF , $file or fatal_error "Unable to open $file: $!"; + + while ( ) { + last unless /^#/; + $first = 0; + } + + print $script < ) { + chomp; + if ( /^\s*$/ ) { + print $script "\n" unless $lastlineblank; + $lastlineblank = 1; + } else { + if ( $indent ) { + s/^(\s*)/$indent1$1$indent2/; + s/ /\t/ if $indent2; + } + + print $script $_; + print $script "\n"; + $lastlineblank = 0; + } + } + + close IF; + + print $script "\n" unless $lastlineblank; + + print $script <