summaryrefslogtreecommitdiff
path: root/Porting
diff options
context:
space:
mode:
authorMarcus Holland-Moritz <mhx-perl@gmx.net>2008-10-12 02:51:44 +0000
committerMarcus Holland-Moritz <mhx-perl@gmx.net>2008-10-12 02:51:44 +0000
commitd5f3326709737080f113937629ab2010559f0729 (patch)
tree8cb26289dd8043883f66f85a7dd0dc41c454a5c8 /Porting
parentbe4f373d52665c10481b8bb9351422b96274c44c (diff)
downloadperl-d5f3326709737080f113937629ab2010559f0729.tar.gz
Make expand-macro.pl accept macro expressions, i.e. macros with
arguments. This makes it much more convenient to get expanded expressions that can be directly copied to a debugger. This is optional, so the original behaviour is maintained. Allow to read the macro name or expression from stdin, which can be useful for feeding it multi-line macro expressions. Use Pod::Usage and move the usage to POD section. p4raw-id: //depot/perl@34474
Diffstat (limited to 'Porting')
-rw-r--r--Porting/expand-macro.pl66
1 files changed, 39 insertions, 27 deletions
diff --git a/Porting/expand-macro.pl b/Porting/expand-macro.pl
index 87f369fc43..2cdaa79727 100644
--- a/Porting/expand-macro.pl
+++ b/Porting/expand-macro.pl
@@ -1,54 +1,44 @@
#!perl -w
use strict;
+use Pod::Usage;
use Getopt::Std;
+$Getopt::Std::STANDARD_HELP_VERSION = 1;
-use vars qw($trysource $tryout $sentinel);
-$trysource = "try.c";
-$tryout = "try.i";
+my $trysource = "try.c";
+my $tryout = "try.i";
-getopts('fF:ekvI:', \my %opt) or usage();
+getopts('fF:ekvI:', \my %opt) or pod2usage();
-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;
-usage "missing <macro-name>" unless defined $macro;
+my($expr, @headers) = @ARGV ? splice @ARGV : "-";
-$sentinel = "$macro expands to";
-
-usage "-f and -F <tool> are exclusive\n" if $opt{f} and $opt{F};
+pod2usage "-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 $_;
}
-if (!@ARGV) {
+if ($expr eq '-') {
+ warn "reading from stdin...\n";
+ $expr = do { local $/; <> };
+}
+
+my($macro, $args) = $expr =~ /^\s*(\w+)((?:\s*\(.*\))?)\s*;?\s*$/s
+ or pod2usage "$expr doesn't look like a macro-name or macro-expression to me";
+
+if (!(@ARGV = @headers)) {
open my $fh, '<', 'MANIFEST' or die "Can't open MANIFEST: $!";
while (<$fh>) {
push @ARGV, $1 if m!^([^/]+\.h)\t!;
}
}
-my $args = '';
-
my $header;
while (<>) {
next unless /^#\s*define\s+$macro\b/;
my ($def_args) = /^#\s*define\s+$macro\(([^)]*)\)/;
- if (defined $def_args) {
+ if (defined $def_args && !$args) {
my @args = split ',', $def_args;
print "# macro: $macro args: @args in $_\n" if $opt{v};
my $argname = "A0";
@@ -61,6 +51,8 @@ die "$macro not found\n" unless defined $header;
open my $out, '>', $trysource or die "Can't open $trysource: $!";
+my $sentinel = "$macro expands to";
+
print $out <<"EOF";
#include "EXTERN.h"
#include "perl.h"
@@ -106,3 +98,23 @@ unless ($opt{k}) {
die "Can't unlink $_" unless unlink $_;
}
}
+
+__END__
+
+=head1 NAME
+
+expand-macro.pl - expand C macros using the C preprocessor
+
+=head1 SYNOPSIS
+
+ expand-macro.pl [options] [ < macro-name | macro-expression | - > [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 they're present (errdetect)
+ -k keep them after generating (for handy inspection)
+ -v verbose
+ -I <indent-opts> passed into indent
+
+=cut