diff options
author | Nicholas Clark <nick@ccl4.org> | 2008-02-22 20:06:15 +0000 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2008-02-22 20:06:15 +0000 |
commit | 27c6397cdef882675fd24e716944ef4ce35abe7b (patch) | |
tree | cd0c9218b7319fa862169f2570ae2d9d9afa31d6 /Porting | |
parent | a93e78e3a0993367922540f294652a138d1d7225 (diff) | |
download | perl-27c6397cdef882675fd24e716944ef4ce35abe7b.tar.gz |
Take advantage of the fact that we can use indent as a stdin/stdout
filter to reduce its workload (and ours) by only sending it the 3 or
so lines that we are interested in printing, not the preceding
bucket loads.
p4raw-id: //depot/perl@33353
Diffstat (limited to 'Porting')
-rw-r--r-- | Porting/expand-macro.pl | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/Porting/expand-macro.pl b/Porting/expand-macro.pl index aee4f3670d..472b789a32 100644 --- a/Porting/expand-macro.pl +++ b/Porting/expand-macro.pl @@ -74,14 +74,30 @@ print "doing: make $tryout\n" if $opt{v}; system "make $tryout" and die; # if user wants 'indent' formatting .. -$opt{I} //= ''; -system "indent $opt{I} $tryout" and die if $opt{f}; -system "$opt{F} $opt{I} $tryout" and die if $opt{F}; +my $out_fh; + +if ($opt{f} || $opt{F}) { + # a: indent is a well behaved filter when given 0 arguments, reading from + # stdin and writing to stdout + # b: all our braces should be balanced, indented back to column 0, in the + # headers, hence everything before our #line directive can be ignored + # + # We can take advantage of this to reduce the work to indent. + + my $indent_command = $opt{f} ? 'indent' : $opt{F}; + + if (defined $opt{I}) { + $indent_command .= " $opt{I}"; + } + open $out_fh, '|-', $indent_command or die $?; +} else { + $out_fh = \*STDOUT; +} open my $fh, '<', $tryout or die "Can't open $tryout: $!"; while (<$fh>) { - print if /$sentinel/o .. 1; + print $out_fh $_ if /$sentinel/o .. 1; } unless ($opt{k}) { |