2 # Copyright 1999, 2000, 2001 Patrik Stridvall
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 package winapi_fixup_documentation;
23 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
28 @EXPORT_OK = qw(fixup_documentation);
30 use config qw($current_dir $wine_dir);
31 use modules qw($modules);
32 use options qw($options);
33 use output qw($output);
34 use winapi qw($win16api $win32api @winapis);
36 my %documentation_line_used;
38 sub fixup_documentation($$) {
42 my $file = $function->file;
43 my $documentation_line = $function->documentation_line;
44 my $documentation = $function->documentation;
45 my $function_line = $function->function_line;
46 my $linkage = $function->linkage;
47 my $return_type = $function->return_type;
48 my $calling_convention = $function->calling_convention;
49 my $internal_name = $function->internal_name;
50 my $statements = $function->statements;
52 if($linkage eq "static" ||
53 ($linkage eq "extern" && !defined($statements)) ||
54 ($linkage eq "" && !defined($statements)))
59 my @external_names = $function->external_names;
60 if($#external_names < 0) {
64 if($documentation_line_used{$file}{documentation_line}) {
65 $documentation = undef;
67 $documentation_line_used{$file}{$documentation_line}++;
69 my @module_ordinal_entries = ();
70 foreach my $entry2 ($function->get_all_module_ordinal) {
71 (my $external_name2, my $module2, my $ordinal2) = @$entry2;
72 if(($external_name2 eq "@" ||
73 ($win16api->is_module($module2) && !$win16api->is_function_stub_in_module($module2, $external_name2)) ||
74 ($win32api->is_module($module2) && !$win32api->is_function_stub_in_module($module2, $external_name2))) &&
75 $modules->is_allowed_module_in_file($module2, "$current_dir/$file"))
77 push @module_ordinal_entries, $entry2;
81 my $spec_modified = 0;
83 if($options->stub && defined($documentation)) {
84 my $calling_convention16 = $function->calling_convention16;
85 my $calling_convention32 = $function->calling_convention32;
87 foreach my $winapi (@winapis) {
89 my $module = $winapi->function_internal_module($internal_name);
90 my $ordinal = $winapi->function_internal_ordinal($internal_name);
92 if($winapi->is_function_stub_in_module($module, $internal_name)) {
93 my $external_name = $internal_name;
94 if($winapi->name eq "win16") {
95 $external_name =~ s/(?:_)?16([AW]?)$//;
100 push @entries, [$external_name, $module, $ordinal];
103 foreach (split(/\n/, $documentation)) {
104 if(/^\s*\*\s*(\S+)\s*[\(\[]\s*(\w+)\s*\.\s*([^\s\)\]]*)\s*[\)\]].*?$/) {
105 my $external_name = $1;
109 if($external_name ne "@" &&
110 $winapi->is_module($module) &&
111 $winapi->is_function_stub_in_module($module, $external_name) &&
112 $internal_name !~ /^\U$module\E_\Q$external_name\E$/)
114 push @entries, [$external_name, $module, $ordinal];
119 foreach my $entry (@entries) {
120 (my $external_name, my $module, my $ordinal) = @$entry;
122 my $refargument_types = $function->argument_types;
124 if(!defined($refargument_types)) {
130 my @argument_kinds = map {
133 if($type ne "..." && !defined($kind = $winapi->translate_argument($type))) {
134 $output->write("no win*.api translation defined: " . $type . "\n");
138 if(defined($kind) && $kind eq "longlong") {
141 } elsif(defined($kind)) {
144 } elsif($type eq "...") {
145 if($winapi->name eq "win16") {
146 $calling_convention16 = "pascal"; # FIXME: Is this correct?
148 $calling_convention32 = "varargs";
156 } @$refargument_types;
158 my $search = "^\\s*$ordinal\\s+stub\\s+$external_name\\s*(?:#.*?)?\$";
160 if($winapi->name eq "win16") {
161 $replace = "$ordinal $calling_convention16 $external_name(@argument_kinds) $internal_name";
163 $replace = "$ordinal $calling_convention32 $external_name(@argument_kinds) $internal_name";
168 $editor->replace_spec_file($module, $search, $replace);
174 my %found_external_names;
175 foreach my $external_name (@external_names) {
176 $found_external_names{$external_name} = {};
179 my $documentation_modified = 0;
181 if(!$spec_modified &&
182 (defined($documentation) && !$documentation_modified) &&
183 ($options->documentation_name || $options->documentation_ordinal ||
184 $options->documentation_missing))
193 my $line2 = $documentation_line - 1;
194 foreach (split(/\n/, $documentation)) {
196 if(/^(\s*\*\s*(\S+)\s*)((?:\s*[\(\[]\s*\w+(?:\s*\.\s*[^\s\)\]]*\s*)?[\)\]])+)(.*?)$/) {
198 my $external_name = $2;
205 while($part3 =~ s/^\s*([\(\[]\s*(\w+)(?:\s*\.\s*([^\s\)\]]*)\s*)?[\)\]])//) {
206 push @entries, [$1, $2, $3];
210 foreach my $external_name2 (@external_names) {
211 if($external_name eq $external_name2) {
212 foreach my $entry (@entries) {
213 (undef, my $module, undef) = @$entry;
214 $found_external_names{$external_name2}{$module} = 1;
223 foreach my $entry (@entries) {
225 (my $part32, my $module, my $ordinal) = @$entry;
227 foreach my $entry2 (@module_ordinal_entries) {
228 (my $external_name2, my $module2, my $ordinal2) = @$entry2;
230 if($options->documentation_name && lc($module) eq $module2 &&
231 $external_name ne $external_name2)
233 if(!$found && $part12 =~ s/\b\Q$external_name\E\b/$external_name2/) {
234 $external_name = $external_name2;
239 if($options->documentation_ordinal &&
240 $external_name eq $external_name2 &&
241 lc($module) eq $module2 &&
242 ($#entries > 0 || !defined($ordinal) || ($ordinal ne $ordinal2)))
244 if(defined($ordinal)) {
245 if($part32 =~ s/\Q$module\E\s*.\s*\Q$ordinal\E/\U$module2\E.$ordinal2/ || $#entries > 0) {
249 if($part32 =~ s/\Q$module\E/\U$module2\E.$ordinal2/ || $#entries > 0) {
255 if($replace2) { $replace2 .= "\n"; }
256 $replace2 .= "$part12$part32$part4";
261 $search = "^\Q$_\E\$";
262 $replace = $replace2;
265 } elsif(/^(\s*\*\s*)([^\s\(]+)(?:\(\))?\s*$/) {
267 my $external_name = $2;
269 if($internal_name =~ /^(?:\S+_)?\Q$external_name\E(?:16)?$/) {
270 foreach my $entry (@module_ordinal_entries) {
271 (my $external_name2, my $module, my $ordinal) = @$entry;
274 $search = "^\Q$_\E\$";
275 $replace = "$part1$external_name2 (\U$module\E.$ordinal)";
282 if(defined($line3) && defined($search) && defined($replace)) {
283 if($count > 1 || $#external_names >= 1) {
284 $output->write("multiple entries (fixup not supported)\n");
285 # $output->write("s/$search/$replace/\n");
286 # $output->write("@external_names\n");
288 $documentation_modified = 1;
289 $editor->substitute_line($line3, $search, $replace);
294 if(!$spec_modified && !$documentation_modified &&
295 $options->documentation_missing && defined($documentation))
303 my $line2 = $documentation_line - 1;
304 foreach (split(/\n/, $documentation)) {
306 if(/^(\s*\*\s*)(\S+\s*)([\(\[])\s*\w+\s*\.\s*[^\s\)\]]*\s*([\)\]]).*?$/) {
318 foreach my $entry2 (@module_ordinal_entries) {
319 (my $external_name2, my $module2, my $ordinal2) = @$entry2;
322 foreach my $external_name (keys(%found_external_names)) {
323 foreach my $module3 (keys(%{$found_external_names{$external_name}})) {
324 if($external_name eq $external_name2 && uc($module2) eq $module3) {
329 # FIXME: Not 100% correct
331 !$win16api->is_function_stub_in_module($module2, $internal_name) &&
332 !$win32api->is_function_stub_in_module($module2, $internal_name))
335 $documentation_modified = 1;
336 $part2 = $external_name2 . " " x (length($part2) - length($external_name2));
337 $editor->insert_line($line3, "$part1$part2$part3\U$module2\E.$ordinal2$part4\n");
339 $output->write("$external_name2 (\U$module2\E.$ordinal2) missing (fixup not supported)\n");
345 if(!$documentation_modified &&
346 defined($documentation) &&
347 $options->documentation_wrong)
349 my $line2 = $documentation_line - 1;
350 foreach (split(/\n/, $documentation)) {
352 if(/^\s*\*\s*(\S+)\s*[\(\[]\s*(\w+)\s*\.\s*([^\s\)\]]*)\s*[\)\]].*?$/) {
353 my $external_name = $1;
358 foreach my $entry2 (@module_ordinal_entries) {
359 (my $external_name2, my $module2, my $ordinal2) = @$entry2;
361 if($external_name eq $external_name2 &&
362 lc($module) eq $module2 &&
363 $ordinal eq $ordinal2)
370 $documentation_modified = 1;
372 $editor->delete_line($line2, "^\Q$_\E\$");
374 $output->write("$external_name (\U$module\E.$ordinal) wrong (fixup not supported)\n");
381 if(!$spec_modified && !$documentation_modified && !defined($documentation))
384 foreach my $winapi (@winapis) {
385 my $external_name = $winapi->function_external_name($internal_name);
386 my $module = $winapi->function_internal_module($internal_name);
387 my $ordinal = $winapi->function_internal_ordinal($internal_name);
389 if(defined($external_name) && defined($module) && defined($ordinal)) {
390 $insert .= " *\t\t$external_name (\U$module\E.$ordinal)\n";
394 $editor->insert_line($function_line,
395 "/" . "*" x 71 . "\n" .