- API files update.
[wine] / tools / winapi / winapi.pm
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17 #
18
19 package winapi;
20
21 use strict;
22
23 use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);
24 require Exporter;
25
26 @ISA = qw(Exporter);
27 @EXPORT = qw();
28 @EXPORT_OK = qw($win16api $win32api @winapis);
29
30 use vars qw($win16api $win32api @winapis);
31
32 use config qw($current_dir $wine_dir $winapi_dir);
33 use options qw($options);
34 use output qw($output);
35
36 use vars qw($modules);
37
38 sub import {
39     $Exporter::ExportLevel++;
40     &Exporter::import(@_);
41     $Exporter::ExportLevel--;
42
43     if (defined($modules) && defined($win16api) && defined($win32api)) {
44         return;
45     }
46
47     require modules;
48     import modules qw($modules);
49
50     my @spec_files16 = $modules->allowed_spec_files16;
51     $win16api = 'winapi'->new("win16", \@spec_files16);
52     
53     my @spec_files32 = $modules->allowed_spec_files32;
54     $win32api = 'winapi'->new("win32", \@spec_files32);
55     
56     @winapis = ($win16api, $win32api);
57
58     for my $internal_name ($win32api->all_internal_functions) {
59         my $module16 = $win16api->function_internal_module($internal_name);
60         my $module32 = $win16api->function_internal_module($internal_name);
61         if(defined($module16) &&
62            !$win16api->is_function_stub_in_module($module16, $internal_name) &&
63            !$win32api->is_function_stub_in_module($module32, $internal_name))
64         {
65             $win16api->found_shared_internal_function($internal_name);
66             $win32api->found_shared_internal_function($internal_name);
67         }
68     }
69 }
70
71
72 sub new {
73     my $proto = shift;
74     my $class = ref($proto) || $proto;
75     my $self  = {};
76     bless ($self, $class);
77
78     my $name = \${$self->{NAME}};
79     my $function_forward = \%{$self->{FUNCTION_FORWARD}};
80     my $function_internal_name = \%{$self->{FUNCTION_INTERNAL_NAME}};
81     my $function_module = \%{$self->{FUNCTION_MODULE}};
82
83     $$name = shift;
84     my $refspec_files = shift;
85
86     foreach my $file (@$refspec_files) {
87         $self->parse_spec_file("$wine_dir/$file");
88     }
89
90     $self->parse_api_file("$$name.api");
91
92     foreach my $module (sort(keys(%$function_forward))) {
93         foreach my $external_name (sort(keys(%{$$function_forward{$module}}))) {
94             (my $forward_module, my $forward_external_name) = @{$$function_forward{$module}{$external_name}};
95             my $forward_internal_name = $$function_internal_name{$forward_external_name};
96             if(defined($forward_internal_name)) {
97                 $$function_module{$forward_internal_name} .= " & $module";
98             }
99         }
100     }
101
102     return $self;
103 }
104
105 sub win16api {
106     return $win16api;
107 }
108
109 sub win32api {
110     return $win32api;
111 }
112
113 sub parse_api_file {
114     my $self = shift;
115
116     my $allowed_kind = \%{$self->{ALLOWED_KIND}};
117     my $allowed_modules = \%{$self->{ALLOWED_MODULES}};
118     my $allowed_modules_limited = \%{$self->{ALLOWED_MODULES_LIMITED}};
119     my $allowed_modules_unlimited = \%{$self->{ALLOWED_MODULES_UNLIMITED}};
120     my $translate_argument = \%{$self->{TRANSLATE_ARGUMENT}};
121     my $type_format = \%{$self->{TYPE_FORMAT}};
122
123     my $file = shift;
124
125     my $module;
126     my $kind;
127     my $format;
128     my $extension = 0;
129     my $forbidden = 0;
130
131     $output->lazy_progress("$file");
132
133     open(IN, "< $winapi_dir/$file") || die "$winapi_dir/$file: $!\n";
134     $/ = "\n";
135     while(<IN>) {
136         s/^\s*?(.*?)\s*$/$1/; # remove whitespace at begin and end of line
137         s/^(.*?)\s*#.*$/$1/;  # remove comments
138         /^$/ && next;         # skip empty lines
139
140         if(/^%%(\S+)$/) {
141             $module = $1;
142             $module =~ s/\.dll$//; # FIXME: Kludge
143         } elsif(!$modules->is_allowed_module($module)) {
144             # Nothing
145         } elsif(s/^%(\S+)\s*//) {
146             $kind = $1;
147             $format = undef;
148             $forbidden = 0;
149             $extension = 0;
150
151             $$allowed_kind{$kind} = 1;
152             if(/^--forbidden/) {
153                 $forbidden = 1;
154             } elsif(/^--extension/) {
155                 $extension = 1;
156             } elsif(/^--format=(\".*?\"|\S*)/) {
157                 $format = $1;
158                 $format =~ s/^\"(.*?)\"$/$1/;
159             }
160
161             if(!defined($format)) {
162                 if($kind eq "long") {
163                     $format  = "%d|%u|%x|%X|";
164                     $format .= "%hd|%hu|%hx|%hX|";
165                     $format .= "%ld|%lu|%lx|%lX|";
166                     $format .= "%04x|%04X|0x%04x|0x%04X|";
167                     $format .= "%08x|%08X|0x%08x|0x%08X|";
168                     $format .= "%08lx|%08lX|0x%08lx|0x%08lX";
169                 } elsif($kind eq "longlong") {
170                     $format = "%lld";
171                 } elsif($kind eq "ptr") {
172                     $format = "%p";
173                 } elsif($kind eq "segptr") {
174                     $format = "%p";
175                 } elsif($kind eq "str") {
176                     $format = "%p|%s";
177                 } elsif($kind eq "wstr") {
178                     $format = "%p|%s";
179                 } elsif($kind eq "word") {
180                     $format  = "%d|%u|%x|%X|";
181                     $format .= "%hd|%hu|%hx|%hX|";
182                     $format .= "%04x|%04X|0x%04x|0x%04X";
183                 } else {
184                     $format = "<unknown>";
185                 }
186             }
187         } elsif(defined($kind)) {
188             my $type = $_;
189             if(!$forbidden) {
190                 if(defined($module)) {
191                     if($$allowed_modules_unlimited{$type}) {
192                         $output->write("$file: type ($type) already specificed as an unlimited type\n");
193                     } elsif(!$$allowed_modules{$type}{$module}) {
194                         $$allowed_modules{$type}{$module} = 1;
195                         $$allowed_modules_limited{$type} = 1;
196                     } else {
197                         $output->write("$file: type ($type) already specificed\n");
198                     }
199                 } else {
200                     $$allowed_modules_unlimited{$type} = 1;
201                 }
202             } else {
203                 $$allowed_modules_limited{$type} = 1;
204             }
205             if(defined($$translate_argument{$type}) && $$translate_argument{$type} ne $kind) {
206                 $output->write("$file: type ($type) respecified as different kind ($kind != $$translate_argument{$type})\n");
207             } else {
208                 $$translate_argument{$type} = $kind;
209             }
210
211             $$type_format{$module}{$type} = $format;
212         } else {
213             $output->write("$file: file must begin with %<type> statement\n");
214             exit 1;
215         }
216     }
217     close(IN);
218 }
219
220 sub parse_spec_file {
221     my $self = shift;
222
223     my $function_internal_arguments = \%{$self->{FUNCTION_INTERNAL_ARGUMENTS}};
224     my $function_external_arguments = \%{$self->{FUNCTION_EXTERNAL_ARGUMENTS}};
225     my $function_internal_ordinal = \%{$self->{FUNCTION_INTERNAL_ORDINAL}};
226     my $function_external_ordinal = \%{$self->{FUNCTION_EXTERNAL_ORDINAL}};
227     my $function_internal_calling_convention = \%{$self->{FUNCTION_INTERNAL_CALLING_CONVENTION}};
228     my $function_external_calling_convention = \%{$self->{FUNCTION_EXTERNAL_CALLING_CONVENTION}};
229     my $function_internal_name = \%{$self->{FUNCTION_INTERNAL_NAME}};
230     my $function_external_name = \%{$self->{FUNCTION_EXTERNAL_NAME}};
231     my $function_forward = \%{$self->{FUNCTION_FORWARD}};
232     my $function_internal_module = \%{$self->{FUNCTION_INTERNAL_MODULE}};
233     my $function_external_module = \%{$self->{FUNCTION_EXTERNAL_MODULE}};
234     my $function_wine_extension = \%{$self->{FUNCTION_WINE_EXTENSION}};
235     my $modules = \%{$self->{MODULES}};
236     my $module_files = \%{$self->{MODULE_FILES}};
237     my $module_external_calling_convention = \%{$self->{MODULE_EXTERNAL_CALLING_CONVENTION}};
238
239     my $file = shift;
240     $file =~ s%^\./%%;
241
242     my %ordinals;
243     my $module;
244     my $wine_extension = 0;
245
246     $output->lazy_progress("$file");
247
248     $module = $file;
249     $module =~ s/^.*?([^\/]*)\.spec$/$1/;
250
251     open(IN, "< $file") || die "$file: $!\n";
252     $/ = "\n";
253     my $header = 1;
254     my $lookahead = 0;
255     while($lookahead || defined($_ = <IN>)) {
256         $lookahead = 0;
257         s/^\s*(.*?)\s*$/$1/;
258         if(s/^(.*?)\s*\#\s*(.*)\s*$/$1/) {
259             my $comment = $2;
260             if ($comment =~ /^Wine/) { # FIXME: Kludge
261                 $wine_extension = 1;
262             }
263         }
264         /^$/ && next;
265
266         if($header)  {
267             if(/^\d+|@/) { $header = 0; $lookahead = 1; }
268             next;
269         }
270
271         my $ordinal;
272         if(/^(\d+|@)\s+
273            (pascal|pascal16|stdcall|cdecl|varargs)\s+
274            ((?:(?:-noimport|-noname|-norelay|-i386|-ret64|-register|-interrupt)\s+)*)(\S+)\s*\(\s*(.*?)\s*\)\s*(\S+)$/x)
275         {
276             my $calling_convention = $2;
277             my $flags = $3;
278             my $external_name = $4;
279             my $arguments = $5;
280             my $internal_name = $6;
281
282             $ordinal = $1;
283
284             $flags =~ s/\s+/ /g;
285
286             if($flags =~ /-noname/) {
287                 # $external_name = "@";
288             }
289
290             if($flags =~ /(?:-register|-interrupt)/) {
291                 if($arguments) { $arguments .= " "; }
292                 $arguments .= "ptr";
293                 $calling_convention .= " -register";
294             }
295
296             if($external_name ne "@") {
297                 $$module_external_calling_convention{$module}{$external_name} = $calling_convention;
298             } else {
299                 $$module_external_calling_convention{$module}{"\@$ordinal"} = $calling_convention;
300             }
301             if(!$$function_internal_name{$external_name}) {
302                 $$function_internal_name{$external_name} = $internal_name;
303             } else {
304                 $$function_internal_name{$external_name} .= " & $internal_name";
305             }
306             if(!$$function_external_name{$internal_name}) {
307                 $$function_external_name{$internal_name} = $external_name;
308             } else {
309                 $$function_external_name{$internal_name} .= " & $external_name";
310             }
311             $$function_internal_arguments{$internal_name} = $arguments;
312             $$function_external_arguments{$external_name} = $arguments;
313             if(!$$function_internal_ordinal{$internal_name}) {
314                 $$function_internal_ordinal{$internal_name} = $ordinal;
315             } else {
316                 $$function_internal_ordinal{$internal_name} .= " & $ordinal";
317             }
318             if(!$$function_external_ordinal{$external_name}) {
319                 $$function_external_ordinal{$external_name} = $ordinal;
320             } else {
321                 $$function_external_ordinal{$external_name} .= " & $ordinal";
322             }
323             $$function_internal_calling_convention{$internal_name} = $calling_convention;
324             $$function_external_calling_convention{$external_name} = $calling_convention;
325             if(!$$function_internal_module{$internal_name}) {
326                 $$function_internal_module{$internal_name} = "$module";
327             } else {
328                 $$function_internal_module{$internal_name} .= " & $module";
329             }
330             if(!$$function_external_module{$external_name}) {
331                 $$function_external_module{$external_name} = "$module";
332             } else {
333                 $$function_external_module{$external_name} .= " & $module";
334             }
335             $$function_wine_extension{$module}{$external_name} = $wine_extension;
336
337             if(0 && $options->spec_mismatch) {
338                 if($external_name eq "@") {
339                     if($internal_name !~ /^\U$module\E_$ordinal$/) {
340                         $output->write("$file: $external_name: the internal name ($internal_name) mismatch\n");
341                     }
342                 } else {
343                     my $name = $external_name;
344
345                     my $name1 = $name;
346                     $name1 =~ s/^Zw/Nt/;
347
348                     my $name2 = $name;
349                     $name2 =~ s/^(?:_|Rtl|k32|K32)//;
350
351                     my $name3 = $name;
352                     $name3 =~ s/^INT_Int[0-9a-f]{2}Handler$/BUILTIN_DefaultIntHandler/;
353
354                     my $name4 = $name;
355                     $name4 =~ s/^(VxDCall)\d$/$1/;
356
357                     # FIXME: This special case is becuase of a very ugly kludge that should be fixed IMHO
358                     my $name5 = $name;
359                     $name5 =~ s/^(.*?16)_(.*?)$/$1_fn$2/;
360
361                     if(uc($internal_name) ne uc($external_name) &&
362                        $internal_name !~ /(\Q$name\E|\Q$name1\E|\Q$name2\E|\Q$name3\E|\Q$name4\E|\Q$name5\E)/)
363                     {
364                         $output->write("$file: $external_name: internal name ($internal_name) mismatch\n");
365                     }
366                 }
367             }
368         } elsif(/^(\d+|@)\s+stub(?:\s+(-noimport|-noname|-norelay|-i386|-ret64))?\s+(\S+)$/) {
369             $ordinal = $1;
370
371             my $flags = $2;
372             my $external_name = $3;
373
374             $flags = "" if !defined($flags);
375
376             if($flags =~ /-noname/) {
377                 # $external_name = "@";
378             }
379
380             my $internal_name = $external_name;
381
382             if ($external_name ne "@") {
383                 $$module_external_calling_convention{$module}{$external_name} = "stub";
384             } else {
385                 $$module_external_calling_convention{$module}{"\@$ordinal"} = "stub";
386             }
387             if(!$$function_internal_name{$external_name}) {
388                 $$function_internal_name{$external_name} = $internal_name;
389             } else {
390                 $$function_internal_name{$external_name} .= " & $internal_name";
391             }
392             if(!$$function_external_name{$internal_name}) {
393                 $$function_external_name{$internal_name} = $external_name;
394             } else {
395                 $$function_external_name{$internal_name} .= " & $external_name";
396             }
397             if(!$$function_internal_ordinal{$internal_name}) {
398                 $$function_internal_ordinal{$internal_name} = $ordinal;
399             } else {
400                 $$function_internal_ordinal{$internal_name} .= " & $ordinal";
401             }
402             if(!$$function_external_ordinal{$external_name}) {
403                 $$function_external_ordinal{$external_name} = $ordinal;
404             } else {
405                 $$function_external_ordinal{$external_name} .= " & $ordinal";
406             }
407             if(!$$function_internal_module{$internal_name}) {
408                 $$function_internal_module{$internal_name} = "$module";
409             } else { # if($$function_internal_module{$internal_name} !~ /$module/) {
410                 $$function_internal_module{$internal_name} .= " & $module";
411             }
412             if(!$$function_external_module{$external_name}) {
413                 $$function_external_module{$external_name} = "$module";
414             } else { # if($$function_external_module{$external_name} !~ /$module/) {
415                 $$function_external_module{$external_name} .= " & $module";
416             }
417         } elsif(/^(\d+|@)\s+forward(?:\s+(?:-noimport|-norelay|-i386|-ret64))?\s+(\S+)\s+(\S+)\.(\S+)$/) {
418             $ordinal = $1;
419
420             my $external_name = $2;
421             my $forward_module = lc($3);
422             my $forward_name = $4;
423
424             if ($external_name ne "@") {
425                 $$module_external_calling_convention{$module}{$external_name} = "forward";
426             } else {
427                 $$module_external_calling_convention{$module}{"\@$ordinal"} = "forward";
428             }
429             $$function_forward{$module}{$external_name} = [$forward_module, $forward_name];
430         } elsif(/^(\d+|@)\s+extern\s+(\S+)\s+(\S+)$/) {
431             $ordinal = $1;
432
433             my $external_name = $2;
434             my $internal_name = $3;
435
436             if ($external_name ne "@") {
437                 $$module_external_calling_convention{$module}{$external_name} = "extern";
438             } else {
439                 $$module_external_calling_convention{$module}{"\@$ordinal"} = "extern";
440             }
441         } elsif(/^(\d+|@)\s+(equate|variable)/) {
442             # ignore
443         } else {
444             my $next_line = <IN>;
445             if(!defined($next_line) || $next_line =~ /^\s*\d|@/) {
446                 die "$file: $.: syntax error: '$_'\n";
447             } else {
448                 $_ .= $next_line;
449                 $lookahead = 1;
450             }
451         }
452
453         if(defined($ordinal)) {
454             if($ordinal ne "@" && $ordinals{$ordinal}) {
455                 $output->write("$file: ordinal redefined: $_\n");
456             }
457             $ordinals{$ordinal}++;
458         }
459     }
460     close(IN);
461
462     $$modules{$module}++;
463
464     $$module_files{$module} = $file;
465 }
466
467 sub name {
468     my $self = shift;
469     my $name = \${$self->{NAME}};
470
471     return $$name;
472 }
473
474 sub is_allowed_kind {
475     my $self = shift;
476     my $allowed_kind = \%{$self->{ALLOWED_KIND}};
477
478     my $kind = shift;
479     if(defined($kind)) {
480         return $$allowed_kind{$kind};
481     } else {
482         return 0;
483     }
484
485 }
486
487 sub allow_kind {
488     my $self = shift;
489     my $allowed_kind = \%{$self->{ALLOWED_KIND}};
490
491     my $kind = shift;
492
493     $$allowed_kind{$kind}++;
494 }
495
496 sub is_limited_type {
497     my $self = shift;
498     my $allowed_modules_limited = \%{$self->{ALLOWED_MODULES_LIMITED}};
499
500     my $type = shift;
501
502     return $$allowed_modules_limited{$type};
503 }
504
505 sub is_allowed_type_in_module {
506     my $self = shift;
507     my $allowed_modules = \%{$self->{ALLOWED_MODULES}};
508     my $allowed_modules_limited = \%{$self->{ALLOWED_MODULES_LIMITED}};
509
510     my $type = shift;
511     my @modules = split(/ \& /, shift);
512
513     if(!$$allowed_modules_limited{$type}) { return 1; }
514
515     foreach my $module (@modules) {
516         if($$allowed_modules{$type}{$module}) { return 1; }
517     }
518
519     return 0;
520 }
521
522 sub allow_type_in_module {
523     my $self = shift;
524     my $allowed_modules = \%{$self->{ALLOWED_MODULES}};
525
526     my $type = shift;
527     my @modules = split(/ \& /, shift);
528
529     foreach my $module (@modules) {
530         $$allowed_modules{$type}{$module}++;
531     }
532 }
533
534 sub type_used_in_module {
535     my $self = shift;
536     my $used_modules = \%{$self->{USED_MODULES}};
537
538     my $type = shift;
539     my @modules = split(/ \& /, shift);
540
541     foreach my $module (@modules) {
542         $$used_modules{$type}{$module} = 1;
543     }
544
545     return ();
546 }
547
548 sub types_not_used {
549     my $self = shift;
550     my $used_modules = \%{$self->{USED_MODULES}};
551     my $allowed_modules = \%{$self->{ALLOWED_MODULES}};
552
553     my $not_used;
554     foreach my $type (sort(keys(%$allowed_modules))) {
555         foreach my $module (sort(keys(%{$$allowed_modules{$type}}))) {
556             if(!$$used_modules{$type}{$module}) {
557                 $$not_used{$module}{$type} = 1;
558             }
559         }
560     }
561     return $not_used;
562 }
563
564 sub types_unlimited_used_in_modules {
565     my $self = shift;
566
567     my $used_modules = \%{$self->{USED_MODULES}};
568     my $allowed_modules = \%{$self->{ALLOWED_MODULES}};
569     my $allowed_modules_unlimited = \%{$self->{ALLOWED_MODULES_UNLIMITED}};
570
571     my $used_types;
572     foreach my $type (sort(keys(%$allowed_modules_unlimited))) {
573         my $count = 0;
574         my @modules = ();
575         foreach my $module (sort(keys(%{$$used_modules{$type}}))) {
576             $count++;
577             push @modules, $module;
578         }
579         if($count) {
580             foreach my $module (@modules) {
581               $$used_types{$type}{$module} = 1;
582             }
583         }
584     }
585     return $used_types;
586 }
587
588 sub translate_argument {
589     my $self = shift;
590     my $translate_argument = \%{$self->{TRANSLATE_ARGUMENT}};
591
592     my $type = shift;
593
594     return $$translate_argument{$type};
595 }
596
597 sub declare_argument {
598     my $self = shift;
599     my $translate_argument = \%{$self->{TRANSLATE_ARGUMENT}};
600
601     my $type = shift;
602     my $kind = shift;
603
604     $$translate_argument{$type} = $kind;
605 }
606
607 sub all_declared_types {
608     my $self = shift;
609     my $translate_argument = \%{$self->{TRANSLATE_ARGUMENT}};
610
611     return sort(keys(%$translate_argument));
612 }
613
614 sub is_allowed_type_format {
615     my $self = shift;
616     my $type_format = \%{$self->{TYPE_FORMAT}};
617
618     my $module = shift;
619     my $type = shift;
620     my $format = shift;
621
622     my $formats;
623
624     if(defined($module) && defined($type)) {
625         local $_;
626         foreach (split(/ & /, $module)) {
627             if(defined($formats)) {
628                 $formats .= "|";
629             } else {
630                 $formats = "";
631             }
632             if(defined($$type_format{$_}{$type})) {
633                 $formats .= $$type_format{$_}{$type};
634             }
635         }
636     }
637
638     if(defined($formats)) {
639         local $_;
640         foreach (split(/\|/, $formats)) {
641             if($_ eq $format) {
642                 return 1;
643             }
644         }
645     }
646
647     return 0;
648 }
649
650 sub all_modules {
651     my $self = shift;
652     my $modules = \%{$self->{MODULES}};
653
654     return sort(keys(%$modules));
655 }
656
657 sub is_module {
658     my $self = shift;
659     my $modules = \%{$self->{MODULES}};
660
661     my $name = shift;
662
663     return $$modules{$name};
664 }
665
666 sub module_file {
667     my $self = shift;
668
669     my $module = shift;
670
671     my $module_files = \%{$self->{MODULE_FILES}};
672
673     return $$module_files{$module};
674 }
675
676 sub all_internal_functions {
677     my $self = shift;
678     my $function_internal_calling_convention = \%{$self->{FUNCTION_INTERNAL_CALLING_CONVENTION}};
679
680     return sort(keys(%$function_internal_calling_convention));
681 }
682
683 sub all_internal_functions_in_module {
684     my $self = shift;
685     my $function_internal_calling_convention = \%{$self->{FUNCTION_INTERNAL_CALLING_CONVENTION}};
686     my $function_internal_module = \%{$self->{FUNCTION_INTERNAL_MODULE}};
687
688     my $module = shift;
689
690     my @names;
691     foreach my $name (keys(%$function_internal_calling_convention)) {
692         if($$function_internal_module{$name} eq $module) {
693             push @names, $name;
694         }
695     }
696
697     return sort(@names);
698 }
699
700 sub all_external_functions {
701     my $self = shift;
702     my $function_external_name = \%{$self->{FUNCTION_EXTERNAL_NAME}};
703
704     return sort(keys(%$function_external_name));
705 }
706
707 sub all_external_functions_in_module {
708     my $self = shift;
709     my $function_external_name = \%{$self->{FUNCTION_EXTERNAL_NAME}};
710     my $function_external_module = \%{$self->{FUNCTION_EXTERNAL_MODULE}};
711
712     my $module = shift;
713
714     my @names;
715     foreach my $name (keys(%$function_external_name)) {
716         if($$function_external_module{$name} eq $module) {
717             push @names, $name;
718         }
719     }
720
721     return sort(@names);
722 }
723
724 sub all_functions_in_module {
725     my $self = shift;
726     my $module_external_calling_convention = \%{$self->{MODULE_EXTERNAL_CALLING_CONVENTION}};
727
728     my $module = shift;
729
730     return sort(keys(%{$$module_external_calling_convention{$module}}));
731 }
732
733 sub all_broken_forwards {
734     my $self = shift;
735     my $function_forward = \%{$self->{FUNCTION_FORWARD}};
736
737     my @broken_forwards = ();
738     foreach my $module (sort(keys(%$function_forward))) {
739         foreach my $external_name (sort(keys(%{$$function_forward{$module}}))) {
740             (my $forward_module, my $forward_external_name) = @{$$function_forward{$module}{$external_name}};
741
742             my $forward_external_calling_convention =
743                 $self->function_external_calling_convention_in_module($forward_module, $forward_external_name);
744
745             if(!defined($forward_external_calling_convention)) {
746                 push @broken_forwards, [$module, $external_name, $forward_module, $forward_external_name];
747             }
748         }
749     }
750     return @broken_forwards;
751 }
752
753
754 sub function_internal_ordinal {
755     my $self = shift;
756     my $function_internal_ordinal = \%{$self->{FUNCTION_INTERNAL_ORDINAL}};
757
758     my $name = shift;
759
760     return $$function_internal_ordinal{$name};
761 }
762
763 sub function_external_ordinal {
764     my $self = shift;
765     my $function_external_ordinal = \%{$self->{FUNCTION_EXTERNAL_ORDINAL}};
766
767     my $name = shift;
768
769     return $$function_external_ordinal{$name};
770 }
771
772 sub function_internal_calling_convention {
773     my $self = shift;
774     my $function_internal_calling_convention = \%{$self->{FUNCTION_INTERNAL_CALLING_CONVENTION}};
775
776     my $name = shift;
777
778     return $$function_internal_calling_convention{$name};
779 }
780
781 sub function_external_calling_convention {
782     my $self = shift;
783     my $function_external_calling_convention = \%{$self->{FUNCTION_EXTERNAL_CALLING_CONVENTION}};
784
785     my $name = shift;
786
787     return $$function_external_calling_convention{$name};
788 }
789
790 sub function_external_calling_convention_in_module {
791     my $self = shift;
792     my $module_external_calling_convention = \%{$self->{MODULE_EXTERNAL_CALLING_CONVENTION}};
793
794     my $module = shift;
795     my $name = shift;
796
797     return $$module_external_calling_convention{$module}{$name};
798 }
799
800 sub function_internal_name {
801     my $self = shift;
802     my $function_internal_name = \%{$self->{FUNCTION_INTERNAL_NAME}};
803
804     my $name = shift;
805
806     return $$function_internal_name{$name};
807 }
808
809 sub function_external_name {
810     my $self = shift;
811     my $function_external_name = \%{$self->{FUNCTION_EXTERNAL_NAME}};
812
813     my $name = shift;
814
815     return $$function_external_name{$name};
816 }
817
818 sub function_forward_final_destination {
819     my $self = shift;
820
821     my $function_forward = \%{$self->{FUNCTION_FORWARD}};
822
823     my $module = shift;
824     my $name = shift;
825
826     my $forward_module = $module;
827     my $forward_name = $name;
828     while(defined(my $forward = $$function_forward{$forward_module}{$forward_name})) {
829         ($forward_module, $forward_name) = @$forward;
830     }
831
832     return ($forward_module, $forward_name);
833 }
834
835 sub is_function {
836     my $self = shift;
837     my $function_internal_calling_convention = \%{$self->{FUNCTION_INTERNAL_CALLING_CONVENTION}};
838
839     my $name = shift;
840
841     return $$function_internal_calling_convention{$name};
842 }
843
844 sub all_shared_internal_functions {
845     my $self = shift;
846     my $function_shared = \%{$self->{FUNCTION_SHARED}};
847
848     return sort(keys(%$function_shared));
849 }
850
851 sub is_shared_internal_function {
852     my $self = shift;
853     my $function_shared = \%{$self->{FUNCTION_SHARED}};
854
855     my $name = shift;
856
857     return $$function_shared{$name};
858 }
859
860 sub found_shared_internal_function {
861     my $self = shift;
862     my $function_shared = \%{$self->{FUNCTION_SHARED}};
863
864     my $name = shift;
865
866     $$function_shared{$name} = 1;
867 }
868
869 sub function_internal_arguments {
870     my $self = shift;
871     my $function_internal_arguments = \%{$self->{FUNCTION_INTERNAL_ARGUMENTS}};
872
873     my $name = shift;
874
875     return $$function_internal_arguments{$name};
876 }
877
878 sub function_external_arguments {
879     my $self = shift;
880     my $function_external_arguments = \%{$self->{FUNCTION_EXTERNAL_ARGUMENTS}};
881
882     my $name = shift;
883
884     return $$function_external_arguments{$name};
885 }
886
887 sub function_internal_module {
888     my $self = shift;
889     my $function_internal_module = \%{$self->{FUNCTION_INTERNAL_MODULE}};
890
891     my $name = shift;
892
893     return $$function_internal_module{$name};
894 }
895
896 sub function_external_module {
897     my $self = shift;
898     my $function_external_module = \%{$self->{FUNCTION_EXTERNAL_MODULE}};
899
900     my $name = shift;
901
902     return $$function_external_module{$name};
903 }
904
905 sub function_wine_extension {
906     my $self = shift;
907     my $function_wine_extension = \%{$self->{FUNCTION_WINE_EXTENSION}};
908
909     my $module = shift;
910     my $name = shift;
911
912     return $$function_wine_extension{$module}{$name};
913 }
914
915 sub is_function_stub {
916     my $self = shift;
917     my $module_external_calling_convention = \%{$self->{MODULE_EXTERNAL_CALLING_CONVENTION}};
918     my $modules = \%{$self->{MODULES}};
919
920     my $module = shift;
921     my $name = shift;
922
923     foreach my $module (keys(%$modules)) {
924         if($$module_external_calling_convention{$module}{$name} eq "stub") {
925             return 1;
926         }
927     }
928
929     return 0;
930 }
931
932 sub is_function_stub_in_module {
933     my $self = shift;
934     my $module_external_calling_convention = \%{$self->{MODULE_EXTERNAL_CALLING_CONVENTION}};
935
936     my $module = shift;
937     my $name = shift;
938
939     if(!defined($$module_external_calling_convention{$module}{$name})) {
940         return 0;
941     }
942     return $$module_external_calling_convention{$module}{$name} eq "stub";
943 }
944
945 ########################################################################
946 # class methods
947 #
948
949 sub _get_all_module_internal_ordinal {
950     my $winapi = shift;
951     my $internal_name = shift;
952
953     my @entries = ();
954
955     my @name = (); {
956         my $name = $winapi->function_external_name($internal_name);
957         if(defined($name)) {
958             @name = split(/ & /, $name);
959         }
960     }
961
962     my @module = (); {
963         my $module = $winapi->function_internal_module($internal_name);
964         if(defined($module)) {
965             @module = split(/ & /, $module);
966         }
967     }
968
969     my @ordinal = (); {
970         my $ordinal = $winapi->function_internal_ordinal($internal_name);
971         if(defined($ordinal)) {
972             @ordinal = split(/ & /, $ordinal);
973         }
974     }
975
976     my $name;
977     my $module;
978     my $ordinal;
979     while(defined($name = shift @name) &&
980           defined($module = shift @module) &&
981           defined($ordinal = shift @ordinal))
982     {
983         push @entries, [$name, $module, $ordinal];
984     }
985
986     return @entries;
987 }
988
989 sub get_all_module_internal_ordinal16 {
990     return _get_all_module_internal_ordinal($win16api, @_);
991 }
992
993 sub get_all_module_internal_ordinal32 {
994     return _get_all_module_internal_ordinal($win32api, @_);
995 }
996
997 sub get_all_module_internal_ordinal {
998     my @entries = ();
999     foreach my $winapi (@winapis) {
1000         push @entries, _get_all_module_internal_ordinal($winapi, @_);
1001     }
1002
1003     return @entries;
1004 }
1005
1006 sub _get_all_module_external_ordinal {
1007     my $winapi = shift;
1008     my $external_name = shift;
1009
1010     my @entries = ();
1011
1012     my @name = (); {
1013         my $name = $winapi->function_internal_name($external_name);
1014         if(defined($name)) {
1015             @name = split(/ & /, $name);
1016         }
1017     }
1018
1019     my @module = (); {
1020         my $module = $winapi->function_external_module($external_name);
1021         if(defined($module)) {
1022             @module = split(/ & /, $module);
1023         }
1024     }
1025
1026     my @ordinal = (); {
1027         my $ordinal = $winapi->function_external_ordinal($external_name);
1028         if(defined($ordinal)) {
1029             @ordinal = split(/ & /, $ordinal);
1030         }
1031     }
1032
1033     my $name;
1034     my $module;
1035     my $ordinal;
1036     while(defined($name = shift @name) &&
1037           defined($module = shift @module) &&
1038           defined($ordinal = shift @ordinal))
1039     {
1040         push @entries, [$name, $module, $ordinal];
1041     }
1042
1043     return @entries;
1044 }
1045
1046 sub get_all_module_external_ordinal16 {
1047     return _get_all_module_external_ordinal($win16api, @_);
1048 }
1049
1050 sub get_all_module_external_ordinal32 {
1051     return _get_all_module_external_ordinal($win32api, @_);
1052 }
1053
1054 sub get_all_module_external_ordinal {
1055     my @entries = ();
1056     foreach my $winapi (@winapis) {
1057         push @entries, _get_all_module_external_ordinal($winapi, @_);
1058     }
1059
1060     return @entries;
1061 }
1062
1063 1;