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