diff options
author | Jim Cromie <jcromie@cpan.org> | 2008-02-07 10:03:22 -0700 |
---|---|---|
committer | Nicholas Clark <nick@ccl4.org> | 2008-02-22 19:47:52 +0000 |
commit | a93e78e3a0993367922540f294652a138d1d7225 (patch) | |
tree | 84a76d99061c796ad231126e3a3b0a1150d7d85d /Porting | |
parent | ec6c7eee5fd971644a9be3d1160b3f2aff419da1 (diff) | |
download | perl-a93e78e3a0993367922540f294652a138d1d7225.tar.gz |
[patch] Porting/expand-macros.pl gets 'indent'ing
Message-ID: <47AB9C4A.3080107@gmail.com>
Date: Thu, 07 Feb 2008 17:03:22 -0700
p4raw-id: //depot/perl@33352
Diffstat (limited to 'Porting')
-rw-r--r-- | Porting/expand-macro.pl | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/Porting/expand-macro.pl b/Porting/expand-macro.pl index caa4b472e1..aee4f3670d 100644 --- a/Porting/expand-macro.pl +++ b/Porting/expand-macro.pl @@ -1,16 +1,37 @@ #!perl -w use strict; +use Getopt::Std; + use vars qw($trysource $tryout $sentinel); $trysource = "try.c"; $tryout = "try.i"; +getopts('fF:ekvI:', \my %opt) or usage(); + +sub usage { + die<<EO_HELP; +@_; +usage: $0 [options] <macro-name> [headers] +options: + -f use 'indent' to format output + -F <tool> use <tool> to format output (instead of -f) + -e erase try.[ic] instead of failing when theyre present (errdetect) + -k keep them after generating (for handy inspection) + -v verbose + -I <indent-opts> passed into indent +EO_HELP +} + my $macro = shift; -die "$0 macro [headers]" unless defined $macro; +usage "missing <macro-name>" unless defined $macro; $sentinel = "$macro expands to"; +usage "-f and -F <tool> are exclusive\n" if $opt{f} and $opt{F}; + foreach($trysource, $tryout) { + unlink $_ if $opt{e}; die "You already have a $_" if -e $_; } @@ -23,16 +44,20 @@ if (!@ARGV) { my $args = ''; +my $found_macro; while (<>) { next unless /^#\s*define\s+$macro\b/; my ($def_args) = /^#\s*define\s+$macro\(([^)]*)\)/; if (defined $def_args) { my @args = split ',', $def_args; + print "# macro: $macro args: @args in $_\n" if $opt{v}; my $argname = "A0"; $args = '(' . join (', ', map {$argname++} 1..@args) . ')'; } + $found_macro++; last; } +die "$macro not found\n" unless $found_macro; open my $out, '>', $trysource or die "Can't open $trysource: $!"; @@ -45,14 +70,22 @@ EOF close $out or die "Can't close $trysource: $!"; +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}; + open my $fh, '<', $tryout or die "Can't open $tryout: $!"; while (<$fh>) { print if /$sentinel/o .. 1; } -foreach($trysource, $tryout) { - die "Can't unlink $_" unless unlink $_; +unless ($opt{k}) { + foreach($trysource, $tryout) { + die "Can't unlink $_" unless unlink $_; + } } |