11 my $function_found_callback = shift;
12 my $preprocessor_found_callback = shift;
15 my $debug_channels = [];
18 my $documentation_line;
23 my $calling_convention;
24 my $internal_name = "";
27 my $argument_documentations;
30 my $function_begin = sub {
31 $documentation_line = shift;
32 $documentation = shift;
33 $function_line = shift;
36 $calling_convention = shift;
37 $internal_name = shift;
38 $argument_types = shift;
39 $argument_names = shift;
40 $argument_documentations = shift;
42 if($#$argument_names == -1) {
43 foreach my $n (0..$#$argument_types) {
44 push @$argument_names, "";
48 if($#$argument_documentations == -1) {
49 foreach my $n (0..$#$argument_documentations) {
50 push @$argument_documentations, "";
56 my $function_end = sub {
57 my $function = 'winapi_function'->new;
59 if(!defined($documentation_line)) {
60 $documentation_line = 0;
63 $function->file($file);
64 $function->debug_channels([@$debug_channels]);
65 $function->documentation_line($documentation_line);
66 $function->documentation($documentation);
67 $function->function_line($function_line);
68 $function->linkage($linkage);
69 $function->return_type($return_type);
70 $function->calling_convention($calling_convention);
71 $function->internal_name($internal_name);
72 $function->argument_types([@$argument_types]);
73 $function->argument_names([@$argument_names]);
74 $function->argument_documentations([@$argument_documentations]);
75 $function->statements($statements);
77 &$function_found_callback($function);
81 my @comment_lines = ();
87 my $lookahead_count = 0;
89 print STDERR "Processing file '$file' ... " if $options->verbose;
90 open(IN, "< $file") || die "<internal>: $file: $!\n";
92 while($again || defined(my $line = <IN>)) {
102 $lookahead_count = 0;
104 print " $level($lookahead_count): $line\n" if $options->debug >= 2;
105 print "*** $_\n" if $options->debug >= 3;
107 $lookahead_count = 0;
111 # CVS merge conflicts in file?
112 if(/^(<<<<<<<|=======|>>>>>>>)/) {
113 $output->write("$file: merge conflicts in file\n");
118 if(s/^(.*?)(\/\*.*?\*\/)(.*)$/$1 $3/s) {
119 push @comment_lines, $.;
129 # remove C++ comments
130 while(s/^(.*?)\/\/.*?$/$1\n/s) { $again = 1 }
134 if(/^\s*$/) { next; }
136 # remove preprocessor directives
141 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
143 &$preprocessor_found_callback($1, $3);
145 &$preprocessor_found_callback($1, "");
152 if(s/^\s*extern\s+"C"\s+\{//m) {
158 my $documentation_line;
160 my @argument_documentations = ();
163 while($n >= 0 && ($comments[$n] !~ /^\/\*\*/ ||
164 $comments[$n] =~ /^\/\*\*+\/$/))
169 if(defined($comments[$n]) && $n >= 0) {
170 my @lines = split(/\n/, $comments[$n]);
172 $documentation_line = $comment_lines[$n] - scalar(@lines) + 1;
173 $documentation = $comments[$n];
175 for(my $m=$n+1; $m <= $#comments; $m++) {
176 if($comments[$m] =~ /^\/\*\*+\/$/ ||
177 $comments[$m] =~ /^\/\*\s*(?:\!)?defined/) # FIXME: Kludge
179 @argument_documentations = ();
182 push @argument_documentations, $comments[$m];
193 s/^([^\{\}\'\"]*)//s;
197 while(/^./ && !s/^\'//) {
214 while(/^./ && !s/^\"//) {
235 print "+1: \{$_\n" if $options->debug >= 2;
239 $line .= "}" if $level > 1;
240 print "-1: \}$_\n" if $options->debug >= 2;
242 if($level == -1 && $extern_c) {
248 if(!defined($statements)) {
252 if($line !~ /^\s*$/) {
253 $statements .= "$line\n";
256 if($internal_name && $level == 0) {
260 } elsif(/(extern\s+|static\s+)?((struct\s+|union\s+|enum\s+|signed\s+|unsigned\s+)?\w+((\s*\*)+\s*|\s+))
261 ((__cdecl|__stdcall|CDECL|VFWAPIV|VFWAPI|WINAPIV|WINAPI|CALLBACK)\s+)?
262 (\w+(\(\w+\))?)\s*\(([^\)]*)\)\s*(\{|\;)/sx)
264 my @lines = split(/\n/, $&);
265 my $function_line = $. - scalar(@lines) + 1;
274 my $return_type = $2;
275 my $calling_convention = $7;
279 if(!defined($linkage)) {
283 if(!defined($calling_convention)) {
284 $calling_convention = "";
287 $linkage =~ s/\s*$//;
289 $return_type =~ s/\s*$//;
290 $return_type =~ s/\s*\*\s*/*/g;
291 $return_type =~ s/(\*+)/ $1/g;
293 if($regs_entrypoints{$name}) {
294 $name = $regs_entrypoints{$name};
297 $arguments =~ y/\t\n/ /;
298 $arguments =~ s/^\s*(.*?)\s*$/$1/;
299 if($arguments eq "") { $arguments = "..." }
303 my @arguments = split(/,/, $arguments);
304 foreach my $n (0..$#arguments) {
305 my $argument_type = "";
306 my $argument_name = "";
307 my $argument = $arguments[$n];
308 $argument =~ s/^\s*(.*?)\s*$/$1/;
309 # print " " . ($n + 1) . ": '$argument'\n";
310 $argument =~ s/^(IN OUT(?=\s)|IN(?=\s)|OUT(?=\s)|\s*)\s*//;
311 $argument =~ s/^(const(?=\s)|CONST(?=\s)|\s*)\s*//;
312 if($argument =~ /^\.\.\.$/) {
313 $argument_type = "...";
314 $argument_name = "...";
315 } elsif($argument =~ /^
316 ((?:struct\s+|union\s+|enum\s+|(?:signed\s+|unsigned\s+)
317 (?:short\s+(?=int)|long\s+(?=int))?)?\w+)\s*
318 ((?:const)?\s*(?:\*\s*?)*)\s*
319 (?:WINE_UNUSED\s+)?(\w*)\s*(?:\[\]|\s+OPTIONAL)?/x)
321 $argument_type = "$1";
323 $argument_type .= " $2";
327 $argument_type =~ s/\s*const\s*/ /;
328 $argument_type =~ s/^\s*(.*?)\s*$/$1/;
330 $argument_name =~ s/^\s*(.*?)\s*$/$1/;
332 die "$file: $.: syntax error: '$argument'\n";
334 $argument_types[$n] = $argument_type;
335 $argument_names[$n] = $argument_name;
336 # print " " . ($n + 1) . ": '" . $argument_types[$n] . "', '" . $argument_names[$n] . "'\n";
338 if($#argument_types == 0 && $argument_types[0] =~ /^void$/i) {
339 $#argument_types = -1;
340 $#argument_names = -1;
343 if($options->debug) {
344 print "$file: $return_type $calling_convention $name(" . join(",", @arguments) . ")\n";
347 &$function_begin($documentation_line, $documentation,
348 $function_line, $linkage, $return_type, $calling_convention, $name,
349 \@argument_types,\@argument_names,\@argument_documentations);
353 } elsif(/__ASM_GLOBAL_FUNC\(\s*(.*?)\s*,/s) {
356 &$function_begin($documentation_line, $documentation,
357 $function_line, "", "void", "__asm", $1, \@arguments);
359 } elsif(/DC_(GET_X_Y|GET_VAL_16)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
361 my @arguments = ("HDC16");
362 &$function_begin($documentation_line, $documentation,
363 $function_line, "", $2, "WINAPI", $3, \@arguments);
365 } elsif(/DC_(GET_VAL)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,.*?\)/s) {
367 my $return16 = $3 . "16";
369 my $name16 = $2 . "16";
371 my @arguments16 = ("HDC16");
372 my @arguments32 = ("HDC");
374 if($name16 eq "COLORREF16") { $name16 = "COLORREF"; }
376 &$function_begin($documentation_line, $documentation,
377 $function_line, "", $name16, "WINAPI", $return16, \@arguments16);
379 &$function_begin($documentation_line, $documentation,
380 $function_line, "", $name32, "WINAPI", $return32, \@arguments32);
382 } elsif(/DC_(GET_VAL_EX)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
384 my @arguments16 = ("HDC16", "LP" . $5 . "16");
385 my @arguments32 = ("HDC", "LP" . $5);
386 &$function_begin($documentation_line, $documentation,
387 $function_line, "", "BOOL16", "WINAPI", $2 . "16", \@arguments16);
389 &$function_begin($documentation_line, $documentation,
390 $function_line, "", "BOOL", "WINAPI", $2, \@arguments32);
392 } elsif(/DC_(SET_MODE)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
394 my @arguments16 = ("HDC16", "INT16");
395 my @arguments32 = ("HDC", "INT");
396 &$function_begin($documentation_line, $documentation,
397 $function_line, "", "INT16", "WINAPI", $2 . "16", \@arguments16);
399 &$function_begin($documentation_line, $documentation,
400 $function_line, "", "INT", "WINAPI", $2, \@arguments32);
402 } elsif(/WAVEIN_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
404 my @arguments16 = ("HWAVEIN16");
405 my @arguments32 = ("HWAVEIN");
406 &$function_begin($documentation_line, $documentation,
407 $function_line, "", "UINT16", "WINAPI", "waveIn" . $1 . "16", \@arguments16);
409 &$function_begin($documentation_line, $documentation,
410 $function_line, "", "UINT", "WINAPI", "waveIn" . $1, \@arguments32);
412 } elsif(/WAVEOUT_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
414 my @arguments16 = ("HWAVEOUT16");
415 my @arguments32 = ("HWAVEOUT");
416 &$function_begin($documentation_line, $documentation,
417 $function_line, "", "UINT16", "WINAPI", "waveOut" . $1 . "16", \@arguments16);
419 &$function_begin($documentation_line, $documentation,
420 $function_line, "", "UINT", "WINAPI", "waveOut" . $1, \@arguments32);
422 } elsif(/WAVEOUT_SHORTCUT_(1|2)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
425 my @arguments16 = ("HWAVEOUT16", $4);
426 my @arguments32 = ("HWAVEOUT", $4);
427 &$function_begin($documentation_line, $documentation,
428 $function_line, "", "UINT16", "WINAPI", "waveOut" . $2 . "16", \@arguments16);
430 &$function_begin($documentation_line, $documentation,
431 $function_line, "", "UINT", "WINAPI", "waveOut" . $2, \@arguments32);
434 my @arguments16 = ("UINT16", $4);
435 my @arguments32 = ("UINT", $4);
436 &$function_begin($documentation_line, $documentation,
437 $function_line, "", "UINT16", "WINAPI", "waveOut". $2 . "16", \@arguments16);
439 &$function_begin($documentation_line, $documentation,
440 $function_line, "", "UINT", "WINAPI", "waveOut" . $2, \@arguments32);
443 } elsif(/DEFINE_REGS_ENTRYPOINT_\d+\(\s*(\S*)\s*,\s*([^\s,\)]*).*?\)/s) {
445 $regs_entrypoints{$2} = $1;
446 } elsif(/DEFAULT_DEBUG_CHANNEL\s*\((\S+)\)/s) {
448 unshift @$debug_channels, $1;
449 } elsif(/(DEFAULT|DECLARE)_DEBUG_CHANNEL\s*\((\S+)\)/s) {
451 push @$debug_channels, $1;
452 } elsif(/\'[^\']*\'/s) {
454 } elsif(/\"[^\"]*\"/s) {
458 } elsif(/extern\s+"C"\s+{/s) {
462 print "+1: $_\n" if $options->debug >= 2;
469 print STDERR "done\n" if $options->verbose;
470 $output->write("$file: not at toplevel at end of file\n") unless $level == 0;