#!/usr/bin/perl
# Configuration file and script preprocessor
-# (c) 2004 Martin Mares <mj@ucw.cz>
+# (c) 2004--2007 Martin Mares <mj@ucw.cz>
use strict;
use warnings;
open CF, $ARGV[2] or die "Unable to open $ARGV[2]";
my %options = ();
+my %vars = ();
while (<CF>) {
- /^(CONFIG_\w+)=[^0]/ || next;
- $options{$1} = 1;
+ chomp;
+ if (my ($k,$v) = /^(\w+)=(.*)/) {
+ $v =~ s/\s+$//;
+ $vars{$k} = $v;
+ $options{$k} = 1 if ($k =~ /^CONFIG_/);
+ }
}
close CF;
die "Piped command '$cmd' failed" if $?;
print OUT `$1`;
} else {
+ sub repl ($) {
+ my $v = shift @_;
+ exists $vars{$v} or die "Cannot substitute $v: variable not set";
+ return $vars{$v};
+ }
+ s/@(\w+)@/repl($1)/ge;
print OUT;
}
}