From 349cfa7acb95abe865209a28e417ec74b56f9bba Mon Sep 17 00:00:00 2001 From: Alberto Gonzalez Iniesta Date: Tue, 21 Feb 2012 15:53:40 +0100 Subject: Imported Upstream version 2.2.1 --- install-win32/macro.pl | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 install-win32/macro.pl (limited to 'install-win32/macro.pl') diff --git a/install-win32/macro.pl b/install-win32/macro.pl new file mode 100644 index 0000000..08ba58a --- /dev/null +++ b/install-win32/macro.pl @@ -0,0 +1,61 @@ +#!/usr/bin/perl + +# Simple macro processor. + +# Macros are defined in a control file that follows +# a simple definition-based grammar as documented in the +# trans script. Stdin is then copied to stdout, and any +# occurrence of @@MACRO@@ is substituted. Macros can also +# be specified on the command line. + +die "usage: macro [-O] [-C] [-Dname=var ...] [control-file ...] " if (@ARGV < 1); + +%Parms = (); +$open_quote = "@@"; +$close_quote = "@@"; + +while ($arg=shift(@ARGV)) { + if ($arg =~ /^-/) { + if ($arg =~ /^-D(\w+)(?:=(.*))?$/) { + $Parms{$1} = $2 + } elsif ($arg =~ /-O(.*)$/) { + $open_quote = $1; + } elsif ($arg =~ /-C(.*)$/) { + $close_quote = $1; + } else { + die "unrecognized option: $arg"; + } + } else { + open(CONTROL, "< $arg") or die "cannot open $arg"; + while () { + if (/^!define\s+(\w+)(?:\s+['"]?(.*?)['"]?)?\s*$/) { + $Parms{$1} = $2; + } + } + } +} + +sub print_symbol_table { + foreach my $k (sort (keys(%Parms))) { + my $v = $Parms{$k}; + print "[$k] -> \"$v\"\n"; + } +} + +#print_symbol_table (); +#exit 0; + +while () { + s{ + \Q$open_quote\E + \s* + ( + \w+ + ) + \s* + \Q$close_quote\E + }{ + $Parms{$1} + }xge; + print; +} -- cgit v1.2.3