Merged msacm and msacm32 dlls.
[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 $line = <IN>;
55             if(defined($line)) {
56                 $_ = $1 . " " . $line;
57                 $again = 1;
58                 next;
59             }
60         }
61         # remove leading and trailing whitespace
62         s/^\s*(.*?)\s*$/$1/;
63
64         if(/^AC_CHECK_HEADERS\(\s*(.*?)\)\s*$/) {
65             my @arguments = split(/,/,$1);
66             foreach my $name (split(/\s+/, $arguments[0])) {            
67                 $$conditional_headers{$name}++;
68             }
69         } elsif(/^AC_CHECK_FUNCS\(\s*(.*?)\)\s*$/) {
70             my @arguments = split(/,/,$1);
71             foreach my $name (split(/\s+/, $arguments[0])) {            
72                 $$conditional_functions{$name}++;
73             }
74         } elsif(/^AC_FUNC_ALLOCA/) {
75             $$conditional_headers{"alloca.h"}++;
76         }
77
78     }
79     close(IN);
80
81     if($$options->progress) {
82         $$output->progress("$config_h_in_file");
83     }
84
85     open(IN, "< $config_h_in_file");
86     local $/ = "\n";
87     while(<IN>) {
88         if(/^\#undef\s+(\S+)$/) {
89             $$conditionals{$1}++;
90         }
91     }
92     close(IN);
93
94     return $self;
95 }
96
97 sub is_function {
98     my $self = shift;
99     my $functions = \%{$self->{FUNCTIONS}};
100
101     my $name = shift;
102
103     return $$functions{$name};
104 }
105
106 sub is_conditional {
107     my $self = shift;
108     my $conditionals = \%{$self->{CONDITIONALS}};
109
110     my $name = shift;
111
112     return $$conditionals{$name};
113 }
114
115 sub is_conditional_header {
116     my $self = shift;
117     my $conditional_headers = \%{$self->{CONDITIONAL_HEADERS}};
118
119     my $name = shift;
120
121     return $$conditional_headers{$name};
122 }
123
124 sub is_conditional_function {
125     my $self = shift;
126     my $conditional_functions = \%{$self->{CONDITIONAL_FUNCTIONS}};
127
128     my $name = shift;
129
130     return $$conditional_functions{$name};
131 }
132
133 1;