X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=build%2Fgenconf;h=7a53dc1b3c824749ec689b0a30db8d93feecef47;hb=beb9738f1fbcba84bc0f09f742fb66b1ddfcf349;hp=2c3147861b67ef792eb8dbd7e8fbca98106057e1;hpb=2600ba2ab4a4c12ee35f66439670a771f9c7b622;p=libucw.git diff --git a/build/genconf b/build/genconf index 2c314786..7a53dc1b 100755 --- a/build/genconf +++ b/build/genconf @@ -1,6 +1,6 @@ #!/usr/bin/perl -# Configuration file preprocessor -# (c) 2003 Martin Mares +# Configuration file and script preprocessor +# (c) 2004 Martin Mares use strict; use warnings; @@ -10,28 +10,28 @@ use warnings; open CF, $ARGV[2] or die "Unable to open $ARGV[2]"; my %options = (); while () { - /^(CONFIG_\w+)=1/ || next; + /^(CONFIG_\w+)=[^0]/ || next; $options{$1} = 1; } close CF; 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 +my @ifs = (); # stack of conditions, 1=satisfied, -1=unsatisfied, 0=shadowed my $empty = 0; # last line was empty while () { - if (/^#?ifdef\s+(\w+)/) { - push @ifs, !defined $options{$1}; + if (/^#ifdef\s+(\w+)/) { + push @ifs, (@ifs && $ifs[$#ifs] <= 0) ? 0 : (defined $options{$1}) ? 1 : -1; } elsif (/^#ifndef\s+(\w+)/) { - push @ifs, defined $options{$1}; - } elsif (/^#?endif/) { + push @ifs, (@ifs && $ifs[$#ifs] <= 0) ? 0 : (defined $options{$1}) ? -1 : 1; + } elsif (/^#endif/) { defined pop @ifs || die "Improper nesting of conditionals"; - } elsif (/^#?else/) { + } elsif (/^#else/) { my $x = pop @ifs; defined $x || die "Improper nesting of conditionals"; - push @ifs, !$x; + push @ifs, -$x; } else { - @ifs && $ifs[$#ifs] && next; + @ifs && $ifs[$#ifs] <= 0 && next; if (/^$/) { $empty && next; $empty = 1;