Use open_file()/close_file() in copy1

This commit is contained in:
Tom Eastep 2011-01-15 14:33:16 -08:00
parent 978e8e3849
commit 5c4da0b581

View File

@ -1195,6 +1195,8 @@ sub copy( $ ) {
} }
} }
sub close_file();
# #
# This one handles line continuation and 'here documents' # This one handles line continuation and 'here documents'
@ -1204,72 +1206,72 @@ sub copy1( $ ) {
my $result = 0; my $result = 0;
if ( $script || $debug ) { if ( $script || $debug ) {
my $file = $_[0];
open IF , $file or fatal_error "Unable to open $file: $!";
my ( $do_indent, $here_documents ) = ( 1, ''); my ( $do_indent, $here_documents ) = ( 1, '');
while ( <IF> ) { open_file( $_[0] );
chomp;
while ( $currentfile ) {
while ( <$currentfile> ) {
chomp;
if ( /^${here_documents}\s*$/ ) { if ( /^${here_documents}\s*$/ ) {
if ( $script ) { if ( $script ) {
print $script $here_documents if $here_documents; print $script $here_documents if $here_documents;
print $script "\n"; print $script "\n";
}
if ( $debug ) {
print "GS-----> $here_documents" if $here_documents;
print "GS----->\n";
}
$do_indent = 1;
$here_documents = '';
next;
} }
if ( $debug ) { if ( $do_indent && /.*<<\s*([^ ]+)s*(.*)/ ) {
print "GS-----> $here_documents" if $here_documents; $here_documents = $1;
print "GS----->\n"; 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; if ( $indent && $do_indent ) {
$here_documents = ''; s/^(\s*)/$indent1$1$indent2/;
next; s/ /\t/ if $indent2;
} }
if ( $do_indent && /.*<<\s*([^ ]+)s*(.*)/ ) {
$here_documents = $1;
s/^(\s*)/$indent1$1$indent2/;
s/ /\t/ if $indent2;
$do_indent = 0;
if ( $script ) { if ( $script ) {
print $script $_; print $script $_;
print $script "\n"; print $script "\n";
} }
$do_indent = ! ( $here_documents || /\\$/ );
$result = 1 unless $result || /^\s*$/ || /^\s*#/;
if ( $debug ) { if ( $debug ) {
s/\n/\nGS-----> /g; s/\n/\nGS-----> /g;
print "GS-----> $_\n"; print "GS-----> $_\n";
} }
$result = 1;
next;
} }
if ( $indent && $do_indent ) { close_file;
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 IF;
} }
$lastlineblank = 0; $lastlineblank = 0;