2 # Copyright 1999, 2000, 2001 Patrik Stridvall
4 # This library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the License, or (at your option) any later version.
9 # This library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with this library; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 my $class = ref($proto) || $proto;
27 bless ($self, $class);
29 my $state = \
%{$self->{STATE
}};
30 my $stack = \@
{$self->{STACK
}};
31 my $include_found = \
${$self->{INCLUDE_FOUND
}};
32 my $conditional_found = \
${$self->{CONDITIONAL_FOUND
}};
34 $$include_found = shift;
35 $$conditional_found = shift;
42 my $include_found = \
${$self->{INCLUDE_FOUND
}};
46 &$$include_found($argument);
51 my $state = \
%{$self->{STATE
}};
52 my $conditional_found = \
${$self->{CONDITIONAL_FOUND
}};
56 $$state{$name} = "def";
58 &$$conditional_found($name);
63 my $state = \
%{$self->{STATE
}};
64 my $conditional_found = \
${$self->{CONDITIONAL_FOUND
}};
68 $$state{$name} = "undef";
70 &$$conditional_found($name);
75 my $state = \
%{$self->{STATE
}};
76 my $stack = \@
{$self->{STACK
}};
78 my $directive = shift;
84 } elsif(/^1\s*\|\|/) {
88 if(/^(!)?defined\s*\(\s*(.+?)\s*\)\s*((\&\&|\|\|)\s*)?/){
90 if(defined($1) && $1 eq "!") {
97 } elsif(/^(\w+)\s*(<|<=|==|!=|>=|>)\s*(\w+)\s*((\&\&|\|\|)\s*)?/) {
99 } elsif(/^(!)?(\w+)\s*$/) {
104 print "*** Can't parse '#$directive $_' ***\n";
112 my $state = \
%{$self->{STATE
}};
113 my $stack = \@
{$self->{STACK
}};
115 my $argument = shift;
119 if(defined($argument)) {
120 $self->begin_if("elif", $argument);
126 my $state = \
%{$self->{STATE
}};
127 my $stack = \@
{$self->{STACK
}};
129 my $macro = pop @
$stack;
130 delete $$state{$macro} if defined($macro);
135 my $state = \
%{$self->{STATE
}};
136 my $stack = \@
{$self->{STACK
}};
138 my $directive = shift;
139 my $argument = shift;
141 local $_ = $directive;
143 $self->begin_if("if",$argument);
145 $self->begin_if("if", "defined($argument)");
146 } elsif(/^ifndef$/) {
147 $self->begin_if("if", "!defined($argument)");
148 push @
$stack, $argument;
150 $self->else_if($argument);
155 } elsif(/^include/) {
156 $self->include($argument);
162 my $state = \
%{$self->{STATE
}};
166 my $status = $$state{$name};
168 return defined($status) && $status eq "def";
173 my $state = \
%{$self->{STATE
}};
177 my $status = $$state{$name};
179 return defined($status) && $status eq "undef";
184 my $state = \
%{$self->{STATE
}};
188 my $status = $$state{$name};
190 return !defined($status);