7 my $class = ref($proto) || $proto;
11 my $options = \${$self->{OPTIONS}};
12 my $output = \${$self->{OUTPUT}};
13 my $name = \${$self->{NAME}};
23 } split(/\n/, `find $path -name \\*.api`);
25 foreach my $file (@files) {
27 $module =~ s/.*?\/([^\/]*?)\.api$/$1/;
28 $self->parse_api_file($file,$module);
37 my $options = \${$self->{OPTIONS}};
38 my $output = \${$self->{OUTPUT}};
39 my $allowed_kind = \%{$self->{ALLOWED_KIND}};
40 my $allowed_modules = \%{$self->{ALLOWED_MODULES}};
41 my $allowed_modules_limited = \%{$self->{ALLOWED_MODULES_LIMITED}};
42 my $allowed_modules_unlimited = \%{$self->{ALLOWED_MODULES_UNLIMITED}};
43 my $translate_argument = \%{$self->{TRANSLATE_ARGUMENT}};
44 my $type_format = \%{$self->{TYPE_FORMAT}};
54 if($$options->progress) {
55 $$output->progress("$file");
58 open(IN, "< $file") || die "$file: $!\n";
61 s/^\s*?(.*?)\s*$/$1/; # remove whitespace at begin and end of line
62 s/^(.*?)\s*#.*$/$1/; # remove comments
63 /^$/ && next; # skip empty lines
71 $$allowed_kind{$kind} = 1;
74 } elsif(/^--extension/) {
76 } elsif(/^--format=(\".*?\"|\S*)/) {
78 $format =~ s/^\"(.*?)\"$/$1/;
81 if(!defined($format)) {
83 $format = "%d|%u|%x|%X|";
84 $format .= "%hd|%hu|%hx|%hX|";
85 $format .= "%ld|%lu|%lx|%lX|";
86 $format .= "%04x|%04X|0x%04x|0x%04X|";
87 $format .= "%08x|%08X|0x%08x|0x%08X|";
88 $format .= "%08lx|%08lX|0x%08lx|0x%08lX";
89 } elsif($kind eq "longlong") {
91 } elsif($kind eq "ptr") {
93 } elsif($kind eq "segptr") {
95 } elsif($kind eq "str") {
97 } elsif($kind eq "wstr") {
99 } elsif($kind eq "word") {
100 $format = "%d|%u|%x|%X|";
101 $format .= "%hd|%hu|%hx|%hX|";
102 $format .= "%04x|%04X|0x%04x|0x%04X";
104 $format = "<unknown>";
107 } elsif(defined($kind)) {
110 if(defined($module)) {
111 if($$allowed_modules_unlimited{$type}) {
112 $$output->write("$file: type ($type) already specificed as an unlimited type\n");
113 } elsif(!$$allowed_modules{$type}{$module}) {
114 $$allowed_modules{$type}{$module} = 1;
115 $$allowed_modules_limited{$type} = 1;
117 $$output->write("$file: type ($type) already specificed\n");
120 $$allowed_modules_unlimited{$type} = 1;
123 $$allowed_modules_limited{$type} = 1;
125 if(defined($$translate_argument{$type}) && $$translate_argument{$type} ne $kind) {
126 $$output->write("$file: type ($type) respecified as different kind ($kind != $$translate_argument{$type})\n");
128 $$translate_argument{$type} = $kind;
131 $$type_format{$module}{$type} = $format;
133 $$output->write("$file: file must begin with %<type> statement\n");
140 sub get_spec_file_type {
142 my $class = ref($proto) || $proto;
149 open(IN, "< $file") || die "$file: $!\n";
156 if(/^name\s*(\S*)/) { $module = $1; }
157 if(/^type\s*(\w+)/) { $type = $1; }
159 if(defined($module) && defined($type)) { last; }
163 return ($type, $module);
166 sub read_spec_files {
168 my $class = ref($proto) || $proto;
171 my $wine_dir = shift;
172 my $current_dir = shift;
174 my $win16api = shift;
175 my $win32api = shift;
177 foreach my $file (@$files) {
178 (my $type, my $module) = 'winapi'->get_spec_file_type("$wine_dir/$file");
179 $modules->spec_file_module($file, $module);
180 if($type eq "win16") {
181 $win16api->parse_spec_file("$wine_dir/$file");
182 } elsif($type eq "win32") {
183 $win32api->parse_spec_file("$wine_dir/$file");
188 sub read_all_spec_files {
190 my $class = ref($proto) || $proto;
193 my $wine_dir = shift;
194 my $current_dir = shift;
195 my $file_type = shift;
196 my $win16api = shift;
197 my $win32api = shift;
201 if(&$file_type($_) eq "library") {
206 } split(/\n/, `find $wine_dir -name \\*.spec`);
208 'winapi'->read_spec_files($modules, $wine_dir, $current_dir, \@files, $win16api, $win32api);
211 sub parse_spec_file {
214 my $options = \${$self->{OPTIONS}};
215 my $output = \${$self->{OUTPUT}};
216 my $function_arguments = \%{$self->{FUNCTION_ARGUMENTS}};
217 my $function_calling_convention = \%{$self->{FUNCTION_CALLING_CONVENTION}};
218 my $function_stub = \%{$self->{FUNCTION_STUB}};
219 my $function_module = \%{$self->{FUNCTION_MODULE}};
220 my $modules = \%{$self->{MODULES}};
228 if($$options->progress) {
229 $$output->progress("$file");
232 open(IN, "< $file") || die "$file: $!\n";
236 while($lookahead || defined($_ = <IN>)) {
243 if(/^name\s*(\S*)/) { $module = $1; }
244 if(/^type\s*(\w+)/) { $type = $1; }
245 if(/^\d+|@/) { $header = 0; $lookahead = 1; }
250 if(/^(\d+|@)\s+(pascal|pascal16|stdcall|cdecl|register|interrupt|varargs)\s+(\S+)\s*\(\s*(.*?)\s*\)\s*(\S+)$/) {
251 my $calling_convention = $2;
252 my $external_name = $3;
254 my $internal_name = $5;
258 # FIXME: Internal name existing more than once not handled properly
259 $$function_arguments{$internal_name} = $arguments;
260 $$function_calling_convention{$internal_name} = $calling_convention;
261 if(!$$function_module{$internal_name}) {
262 $$function_module{$internal_name} = "$module";
263 } elsif($$function_module{$internal_name} !~ /$module/) {
264 $$function_module{$internal_name} .= " & $module";
267 if($$options->spec_mismatch) {
268 if($external_name eq "@") {
269 if($internal_name !~ /^\U$module\E_$ordinal$/) {
270 $$output->write("$file: $external_name: the internal name ($internal_name) mismatch\n");
273 my $name = $external_name;
279 $name2 =~ s/^(?:_|Rtl|k32|K32)//;
282 $name3 =~ s/^INT_Int[0-9a-f]{2}Handler$/BUILTIN_DefaultIntHandler/;
285 $name4 =~ s/^(VxDCall)\d$/$1/;
287 # FIXME: This special case is becuase of a very ugly kludge that should be fixed IMHO
289 $name5 =~ s/^(.*?16)_(.*?)$/$1_fn$2/;
291 if(uc($internal_name) ne uc($external_name) &&
292 $internal_name !~ /(\Q$name\E|\Q$name1\E|\Q$name2\E|\Q$name3\E|\Q$name4\E|\Q$name5\E)/)
294 $$output->write("$file: $external_name: internal name ($internal_name) mismatch\n");
298 } elsif(/^(\d+|@)\s+stub\s+(\S+)$/) {
299 my $external_name = $2;
304 if($type eq "win16") {
305 $internal_name = $external_name . "16";
307 $internal_name = $external_name;
310 # FIXME: Internal name existing more than once not handled properly
311 $$function_stub{$internal_name} = 1;
312 if(!$$function_module{$internal_name}) {
313 $$function_module{$internal_name} = "$module";
314 } elsif($$function_module{$internal_name} !~ /$module/) {
315 $$function_module{$internal_name} .= " & $module";
317 } elsif(/^(\d+|@)\s+(equate|long|word|extern|forward)/) {
320 my $next_line = <IN>;
321 if(!defined($next_line) || $next_line =~ /^\s*\d|@/) {
322 die "$file: $.: syntax error: '$_'\n";
329 if(defined($ordinal)) {
330 if($ordinal ne "@" && $ordinals{$ordinal}) {
331 $$output->write("$file: ordinal redefined: $_\n");
333 $ordinals{$ordinal}++;
338 $$modules{$module}++;
343 my $name = \${$self->{NAME}};
348 sub is_allowed_kind {
350 my $allowed_kind = \%{$self->{ALLOWED_KIND}};
354 return $$allowed_kind{$kind};
360 sub is_limited_type {
362 my $allowed_modules_limited = \%{$self->{ALLOWED_MODULES_LIMITED}};
366 return $$allowed_modules_limited{$type};
369 sub allowed_type_in_module {
371 my $allowed_modules = \%{$self->{ALLOWED_MODULES}};
372 my $allowed_modules_limited = \%{$self->{ALLOWED_MODULES_LIMITED}};
375 my @modules = split(/ \& /, shift);
377 if(!$$allowed_modules_limited{$type}) { return 1; }
379 foreach my $module (@modules) {
380 if($$allowed_modules{$type}{$module}) { return 1; }
386 sub type_used_in_module {
388 my $used_modules = \%{$self->{USED_MODULES}};
391 my @modules = split(/ \& /, shift);
393 foreach my $module (@modules) {
394 $$used_modules{$type}{$module} = 1;
402 my $used_modules = \%{$self->{USED_MODULES}};
403 my $allowed_modules = \%{$self->{ALLOWED_MODULES}};
406 foreach my $type (sort(keys(%$allowed_modules))) {
407 foreach my $module (sort(keys(%{$$allowed_modules{$type}}))) {
408 if(!$$used_modules{$type}{$module}) {
409 $$not_used{$module}{$type} = 1;
416 sub types_unlimited_used_in_modules {
419 my $output = \${$self->{OUTPUT}};
420 my $used_modules = \%{$self->{USED_MODULES}};
421 my $allowed_modules = \%{$self->{ALLOWED_MODULES}};
422 my $allowed_modules_unlimited = \%{$self->{ALLOWED_MODULES_UNLIMITED}};
425 foreach my $type (sort(keys(%$allowed_modules_unlimited))) {
428 foreach my $module (sort(keys(%{$$used_modules{$type}}))) {
430 push @modules, $module;
433 foreach my $module (@modules) {
434 $$used_types{$type}{$module} = 1;
441 sub translate_argument {
443 my $translate_argument = \%{$self->{TRANSLATE_ARGUMENT}};
445 my $argument = shift;
447 return $$translate_argument{$argument};
450 sub all_declared_types {
452 my $translate_argument = \%{$self->{TRANSLATE_ARGUMENT}};
454 return sort(keys(%$translate_argument));
459 my $type_found = \%{$self->{TYPE_FOUND}};
463 $$type_found{$name}++;
468 my $type_found= \%{$self->{TYPE_FOUND}};
472 return $$type_found{$name};
475 sub is_allowed_type_format {
477 my $type_format = \%{$self->{TYPE_FORMAT}};
485 if(defined($module) && defined($type)) {
487 foreach (split(/ & /, $module)) {
488 if(defined($formats)) {
493 if(defined($$type_format{$_}{$type})) {
494 $formats .= $$type_format{$_}{$type};
499 if(defined($formats)) {
501 foreach (split(/\|/, $formats)) {
513 my $modules = \%{$self->{MODULES}};
515 return sort(keys(%$modules));
520 my $modules = \%{$self->{MODULES}};
524 return $$modules{$name};
529 my $function_calling_convention = \%{$self->{FUNCTION_CALLING_CONVENTION}};
531 return sort(keys(%$function_calling_convention));
534 sub all_functions_stub {
536 my $function_stub = \%{$self->{FUNCTION_STUB}};
538 return sort(keys(%$function_stub));
541 sub all_functions_found {
543 my $function_found = \%{$self->{FUNCTION_FOUND}};
545 return sort(keys(%$function_found));
548 sub function_calling_convention {
550 my $function_calling_convention = \%{$self->{FUNCTION_CALLING_CONVENTION}};
554 return $$function_calling_convention{$name};
559 my $function_calling_convention = \%{$self->{FUNCTION_CALLING_CONVENTION}};
563 return $$function_calling_convention{$name};
566 sub is_shared_function {
568 my $function_shared = \%{$self->{FUNCTION_SHARED}};
572 return $$function_shared{$name};
575 sub found_shared_function {
577 my $function_shared = \%{$self->{FUNCTION_SHARED}};
581 $$function_shared{$name} = 1;
584 sub function_arguments {
586 my $function_arguments = \%{$self->{FUNCTION_ARGUMENTS}};
590 return $$function_arguments{$name};
593 sub function_module {
595 my $function_module = \%{$self->{FUNCTION_MODULE}};
599 return $$function_module{$name};
604 my $function_stub = \%{$self->{FUNCTION_STUB}};
608 return $$function_stub{$name};
613 my $function_found = \%{$self->{FUNCTION_FOUND}};
617 $$function_found{$name}++;
622 my $function_found = \%{$self->{FUNCTION_FOUND}};
626 return $$function_found{$name};