From 5c4da0b58185e26b74c1ec020a0f397f0f879fd9 Mon Sep 17 00:00:00 2001 From: Tom Eastep Date: Sat, 15 Jan 2011 14:33:16 -0800 Subject: [PATCH] Use open_file()/close_file() in copy1 --- Shorewall/Perl/Shorewall/Config.pm | 94 +++++++++++++++--------------- 1 file changed, 48 insertions(+), 46 deletions(-) diff --git a/Shorewall/Perl/Shorewall/Config.pm b/Shorewall/Perl/Shorewall/Config.pm index ce733a606..8f69db7a5 100644 --- a/Shorewall/Perl/Shorewall/Config.pm +++ b/Shorewall/Perl/Shorewall/Config.pm @@ -1195,6 +1195,8 @@ sub copy( $ ) { } } +sub close_file(); + # # This one handles line continuation and 'here documents' @@ -1204,72 +1206,72 @@ sub copy1( $ ) { my $result = 0; if ( $script || $debug ) { - my $file = $_[0]; - - open IF , $file or fatal_error "Unable to open $file: $!"; - my ( $do_indent, $here_documents ) = ( 1, ''); - while ( ) { - chomp; + open_file( $_[0] ); + + while ( $currentfile ) { + while ( <$currentfile> ) { + chomp; - if ( /^${here_documents}\s*$/ ) { - if ( $script ) { - print $script $here_documents if $here_documents; - print $script "\n"; + if ( /^${here_documents}\s*$/ ) { + if ( $script ) { + print $script $here_documents if $here_documents; + print $script "\n"; + } + + if ( $debug ) { + print "GS-----> $here_documents" if $here_documents; + print "GS----->\n"; + } + + $do_indent = 1; + $here_documents = ''; + next; } - if ( $debug ) { - print "GS-----> $here_documents" if $here_documents; - print "GS----->\n"; + if ( $do_indent && /.*<<\s*([^ ]+)s*(.*)/ ) { + $here_documents = $1; + s/^(\s*)/$indent1$1$indent2/; + s/ /\t/ if $indent2; + $do_indent = 0; + + if ( $script ) { + print $script $_; + print $script "\n"; + } + + if ( $debug ) { + s/\n/\nGS-----> /g; + print "GS-----> $_\n"; + } + + $result = 1; + next; } - $do_indent = 1; - $here_documents = ''; - next; - } - - if ( $do_indent && /.*<<\s*([^ ]+)s*(.*)/ ) { - $here_documents = $1; - s/^(\s*)/$indent1$1$indent2/; - s/ /\t/ if $indent2; - $do_indent = 0; + if ( $indent && $do_indent ) { + s/^(\s*)/$indent1$1$indent2/; + s/ /\t/ if $indent2; + } if ( $script ) { print $script $_; print $script "\n"; } + $do_indent = ! ( $here_documents || /\\$/ ); + + $result = 1 unless $result || /^\s*$/ || /^\s*#/; + if ( $debug ) { s/\n/\nGS-----> /g; print "GS-----> $_\n"; } - - $result = 1; - next; } - if ( $indent && $do_indent ) { - s/^(\s*)/$indent1$1$indent2/; - s/ /\t/ if $indent2; - } - - if ( $script ) { - print $script $_; - print $script "\n"; - } - - $do_indent = ! ( $here_documents || /\\$/ ); - - $result = 1 unless $result || /^\s*$/ || /^\s*#/; - - if ( $debug ) { - s/\n/\nGS-----> /g; - print "GS-----> $_\n"; - } + close_file; } - - close IF; } $lastlineblank = 0;