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*\|\|/s) {
88 if (/^(!\s*)?defined\s*\(\s*(\w+)\s*\)\s*(?:(\&\&|\|\|)\s*)?/s ||
89 /^(!\s*)?defined\s*(\w+)\s*(?:(\&\&|\|\|)\s*)?/s)
96 if (defined($sign) && $sign eq "!") {
97 $self->undefine($var);
103 } elsif (/^(!\s*)?(\w+)\s*(?:(<|<=|==|!=|>=|>|\+|\-|\*\/)\s*(\w+)\s*)?(?:(\&\&|\|\|)\s*)?/s) {
109 if (defined($sign) && $sign eq "!") {
110 $self->undefine($var);
116 } elsif(/^(!\s*)?\(/s) {
119 print "*** Can't parse '#$directive $_' ***\n";
127 my $state = \
%{$self->{STATE
}};
128 my $stack = \@
{$self->{STACK
}};
130 my $argument = shift;
134 if(defined($argument)) {
135 $self->begin_if("elif", $argument);
141 my $state = \
%{$self->{STATE
}};
142 my $stack = \@
{$self->{STACK
}};
144 my $macro = pop @
$stack;
145 delete $$state{$macro} if defined($macro);
150 my $state = \
%{$self->{STATE
}};
151 my $stack = \@
{$self->{STACK
}};
153 my $directive = shift;
154 my $argument = shift;
156 local $_ = $directive;
158 $self->begin_if("if",$argument);
160 $self->begin_if("if", "defined($argument)");
161 } elsif(/^ifndef$/) {
162 $self->begin_if("if", "!defined($argument)");
163 push @
$stack, $argument;
165 $self->else_if($argument);
170 } elsif(/^include/) {
171 $self->include($argument);
177 my $state = \
%{$self->{STATE
}};
181 my $status = $$state{$name};
183 return defined($status) && $status eq "def";
188 my $state = \
%{$self->{STATE
}};
192 my $status = $$state{$name};
194 return defined($status) && $status eq "undef";
199 my $state = \
%{$self->{STATE
}};
203 my $status = $$state{$name};
205 return !defined($status);