From 0e5cb7fa89cfd955ca0c52927bbcd273ac5930d9 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Thu, 31 Jul 2003 22:38:25 +0000 Subject: [PATCH] We have to support substitutions in here now. Joy. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@2738 542714f4-19e9-0310-aa3c-eee0fc999fb1 --- bin/configpp | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/bin/configpp b/bin/configpp index e2a839942..b4e8017ba 100755 --- a/bin/configpp +++ b/bin/configpp @@ -1,6 +1,6 @@ #!/usr/bin/perl -w # -# $Id: configpp,v 1.1 2002/10/08 18:46:02 mdb Exp $ +# $Id: configpp,v 1.2 2003/07/31 22:38:25 mdb Exp $ # # Preprocesses a configuration file (a .dop file, for instance), executing # any include directives located in the file. @@ -8,7 +8,17 @@ use File::Basename; my %files = (); -my $file = shift or die "Usage: $0 file\n"; +my $file = shift or die "Usage: $0 file [key=value key=value...]\n"; + +my %subs; +while ($pair = shift) { + if ($pair =~ m/(\S+)=(\S+)/) { + $subs{$1} = $2; + } else { + warn "Unable to parse substitution '$pair'.\n"; + } +} +my $scount = keys %subs; # change into the directory occupied by the file chdir(dirname($file)); @@ -33,6 +43,17 @@ sub read_file { if (m/^.include \"([^\"]*)\"/) { # process the inclusion read_file($1, $path); + + } elsif ($scount > 0 && m/\@[\S]+\@/) { + # handle any substitutions + while (m/\@([-A-Za-z_.]+)\@/) { + my $key = $1; + my $value = $subs{$key}; + $value = $key unless (defined $value); + $_ =~ s/\@$key\@/$value/; + } + print $_; + } else { print $_; }