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