From: Martin Mares Date: Thu, 8 Feb 2007 22:00:26 +0000 (+0100) Subject: Implemented substition of configuration variables. X-Git-Tag: holmes-import~506^2~109^2~2 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=15ea795b7c38ac31c2d00e051fddb65b12e8310c;p=libucw.git Implemented substition of configuration variables. --- diff --git a/build/genconf b/build/genconf index 5e2269b0..29565a9c 100755 --- a/build/genconf +++ b/build/genconf @@ -1,6 +1,6 @@ #!/usr/bin/perl # Configuration file and script preprocessor -# (c) 2004 Martin Mares +# (c) 2004--2007 Martin Mares use strict; use warnings; @@ -9,9 +9,14 @@ use warnings; open CF, $ARGV[2] or die "Unable to open $ARGV[2]"; my %options = (); +my %vars = (); while () { - /^(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; @@ -51,6 +56,12 @@ while () { 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; } }