6 use vars qw($trysource $tryout $sentinel);
10 getopts('fF:ekvI:', \my %opt) or usage();
15 usage: $0 [options] <macro-name> [headers]
17 -f use 'indent' to format output
18 -F <tool> use <tool> to format output (instead of -f)
19 -e erase try.[ic] instead of failing when theyre present (errdetect)
20 -k keep them after generating (for handy inspection)
22 -I <indent-opts> passed into indent
27 usage "missing <macro-name>" unless defined $macro;
29 $sentinel = "$macro expands to";
31 usage "-f and -F <tool> are exclusive\n" if $opt{f} and $opt{F};
33 foreach($trysource, $tryout) {
35 die "You already have a $_" if -e $_;
39 open my $fh, '<', 'MANIFEST' or die "Can't open MANIFEST: $!";
41 push @ARGV, $1 if m!^([^/]+\.h)\t!;
49 next unless /^#\s*define\s+$macro\b/;
50 my ($def_args) = /^#\s*define\s+$macro\(([^)]*)\)/;
51 if (defined $def_args) {
52 my @args = split ',', $def_args;
53 print "# macro: $macro args: @args in $_\n" if $opt{v};
55 $args = '(' . join (', ', map {$argname++} 1..@args) . ')';
60 die "$macro not found\n" unless $found_macro;
62 open my $out, '>', $trysource or die "Can't open $trysource: $!";
71 close $out or die "Can't close $trysource: $!";
73 print "doing: make $tryout\n" if $opt{v};
74 system "make $tryout" and die;
76 # if user wants 'indent' formatting ..
78 system "indent $opt{I} $tryout" and die if $opt{f};
79 system "$opt{F} $opt{I} $tryout" and die if $opt{F};
81 open my $fh, '<', $tryout or die "Can't open $tryout: $!";
84 print if /$sentinel/o .. 1;
88 foreach($trysource, $tryout) {
89 die "Can't unlink $_" unless unlink $_;