From bcf95dc9175ae4859e162d3df7652aade939f0f7 Mon Sep 17 00:00:00 2001 From: Ralf Corsepius Date: Tue, 6 Apr 2010 11:31:11 +0000 Subject: [PATCH] Rework again. --- contrib/crossrpms/specstrip | 100 ++++++++++++++++++++++++++++-------- 1 file changed, 78 insertions(+), 22 deletions(-) diff --git a/contrib/crossrpms/specstrip b/contrib/crossrpms/specstrip index 3f1f2e701c..b61e741610 100755 --- a/contrib/crossrpms/specstrip +++ b/contrib/crossrpms/specstrip @@ -166,30 +166,86 @@ foreach (@buffer0) my @buffer3; foreach my $i ( @buffer2 ) { - print STDERR $i->{state}, $i->{line}, "\n" if $verbose > 1; + print STDERR "STATE:", $i->{state}, " LINE:", $i->{line}, "\n" if $verbose > 1; if ( $i->{state} =~ m/($ppat)/ ) { - } elsif ( $i->{state} =~ m/.*<"([a-zA-Z_0-9\.\-]+)" (!=|==) "([a-zA-Z_0-9\.\-]+)">.*/ ) { - # Filter out constant conditionals - if ( "$2" eq "==" ) { - if ( "$1" eq "$3" ) { - if ( $i->{line} =~ m/^%(if|else|endif).*$/ ) { - } else { - push @buffer3, $i->{line}, "\n"; - } - } - } elsif ( "$2" eq "!=" ){ - if ( "$1" ne "$3" ) { - if ( $i->{line} =~ m/^%(if|else|endif).*$/ ) { - } else { - push @buffer3, $i->{line}, "\n"; - } - } - } else { - die "invalid condition: $i->{state}"; - } } else { - push @buffer3, $i->{line}, "\n" + push @buffer3, $i->{line}; } } -print STDOUT @buffer3; +#foreach my $line ( @buffer3 ) +#{ +# print STDERR "L:<$line>\n"; +#} + +my @buffer4; +@condstack = (); +push @condstack, "<>"; +foreach my $line ( @buffer3 ) +{ +# print STDERR "READ:{", $line, "}\n"; + if ( $line =~/^%if\s+"([a-zA-Z_0-9\.\-]+)"\s+==\s+"([a-zA-Z_0-9\.\-]+)"\s*$/ ) + { + if ( "$1" eq "$2" ) { + push @condstack,""; + } else { + push @condstack,""; + } + } elsif ( $line =~/^%if\s+"([a-zA-Z_0-9\.\-]+)"\s+!=\s+"([a-zA-Z_0-9\.\-]+)"\s*$/ ) + { + if ( "$1" ne "$2" ) { + push @condstack,""; + } else { + push @condstack,""; + } + } elsif ( $line =~/^%if\s+(.*)\s*$/ ) + { + my $exp = $1; + if ( $condstack[$#condstack] =~ m/$/ ) { + push @condstack,""; + } else { + push @condstack,""; + push @buffer4, "$line\n"; + } + } elsif ( $line =~/^%if((os|narch)\s+.*)\s*$/ ) + { + my $exp = $1; + if ( $condstack[$#condstack] =~ m/$/ ) { + push @condstack,""; + } else { + push @condstack,""; + push @buffer4, "$line\n"; + } + } elsif ( $line =~ /^%else\s*$/ ) { + if ( $condstack[$#condstack] =~ m/$/ ) { + $condstack[$#condstack] = ""; + } elsif ( $condstack[$#condstack] =~ m/$/ ) { + $condstack[$#condstack] = ""; + } else { + push @buffer4, "$line\n"; + } + } elsif ( $line =~ /^%endif\s*$/ ) { + + if ( $condstack[$#condstack] =~ m/$/ ) { +# print STDERR "ENDIF: TRUE\n"; + } elsif ( $condstack[$#condstack] =~ m/$/ ) { +# print STDERR "ENDIF: FALSE\n"; + } else { + push @buffer4, "%endif\n"; + } +# print STDERR "POP: $line\n"; + pop @condstack; + } else { +# print STDERR "CATCH $condstack[$#condstack]:$line\n"; + if ( $condstack[$#condstack] =~ m/$/ ) { + push @buffer4, "$line\n"; + } elsif ( $condstack[$#condstack] =~ m/$/ ) { + } else { + push @buffer4, "$line\n"; + } + } + +# print STDERR @condstack, "LINE: $line\n"; +} + +print STDOUT @buffer4;