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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 my $class = ref($proto) || $proto;
28 bless ($self, $class);
30 my $state = \
%{$self->{STATE
}};
31 my $stack = \@
{$self->{STACK
}};
32 my $include_found = \
${$self->{INCLUDE_FOUND
}};
33 my $conditional_found = \
${$self->{CONDITIONAL_FOUND
}};
35 $$include_found = shift;
36 $$conditional_found = shift;
43 my $include_found = \
${$self->{INCLUDE_FOUND
}};
47 &$$include_found($argument);
52 my $state = \
%{$self->{STATE
}};
53 my $conditional_found = \
${$self->{CONDITIONAL_FOUND
}};
57 $$state{$name} = "def";
59 &$$conditional_found($name);
64 my $state = \
%{$self->{STATE
}};
65 my $conditional_found = \
${$self->{CONDITIONAL_FOUND
}};
69 $$state{$name} = "undef";
71 &$$conditional_found($name);
76 my $state = \
%{$self->{STATE
}};
77 my $stack = \@
{$self->{STACK
}};
79 my $directive = shift;
85 } elsif(/^1\s*\|\|/s) {
89 if (/^(!\s*)?defined\s*\(\s*(\w+)\s*\)\s*(?:(\&\&|\|\|)\s*)?/s ||
90 /^(!\s*)?defined\s*(\w+)\s*(?:(\&\&|\|\|)\s*)?/s)
97 if (defined($sign) && $sign eq "!") {
98 $self->undefine($var);
104 } elsif (/^(!\s*)?(\w+)\s*(?:(<|<=|==|!=|>=|>|\+|\-|\*\/)\s*(\w+)\s*)?(?:(\&\&|\|\|)\s*)?/s) {
110 if (defined($sign) && $sign eq "!") {
111 $self->undefine($var);
117 } elsif(/^(!\s*)?\(/s) {
120 print "*** Can't parse '#$directive $_' ***\n";
128 my $state = \
%{$self->{STATE
}};
129 my $stack = \@
{$self->{STACK
}};
131 my $argument = shift;
135 if(defined($argument)) {
136 $self->begin_if("elif", $argument);
142 my $state = \
%{$self->{STATE
}};
143 my $stack = \@
{$self->{STACK
}};
145 my $macro = pop @
$stack;
146 delete $$state{$macro} if defined($macro);
151 my $state = \
%{$self->{STATE
}};
152 my $stack = \@
{$self->{STACK
}};
154 my $directive = shift;
155 my $argument = shift;
157 local $_ = $directive;
159 $self->begin_if("if",$argument);
161 $self->begin_if("if", "defined($argument)");
162 } elsif(/^ifndef$/) {
163 $self->begin_if("if", "!defined($argument)");
164 push @
$stack, $argument;
166 $self->else_if($argument);
171 } elsif(/^include/) {
172 $self->include($argument);
178 my $state = \
%{$self->{STATE
}};
182 my $status = $$state{$name};
184 return defined($status) && $status eq "def";
189 my $state = \
%{$self->{STATE
}};
193 my $status = $$state{$name};
195 return defined($status) && $status eq "undef";
200 my $state = \
%{$self->{STATE
}};
204 my $status = $$state{$name};
206 return !defined($status);