blob: 47053102df2bc4a81cfd084b1200da770a21c694 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
#!/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<openquote>] [-C<closequote>] [-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 (<CONTROL>) {
chomp;
if (/^define\s+(\w+)\s+['"]?(.+?)['"]?\s*$/) {
$Parms{$1} = $2
}
}
}
}
while (<STDIN>) {
s{
\Q$open_quote\E
\s*
(
\w+
)
\s*
\Q$close_quote\E
}{
$Parms{$1}
}xge;
print;
}
|