From: Martin Mares Date: Thu, 5 Feb 2004 19:37:25 +0000 (+0000) Subject: Nested conditionals were processed incorrectly. Also, the "#" at the start X-Git-Tag: holmes-import~1123 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=e270ec25872050be5a969a4a5b85f888e9ec5468;p=libucw.git Nested conditionals were processed incorrectly. Also, the "#" at the start of directives is now mandatory. --- diff --git a/build/genconf b/build/genconf index 2c314786..b088a142 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; @@ -17,21 +17,21 @@ 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;