]> mj.ucw.cz Git - libucw.git/commitdiff
Implemented substition of configuration variables.
authorMartin Mares <mj@ucw.cz>
Thu, 8 Feb 2007 22:00:26 +0000 (23:00 +0100)
committerMartin Mares <mj@ucw.cz>
Thu, 8 Feb 2007 22:00:26 +0000 (23:00 +0100)
build/genconf

index 5e2269b0a76f12a0a835982870239182c18e807e..29565a9c48a9d3bc2e34c442cbd3b8b9c457b690 100755 (executable)
@@ -1,6 +1,6 @@
 #!/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;
@@ -9,9 +9,14 @@ 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;
 
@@ -51,6 +56,12 @@ while (<IN>) {
                        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;
                }
        }