nativeapi.pm 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #
  2. # Copyright 1999, 2000, 2001 Patrik Stridvall
  3. #
  4. # This library is free software; you can redistribute it and/or
  5. # modify it under the terms of the GNU Lesser General Public
  6. # License as published by the Free Software Foundation; either
  7. # version 2.1 of the License, or (at your option) any later version.
  8. #
  9. # This library is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. # Lesser General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU Lesser General Public
  15. # License along with this library; if not, write to the Free Software
  16. # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  17. #
  18. package nativeapi;
  19. use strict;
  20. use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
  21. require Exporter;
  22. @ISA = qw(Exporter);
  23. @EXPORT = qw();
  24. @EXPORT_OK = qw($nativeapi);
  25. use vars qw($nativeapi);
  26. use config qw(file_type $current_dir $wine_dir $winapi_dir);
  27. use options qw($options);
  28. use output qw($output);
  29. $nativeapi = 'nativeapi'->new;
  30. sub new($) {
  31. my $proto = shift;
  32. my $class = ref($proto) || $proto;
  33. my $self = {};
  34. bless ($self, $class);
  35. my $functions = \%{$self->{FUNCTIONS}};
  36. my $conditionals = \%{$self->{CONDITIONALS}};
  37. my $conditional_headers = \%{$self->{CONDITIONAL_HEADERS}};
  38. my $conditional_functions = \%{$self->{CONDITIONAL_FUNCTIONS}};
  39. my $api_file = "$winapi_dir/nativeapi.dat";
  40. my $configure_ac_file = "$wine_dir/configure.ac";
  41. my $config_h_in_file = "$wine_dir/include/config.h.in";
  42. $api_file =~ s/^\.\///;
  43. $configure_ac_file =~ s/^\.\///;
  44. $config_h_in_file =~ s/^\.\///;
  45. $$conditional_headers{"config.h"}++;
  46. $output->progress("$api_file");
  47. open(IN, "< $api_file") || die "Error: Can't open $api_file: $!\n";
  48. local $/ = "\n";
  49. while(<IN>) {
  50. s/^\s*(.*?)\s*$/$1/; # remove whitespace at begin and end of line
  51. s/^(.*?)\s*#.*$/$1/; # remove comments
  52. /^$/ && next; # skip empty lines
  53. $$functions{$_}++;
  54. }
  55. close(IN);
  56. $output->progress("$configure_ac_file");
  57. my $again = 0;
  58. open(IN, "< $configure_ac_file") || die "Error: Can't open $configure_ac_file: $!\n";
  59. local $/ = "\n";
  60. while($again || (defined($_ = <IN>))) {
  61. $again = 0;
  62. chomp;
  63. if(/^(.*?)\\$/) {
  64. my $current = $1;
  65. my $next = <IN>;
  66. if(defined($next)) {
  67. # remove trailing whitespace
  68. $current =~ s/\s+$//;
  69. # remove leading whitespace
  70. $next =~ s/^\s+//;
  71. $_ = $current . " " . $next;
  72. $again = 1;
  73. next;
  74. }
  75. }
  76. # remove leading and trailing whitespace
  77. s/^\s*(.*?)\s*$/$1/;
  78. # skip empty lines
  79. if(/^$/) { next; }
  80. # skip comments
  81. if(/^dnl/) { next; }
  82. if(/AC_CHECK_HEADERS\(\s*([^,\)]*)(?:,|\))?/) {
  83. my $headers = $1;
  84. $headers =~ s/^\s*\[\s*(.*?)\s*\]\s*$/$1/;
  85. foreach my $name (split(/\s+/, $headers)) {
  86. $$conditional_headers{$name}++;
  87. }
  88. } elsif(/AC_HEADER_STAT\(\)/) {
  89. # This checks for a bunch of standard headers
  90. # There's stdlib.h, string.h and sys/types.h too but we don't
  91. # want to force ifdefs for those at this point.
  92. foreach my $name ("sys/stat.h", "memory.h", "strings.h",
  93. "inttypes.h", "stdint.h", "unistd.h") {
  94. $$conditional_headers{$name}++;
  95. }
  96. } elsif(/AC_CHECK_FUNCS\(\s*([^,\)]*)(?:,|\))?/) {
  97. my $funcs = $1;
  98. $funcs =~ s/^\s*\[\s*(.*?)\s*\]\s*$/$1/;
  99. foreach my $name (split(/\s+/, $funcs)) {
  100. $$conditional_functions{$name}++;
  101. }
  102. } elsif(/AC_FUNC_ALLOCA/) {
  103. $$conditional_headers{"alloca.h"}++;
  104. } elsif (/AC_DEFINE\(\s*HAVE_(.*?)_H/) {
  105. my $name = lc($1);
  106. $name =~ s/_/\//;
  107. $name .= ".h";
  108. next if $name =~ m%correct/%;
  109. $$conditional_headers{$name}++;
  110. }
  111. }
  112. close(IN);
  113. $output->progress("$config_h_in_file");
  114. open(IN, "< $config_h_in_file") || die "Error: Can't open $config_h_in_file: $!\n";
  115. local $/ = "\n";
  116. while(<IN>) {
  117. # remove leading and trailing whitespace
  118. s/^\s*(.*?)\s*$/$1/;
  119. # skip empty lines
  120. if(/^$/) { next; }
  121. if(/^\#undef\s+(\S+)$/) {
  122. $$conditionals{$1}++;
  123. }
  124. }
  125. close(IN);
  126. $nativeapi = $self;
  127. return $self;
  128. }
  129. sub is_function($$) {
  130. my $self = shift;
  131. my $functions = \%{$self->{FUNCTIONS}};
  132. my $name = shift;
  133. return ($$functions{$name} || 0);
  134. }
  135. sub is_conditional($$) {
  136. my $self = shift;
  137. my $conditionals = \%{$self->{CONDITIONALS}};
  138. my $name = shift;
  139. return ($$conditionals{$name} || 0);
  140. }
  141. sub found_conditional($$) {
  142. my $self = shift;
  143. my $conditional_found = \%{$self->{CONDITIONAL_FOUND}};
  144. my $name = shift;
  145. $$conditional_found{$name}++;
  146. }
  147. sub is_conditional_header($$) {
  148. my $self = shift;
  149. my $conditional_headers = \%{$self->{CONDITIONAL_HEADERS}};
  150. my $name = shift;
  151. return ($$conditional_headers{$name} || 0);
  152. }
  153. sub is_conditional_function($$) {
  154. my $self = shift;
  155. my $conditional_functions = \%{$self->{CONDITIONAL_FUNCTIONS}};
  156. my $name = shift;
  157. return ($$conditional_functions{$name} || 0);
  158. }
  159. sub global_report($) {
  160. my $self = shift;
  161. my $output = \${$self->{OUTPUT}};
  162. my $conditional_found = \%{$self->{CONDITIONAL_FOUND}};
  163. my $conditionals = \%{$self->{CONDITIONALS}};
  164. my @messages;
  165. foreach my $name (sort(keys(%$conditionals))) {
  166. if($name =~ /^(?:const|inline|size_t)$/) { next; }
  167. if(0 && !$$conditional_found{$name}) {
  168. push @messages, "config.h.in: conditional $name not used\n";
  169. }
  170. }
  171. foreach my $message (sort(@messages)) {
  172. $output->write($message);
  173. }
  174. }
  175. 1;