- Minor fixes and reorganizations.
[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 $output = \${$self->{OUTPUT}};
12     my $functions = \%{$self->{FUNCTIONS}};
13     my $conditionals = \%{$self->{CONDITIONALS}};
14     my $conditional_headers = \%{$self->{CONDITIONAL_HEADERS}};
15     my $conditional_functions = \%{$self->{CONDITIONAL_FUNCTIONS}};
16
17     $$output = shift;
18     my $api_file = shift;
19     my $configure_in_file = shift;
20     my $config_h_in_file = shift;
21
22     $$output->progress("$api_file");
23
24     open(IN, "< $api_file");
25     $/ = "\n";
26     while(<IN>) {
27         s/^\s*?(.*?)\s*$/$1/; # remove whitespace at begin and end of line
28         s/^(.*?)\s*#.*$/$1/;  # remove comments
29         /^$/ && next;         # skip empty lines   
30         
31         $$functions{$_}++;
32     }
33     close(IN);
34
35     $$output->progress("$configure_in_file");
36
37     my $again = 0;
38     open(IN, "< $configure_in_file");   
39     local $/ = "\n";
40     while($again || (defined($_ = <IN>))) {
41         $again = 0;
42         chomp;
43         if(/(.*)\\$/) {
44             my $line = <IN>;
45             if(defined($line)) {
46                 $_ = $1 . " " . $line;
47                 $again = 1;
48                 next;
49             }
50         }
51         # remove leading and trailing whitespace
52         s/^\s*(.*?)\s*$/$1/;
53
54         if(/^AC_CHECK_HEADERS\(\s*(.*?)\)\s*$/) {
55             my @arguments = split(/,/,$1);
56             foreach my $name (split(/\s+/, $arguments[0])) {            
57                 $$conditional_headers{$name}++;
58             }
59         } elsif(/^AC_CHECK_FUNCS\(\s*(.*?)\)\s*$/) {
60             my @arguments = split(/,/,$1);
61             foreach my $name (split(/\s+/, $arguments[0])) {            
62                 $$conditional_functions{$name}++;
63             }
64         } elsif(/^AC_FUNC_ALLOCA/) {
65             $$conditional_headers{"alloca.h"}++;
66         }
67
68     }
69     close(IN);
70
71     $$output->progress("$config_h_in_file");
72
73     open(IN, "< $config_h_in_file");
74     local $/ = "\n";
75     while(<IN>) {
76         if(/^\#undef\s+(\S+)$/) {
77             $$conditionals{$1}++;
78         }
79     }
80     close(IN);
81
82     return $self;
83 }
84
85 sub is_function {
86     my $self = shift;
87     my $functions = \%{$self->{FUNCTIONS}};
88
89     my $name = shift;
90
91     return $$functions{$name};
92 }
93
94 sub is_conditional {
95     my $self = shift;
96     my $conditionals = \%{$self->{CONDITIONALS}};
97
98     my $name = shift;
99
100     return $$conditionals{$name};
101 }
102
103 sub is_conditional_header {
104     my $self = shift;
105     my $conditional_headers = \%{$self->{CONDITIONAL_HEADERS}};
106
107     my $name = shift;
108
109     return $$conditional_headers{$name};
110 }
111
112 sub is_conditional_function {
113     my $self = shift;
114     my $conditional_functions = \%{$self->{CONDITIONAL_FUNCTIONS}};
115
116     my $name = shift;
117
118     return $$conditional_functions{$name};
119 }
120
121 1;