From: Pavel Charvat Date: Wed, 17 Jan 2007 00:20:56 +0000 (+0100) Subject: Support for the following syntax in configuration files: X-Git-Tag: holmes-import~506^2~112 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=daf489b1c9a3f4dc306c82bf330771540179a1bf;p=libucw.git Support for the following syntax in configuration files: #if CONFIG_ABC || !CONFIG_DEF #elsif (CONFIG_GHI && CONFIG_JKL) || CONFIG_MNO #else #endif Alternatively I can cache it to C-like "defined(CONFIG_ABC)" (CONFIG_ABC alone could expand to its value) or to pure Perl code without substitutions. --- diff --git a/build/genconf b/build/genconf index 0d7bc737..75c957fe 100755 --- a/build/genconf +++ b/build/genconf @@ -15,6 +15,9 @@ while () { } close CF; +my $opt_regex = join("|", keys %options); +sub eval_expr { $_ = "@_"; s/\b($opt_regex)\b/ 1 /g if $opt_regex; s/\bCONFIG_\w+\b/ 0 /g; return eval $_; } + open IN, $ARGV[0] or die "Unable to open $ARGV[0]"; open OUT, ">$ARGV[1]" or die "Unable to create $ARGV[1]"; my @ifs = (); # stack of conditions, 1=satisfied, -1=unsatisfied, 0=shadowed @@ -24,12 +27,18 @@ while () { push @ifs, (@ifs && $ifs[$#ifs] <= 0) ? 0 : (defined $options{$1}) ? 1 : -1; } elsif (/^#ifndef\s+(\w+)/) { push @ifs, (@ifs && $ifs[$#ifs] <= 0) ? 0 : (defined $options{$1}) ? -1 : 1; + } elsif (/^#if\s(.*)$/) { + push @ifs, (@ifs && $ifs[$#ifs] <= 0) ? 0 : (eval_expr $1) ? 1 : -1; } elsif (/^#endif/) { defined pop @ifs || die "Improper nesting of conditionals"; } elsif (/^#else/) { my $x = pop @ifs; defined $x || die "Improper nesting of conditionals"; - push @ifs, -$x; + push @ifs, $x >= 0 ? 0 : 1; + } elsif (/^#elsif\s(.*)$/) { + my $x = pop @ifs; + defined $x || die "Improper nesting of conditionals"; + push @ifs, $x >= 0 ? 0 : (eval_expr $1) ? 1 : -1; } else { @ifs && $ifs[$#ifs] <= 0 && next; if (/^$/) {