Added an unknown VxD error code.
[wine] / tools / winapi_check / nativeapi.pm
1 package nativeapi;
2
3 use strict;
4
5 sub new {
6     my $proto = shift;
7     my $class = ref($proto) || $proto;
8     my $self  = {};
9     bless ($self, $class);
10
11     my $options = \${$self->{OPTIONS}};
12     my $output = \${$self->{OUTPUT}};
13     my $functions = \%{$self->{FUNCTIONS}};
14     my $conditionals = \%{$self->{CONDITIONALS}};
15     my $conditional_headers = \%{$self->{CONDITIONAL_HEADERS}};
16     my $conditional_functions = \%{$self->{CONDITIONAL_FUNCTIONS}};
17
18     $$options = shift;
19     $$output = shift;
20     my $api_file = shift;
21     my $configure_in_file = shift;
22     my $config_h_in_file = shift;
23
24     $api_file =~ s/^\.\///;
25     $configure_in_file =~ s/^\.\///;
26     $config_h_in_file =~ s/^\.\///;
27
28     if($$options->progress) {
29         $$output->progress("$api_file");
30     }
31
32     open(IN, "< $api_file");
33     local $/ = "\n";
34     while(<IN>) {
35         s/^\s*?(.*?)\s*$/$1/; # remove whitespace at begin and end of line
36         s/^(.*?)\s*#.*$/$1/;  # remove comments
37         /^$/ && next;         # skip empty lines   
38         
39         $$functions{$_}++;
40     }
41     close(IN);
42
43     if($$options->progress) {
44         $$output->progress("$configure_in_file");
45     }
46
47     my $again = 0;
48     open(IN, "< $configure_in_file");   
49     local $/ = "\n";
50     while($again || (defined($_ = <IN>))) {
51         $again = 0;
52         chomp;
53         if(/^(.*?)\\$/) {
54             my $current = $1;
55             my $next = <IN>;
56             if(defined($next)) {
57                 # remove trailing whitespace
58                 $current =~ s/\s+$//;
59
60                 # remove leading whitespace
61                 $next =~ s/^\s+//;
62
63                 $_ = $current . " " . $next;
64
65                 $again = 1;
66                 next;
67             }
68         }
69
70         # remove leading and trailing whitespace
71         s/^\s*(.*?)\s*$/$1/;
72
73         # skip emty lines
74         if(/^$/) { next; }
75
76         # skip comments
77         if(/^dnl/) { next; }
78
79         if(/^AC_CHECK_HEADERS\(\s*(.*?)\)\s*$/) {
80             my @arguments = split(/,/,$1);
81             foreach my $name (split(/\s+/, $arguments[0])) {            
82                 $$conditional_headers{$name}++;
83             }
84         } elsif(/^AC_CHECK_FUNCS\(\s*(.*?)\)\s*$/) {
85             my @arguments = split(/,/,$1);
86             foreach my $name (split(/\s+/, $arguments[0])) {            
87                 $$conditional_functions{$name}++;
88             }
89         } elsif(/^AC_FUNC_ALLOCA/) {
90             $$conditional_headers{"alloca.h"}++;
91         }
92
93     }
94     close(IN);
95
96     if($$options->progress) {
97         $$output->progress("$config_h_in_file");
98     }
99
100     open(IN, "< $config_h_in_file");
101     local $/ = "\n";
102     while(<IN>) {
103         # remove leading and trailing whitespace
104         s/^\s*(.*?)\s*$/$1/;
105
106         # skip emty lines
107         if(/^$/) { next; }
108
109         if(/^\#undef\s+(\S+)$/) {
110             $$conditionals{$1}++;
111         }
112     }
113     close(IN);
114
115     return $self;
116 }
117
118 sub is_function {
119     my $self = shift;
120     my $functions = \%{$self->{FUNCTIONS}};
121
122     my $name = shift;
123
124     return $$functions{$name};
125 }
126
127 sub is_conditional {
128     my $self = shift;
129     my $conditionals = \%{$self->{CONDITIONALS}};
130
131     my $name = shift;
132
133     return $$conditionals{$name};
134 }
135
136 sub found_conditional {
137     my $self = shift;
138     my $conditional_found = \%{$self->{CONDITIONAL_FOUND}};
139
140     my $name = shift;
141
142     $$conditional_found{$name}++;
143 }
144
145 sub is_conditional_header {
146     my $self = shift;
147     my $conditional_headers = \%{$self->{CONDITIONAL_HEADERS}};
148
149     my $name = shift;
150
151     return $$conditional_headers{$name};
152 }
153
154 sub is_conditional_function {
155     my $self = shift;
156     my $conditional_functions = \%{$self->{CONDITIONAL_FUNCTIONS}};
157
158     my $name = shift;
159
160     return $$conditional_functions{$name};
161 }
162
163 sub global_report {
164     my $self = shift;
165
166     my $output = \${$self->{OUTPUT}};
167     my $conditional_found = \%{$self->{CONDITIONAL_FOUND}};
168     my $conditionals = \%{$self->{CONDITIONALS}};
169
170     my @messages;
171     foreach my $name (sort(keys(%$conditionals))) {
172         if($name =~ /^const|inline|size_t$/) { next; }
173
174         if(0 && !$$conditional_found{$name}) {
175             push @messages, "config.h.in: conditional $name not used\n";
176         }
177     }
178
179     foreach my $message (sort(@messages)) {
180         $$output->write($message);
181     }
182 }
183
184 1;