xcopy: Add the Romanian translation.
[wine/testsucceed.git] / tools / winapi / preprocessor.pm
blob3d497733eb2d92600cfa8a8537c0a724b0c7b28e
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
19 package preprocessor;
21 use strict;
23 sub new($) {
24 my $proto = shift;
25 my $class = ref($proto) || $proto;
26 my $self = {};
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;
37 return $self;
40 sub include($$) {
41 my $self = shift;
42 my $include_found = \${$self->{INCLUDE_FOUND}};
44 my $argument = shift;
46 &$$include_found($argument);
49 sub define($$) {
50 my $self = shift;
51 my $state = \%{$self->{STATE}};
52 my $conditional_found = \${$self->{CONDITIONAL_FOUND}};
54 my $name = shift;
56 $$state{$name} = "def";
58 &$$conditional_found($name);
61 sub undefine($$) {
62 my $self = shift;
63 my $state = \%{$self->{STATE}};
64 my $conditional_found = \${$self->{CONDITIONAL_FOUND}};
66 my $name = shift;
68 $$state{$name} = "undef";
70 &$$conditional_found($name);
73 sub begin_if($$$) {
74 my $self = shift;
75 my $state = \%{$self->{STATE}};
76 my $stack = \@{$self->{STACK}};
78 my $directive = shift;
79 local $_ = shift;
81 while(!/^$/) {
82 if(/^0\s*\&\&/s) {
83 $_ = "0";
84 } elsif(/^1\s*\|\|/s) {
85 $_ = "1";
88 if (/^(!\s*)?defined\s*\(\s*(\w+)\s*\)\s*(?:(\&\&|\|\|)\s*)?/s ||
89 /^(!\s*)?defined\s*(\w+)\s*(?:(\&\&|\|\|)\s*)?/s)
91 $_ = $';
93 my $sign = $1;
94 my $var = $2;
96 if (defined($sign) && $sign eq "!") {
97 $self->undefine($var);
98 push @$stack, $var;
99 } else {
100 $self->define($var);
101 push @$stack, $var;
103 } elsif (/^(!\s*)?(\w+)\s*(?:(<|<=|==|!=|>=|>|\+|\-|\*\/)\s*(\w+)\s*)?(?:(\&\&|\|\|)\s*)?/s) {
104 $_ = $';
106 my $sign = $1;
107 my $var = $2;
109 if (defined($sign) && $sign eq "!") {
110 $self->undefine($var);
111 push @$stack, $var;
112 } else {
113 $self->define($var);
114 push @$stack, $var;
116 } elsif(/^(!\s*)?\(/s) {
117 $_ = "";
118 } else {
119 print "*** Can't parse '#$directive $_' ***\n";
120 $_ = "";
125 sub else_if($$) {
126 my $self = shift;
127 my $state = \%{$self->{STATE}};
128 my $stack = \@{$self->{STACK}};
130 my $argument = shift;
132 $self->end_if;
134 if(defined($argument)) {
135 $self->begin_if("elif", $argument);
139 sub end_if($) {
140 my $self = shift;
141 my $state = \%{$self->{STATE}};
142 my $stack = \@{$self->{STACK}};
144 my $macro = pop @$stack;
145 delete $$state{$macro} if defined($macro);
148 sub directive($$$) {
149 my $self = shift;
150 my $state = \%{$self->{STATE}};
151 my $stack = \@{$self->{STACK}};
153 my $directive = shift;
154 my $argument = shift;
156 local $_ = $directive;
157 if(/^if$/) {
158 $self->begin_if("if",$argument);
159 } elsif(/^ifdef$/) {
160 $self->begin_if("if", "defined($argument)");
161 } elsif(/^ifndef$/) {
162 $self->begin_if("if", "!defined($argument)");
163 push @$stack, $argument;
164 } elsif(/^elif$/) {
165 $self->else_if($argument);
166 } elsif(/^else$/) {
167 $self->else_if;
168 } elsif(/^endif$/) {
169 $self->end_if;
170 } elsif(/^include/) {
171 $self->include($argument);
175 sub is_def($$) {
176 my $self = shift;
177 my $state = \%{$self->{STATE}};
179 my $name = shift;
181 my $status = $$state{$name};
183 return defined($status) && $status eq "def";
186 sub is_undef($$) {
187 my $self = shift;
188 my $state = \%{$self->{STATE}};
190 my $name = shift;
192 my $status = $$state{$name};
194 return defined($status) && $status eq "undef";
197 sub is_unknown($$) {
198 my $self = shift;
199 my $state = \%{$self->{STATE}};
201 my $name = shift;
203 my $status = $$state{$name};
205 return !defined($status);