3 # Copyright 2002 Patrik Stridvall
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 $0 =~ m
%^(.*?
/?tools)/winapi
/winapi_extract
$%;
24 require "$1/winapi/setup.pm";
28 files_skip files_filter get_spec_files
29 $current_dir $wine_dir $winapi_dir
31 use output qw($output);
32 use winapi_extract_options qw($options);
34 if($options->progress) {
35 $output->enable_progress;
37 $output->disable_progress;
46 use vars qw($win16api $win32api @winapis);
47 if ($options->implemented || $options->stub_statistics || $options->winetest) {
49 import winapi qw($win16api $win32api @winapis);
54 if($options->winetest) {
57 foreach my $spec_file (get_spec_files("winelib")) {
60 my $module = $spec_file;
61 $module =~ s/^.*?([^\/]*)\.spec$/$1/;
65 open(IN, "< $wine_dir/$spec_file") || die "Error: Can't open $wine_dir/$spec_file: $!\n";
69 while($lookahead || defined($_ = <IN>)) {
72 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at beginning and end of line
73 s/^(.*?)\s*#.*$/$1/; # remove comments
74 /^$/ && next; # skip empty lines
84 if(/^(\d+|@)\s+stdcall\s+(\w+)\s*\(\s*([^\)]*)\s*\)/) {
87 my @args = split(/\s+/, $3);
89 push @$entries, [$name, "undef", \@args];
94 $module2spec_file{$module} = $spec_file;
95 $module2entries{$module} = $entries;
101 sub documentation_specifications($) {
102 my $function = shift;
104 my @debug_channels = @{$function->debug_channels};
105 my $documentation = $function->documentation;
106 my $documentation_line = $function->documentation_line;
107 my $return_type = $function->return_type;
108 my $linkage = $function->linkage;
109 my $internal_name = $function->internal_name;
111 if($linkage eq "static") {
116 foreach (split(/\n/, $documentation)) {
117 if(/^\s*\*\s*(\S+)\s*[\(\[]\s*(\w+)\s*\.\s*(\S+)\s*[\)\]]/) {
118 my $external_name = $1;
122 if($ordinal eq "@") {
123 if(1 || !exists($specifications{$module}{unfixed}{$external_name})) {
124 $specifications{$module}{unfixed}{$external_name}{ordinal} = $ordinal;
125 $specifications{$module}{unfixed}{$external_name}{external_name} = $external_name;
126 $specifications{$module}{unfixed}{$external_name}{function} = $function;
128 $output->write("$external_name ($module.$ordinal) already exists\n");
130 } elsif($ordinal =~ /^\d+$/) {
131 if(1 || !exists($specifications{$module}{fixed}{$ordinal})) {
132 $specifications{$module}{fixed}{$ordinal}{ordinal} = $ordinal;
133 $specifications{$module}{fixed}{$ordinal}{external_name} = $external_name;
134 $specifications{$module}{fixed}{$ordinal}{function} = $function;
136 $output->write("$external_name ($module.$ordinal) already exists\n");
138 } elsif($ordinal eq "init") {
139 if(!exists($specifications{$module}{init})) {
140 $specifications{$module}{init}{function} = $function;
142 $output->write("$external_name ($module.$ordinal) already exists\n");
145 if(!exists($specifications{$module}{unknown}{$external_name})) {
146 $specifications{$module}{unknown}{$external_name}{ordinal} = $ordinal;
147 $specifications{$module}{unknown}{$external_name}{external_name} = $external_name;
148 $specifications{$module}{unknown}{$external_name}{function} = $function;
150 $output->write("$external_name ($module.$ordinal) already exists\n");
154 if($options->debug) {
155 $output->write("$external_name ($module.$ordinal)\n");
161 my %module_pseudo_stub;
163 sub statements_pseudo_stub($) {
164 my $function = shift;
167 my $statements = $function->statements;
168 if(defined($statements) && $statements =~ /FIXME[^;]*stub/s) {
169 if($options->win16) {
170 my $external_name16 = $function->external_name16;
171 foreach my $module16 ($function->modules16) {
172 $module_pseudo_stub{$module16}{$external_name16}++;
176 if($options->win32) {
177 my $external_name32 = $function->external_name32;
178 foreach my $module32 ($function->modules32) {
179 $module_pseudo_stub{$module32}{$external_name32}++;
189 if($options->headers) {
190 @h_files = $options->h_files;
191 @h_files = files_skip(@h_files);
192 @h_files = files_filter("winelib", @h_files);
196 if($options->pseudo_implemented || $options->pseudo_stub_statistics) {
197 @c_files = $options->c_files;
198 @c_files = files_skip(@c_files);
199 @c_files = files_filter("winelib", @c_files);
203 my $progress_current = 0;
204 my $progress_max = scalar(@h_files) + scalar(@c_files);
206 foreach my $file (@h_files, @c_files) {
212 open(IN, "< $file") || die "Error: Can't open $file: $!\n";
221 while(s/^.*?\n//) { $max_line++; }
222 if($_) { $max_line++; }
225 my $parser = new c_parser($file);
230 my $update_output = sub {
234 $progress .= "$file (file $progress_current of $progress_max)";
237 if(defined($function)) {
238 my $name = $function->name;
239 my $begin_line = $function->begin_line;
240 my $begin_column = $function->begin_column;
242 $progress .= ": function $name";
243 $prefix .= "$begin_line.$begin_column: function $name: ";
249 $progress .= ": line $line of $max_line";
252 $output->progress($progress);
253 $output->prefix($prefix);
258 my $found_function = sub {
261 my $name = $function->name;
262 $functions{$name} = $function;
264 if ($function->statements) {
269 if($options->implemented || $options->stub_statistics) {
270 $old_function = 'winapi_function'->new;
272 $old_function = 'function'->new;
275 $old_function->file($function->file);
276 $old_function->debug_channels([]); # FIXME: Not complete
278 $old_function->documentation_line(0); # FIXME: Not complete
279 $old_function->documentation(""); # FIXME: Not complete
281 $old_function->function_line($function->begin_line());
282 $old_function->linkage($function->linkage);
283 $old_function->return_type($function->return_type);
284 $old_function->calling_convention($function->calling_convention);
285 $old_function->internal_name($function->name);
286 if (defined($function->argument_types)) {
287 $old_function->argument_types([@{$function->argument_types}]);
289 if (defined($function->argument_names)) {
290 $old_function->argument_names([@{$function->argument_names}]);
292 $old_function->argument_documentations([]); # FIXME: Not complete
293 $old_function->statements_line($function->statements_line);
294 $old_function->statements($function->statements);
296 if($options->winetest) {
297 documentation_specifications($old_function);
300 if ($function->statements) {
308 if ($options->pseudo_implemented || $options->pseudo_stub_statistics) {
309 $pseudo_stub = statements_pseudo_stub($old_function);
312 my $module = $old_function->module;
313 my $external_name = $old_function->external_name;
314 my $statements = $old_function->statements;
315 if ($options->pseudo_implemented && $module && $external_name && $statements) {
316 my @external_names = split(/\s*&\s*/, $external_name);
317 my @modules = split(/\s*&\s*/, $module);
320 while(defined(my $external_name = shift @external_names) &&
321 defined(my $module = shift @modules))
324 $output->write("$module.$external_name: pseudo implemented\n");
326 $output->write("$module.$external_name: implemented\n");
331 $parser->set_found_function_callback($found_function);
333 my $found_line = sub {
338 $parser->set_found_line_callback($found_line);
340 my $found_type = sub {
345 my $kind = $type->kind;
346 my $_name = $type->_name;
347 my $name = $type->name;
349 foreach my $field ($type->fields) {
350 my $field_type_name = $field->type_name;
351 my $field_name = $field->name;
353 if ($options->struct && $kind =~ /^(?:struct|union)$/) {
355 $output->write("$name:$field_type_name:$field_name\n");
357 $output->write("$kind $_name:$field_type_name:$field_name\n");
364 $parser->set_found_type_callback($found_type);
369 if(!$parser->parse_c_file(\$_, \$line, \$column)) {
370 $output->write("can't parse file\n");
378 if($options->implemented && !$options->pseudo_implemented) {
379 foreach my $winapi (@winapis) {
380 my $type = $winapi->name;
382 if($type eq "win16" && !$options->win16) { next; }
383 if($type eq "win32" && !$options->win32) { next; }
385 foreach my $module ($winapi->all_modules) {
386 foreach my $external_name ($winapi->all_functions_in_module($module)) {
387 my $external_calling_convention =
388 $winapi->function_external_calling_convention_in_module($module, $external_name);
390 if($external_calling_convention eq "forward") {
391 (my $forward_module, my $forward_external_name) =
392 $winapi->function_forward_final_destination($module, $external_name);
394 my $forward_external_calling_convention =
395 $winapi->function_external_calling_convention_in_module($forward_module, $forward_external_name);
397 if(!defined($forward_external_calling_convention)) {
401 $external_calling_convention = $forward_external_calling_convention;
404 if ($external_calling_convention ne "stub") {
405 $output->write("*.spec: $module.$external_name: implemented\n");
412 sub output_function($$$$$) {
416 my $external_name = shift;
417 my $function = shift;
419 my $internal_name = $function->internal_name;
422 my $calling_convention;
423 my $refargument_kinds;
424 if($type eq "win16") {
425 $return_kind = $function->return_kind16 || "undef";
426 $calling_convention = $function->calling_convention16 || "undef";
427 $refargument_kinds = $function->argument_kinds16;
428 } elsif($type eq "win32") {
429 $return_kind = $function->return_kind32 || "undef";
430 $calling_convention = $function->calling_convention32 || "undef";
431 $refargument_kinds = $function->argument_kinds32;
434 if(defined($refargument_kinds)) {
435 my @argument_kinds = map { $_ || "undef"; } @$refargument_kinds;
436 print OUT "$ordinal $calling_convention $external_name(@argument_kinds) $internal_name\n";
438 print OUT "$ordinal $calling_convention $external_name() $internal_name # FIXME: arguments undefined\n";
442 if($options->stub_statistics) {
443 foreach my $winapi (@winapis) {
444 my $type = $winapi->name;
446 if($type eq "win16" && !$options->win16) { next; }
447 if($type eq "win32" && !$options->win32) { next; }
450 foreach my $module ($winapi->all_modules) {
451 foreach my $external_name ($winapi->all_functions_in_module($module)) {
452 my $external_calling_convention =
453 $winapi->function_external_calling_convention_in_module($module, $external_name);
454 if($external_calling_convention !~ /^(?:forward|stub)$/) {
455 if($module_pseudo_stub{$module}{$external_name}) {
456 $external_calling_convention = "pseudo_stub";
458 } elsif($external_calling_convention eq "forward") {
459 (my $forward_module, my $forward_external_name) =
460 $winapi->function_forward_final_destination($module, $external_name);
462 my $forward_external_calling_convention =
463 $winapi->function_external_calling_convention_in_module($forward_module, $forward_external_name);
465 if(!defined($forward_external_calling_convention)) {
469 if($forward_external_calling_convention ne "stub" &&
470 $module_pseudo_stub{$forward_module}{$forward_external_name})
472 $forward_external_calling_convention = "pseudo_stub";
475 $external_calling_convention = "forward_$forward_external_calling_convention";
478 $module_counts{$module}{$external_calling_convention}++;
482 foreach my $module ($winapi->all_modules) {
483 my $pseudo_stubs = $module_counts{$module}{pseudo_stub} || 0;
484 my $real_stubs = $module_counts{$module}{stub} || 0;
485 my $forward_pseudo_stubs = $module_counts{$module}{forward_pseudo_stub} || 0;
486 my $forward_real_stubs = $module_counts{$module}{forward_stub} || 0;
490 foreach my $calling_convention (keys(%{$module_counts{$module}})) {
491 my $count = $module_counts{$module}{$calling_convention};
492 if($calling_convention =~ /^forward/) {
499 my $stubs = $real_stubs + $pseudo_stubs;
501 $output->write("*.c: $module: ");
502 $output->write("$stubs of $total functions are stubs ($real_stubs real, $pseudo_stubs pseudo) " .
503 "and $forwards are forwards\n");
507 my $forward_stubs = $forward_real_stubs + $forward_pseudo_stubs;
509 $output->write("*.c: $module: ");
510 $output->write("$forward_stubs of $forwards forwarded functions are stubs " .
511 "($forward_real_stubs real, $forward_pseudo_stubs pseudo)\n");
517 if($options->winetest) {
518 foreach my $module ($win32api->all_modules) {
521 my $package = $module;
522 $package =~ s/\.dll$//;
523 $package =~ s/\./_/g;
527 foreach my $external_name (sort(keys(%{$specifications{$module}{unknown}}))) {
528 my $entry = $specifications{$module}{unknown}{$external_name};
529 push @entries, $entry;
532 foreach my $ordinal (sort {$a <=> $b} keys(%{$specifications{$module}{fixed}})) {
533 my $entry = $specifications{$module}{fixed}{$ordinal};
534 push @entries, $entry;
537 foreach my $external_name (sort(keys(%{$specifications{$module}{unfixed}}))) {
538 my $entry = $specifications{$module}{unfixed}{$external_name};
539 push @entries, $entry;
543 foreach my $entry (@entries) {
544 my $external_name = $entry->{external_name};
545 my $ordinal = $entry->{ordinal};
546 my $function = $entry->{function};
548 my $return_kind = $function->return_kind32 || "undef";
549 my $calling_convention = $function->calling_convention32 || "undef";
550 my $refargument_kinds = $function->argument_kinds32;
553 if(defined($refargument_kinds)) {
554 @argument_kinds = map { $_ || "undef"; } @$refargument_kinds;
557 next if $calling_convention ne "stdcall";
558 next if $external_name eq "\@";
561 open(OUT, "> $wine_dir/programs/winetest/include/${package}.pm") || die "Error: Can't open $wine_dir/programs/winetest/include/${package}.pm: $!\n";
563 print OUT "package ${package};\n";
566 print OUT "use strict;\n";
569 print OUT "require Exporter;\n";
572 print OUT "use wine;\n";
573 print OUT "use vars qw(\@ISA \@EXPORT \@EXPORT_OK);\n";
576 print OUT "\@ISA = qw(Exporter);\n";
577 print OUT "\
@EXPORT = qw();\n";
578 print OUT "\
@EXPORT_OK = qw();\n";
581 print OUT "my \
$module_declarations = {\n";
586 print OUT " \"\Q
$external_name\E
\" => [\"$return_kind\", [";
588 foreach my $argument_kind (@argument_kinds) {
592 print OUT "\"$argument_kind\"";
603 print OUT "&wine
::declare
(\"$module\",\
%\
$module_declarations);\n";
604 print OUT "push \
@EXPORT, map { \"&\" . \
$_; } sort(keys(\
%\
$module_declarations));\n";