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 $function->file($file);
60 $function->debug_channels([@$debug_channels]);
61 $function->documentation($documentation);
62 $function->documentation_line($documentation_line);
63 $function->linkage($linkage);
64 $function->return_type($return_type);
65 $function->calling_convention($calling_convention);
66 $function->internal_name($internal_name);
67 $function->argument_types([@$argument_types]);
68 $function->argument_names([@$argument_names]);
69 $function->argument_documentations([@$argument_documentations]);
70 $function->statements($statements);
72 &$function_found_callback($function);
76 my @comment_lines = ();
82 my $lookahead_count = 0;
84 print STDERR "Processing file '$file' ... " if $options->verbose;
85 open(IN, "< $file") || die "<internal>: $file: $!\n";
87 while($again || defined(my $line = <IN>)) {
99 print " $level($lookahead_count): $line\n" if $options->debug >= 2;
100 print "*** $_\n" if $options->debug >= 3;
102 $lookahead_count = 0;
106 # CVS merge conflicts in file?
107 if(/^(<<<<<<<|=======|>>>>>>>)/) {
108 $output->write("$file: merge conflicts in file\n");
113 if(s/^(.*?)(\/\*.*?\*\/)(.*)$/$1 $3/s) {
114 push @comment_lines, $.;
124 # remove C++ comments
125 while(s/^(.*?)\/\/.*?$/$1\n/s) { $again = 1 }
129 if(/^\s*$/) { next; }
131 # remove preprocessor directives
136 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
138 &$preprocessor_found_callback($1, $3);
140 &$preprocessor_found_callback($1, "");
147 if(s/^\s*extern\s+"C"\s+\{//m) {
153 my $documentation_line;
155 my @argument_documentations = ();
158 while($n >= 0 && ($comments[$n] !~ /^\/\*\*/ ||
159 $comments[$n] =~ /^\/\*\*+\/$/))
164 if(defined($comments[$n]) && $n >= 0) {
165 my @lines = split(/\n/, $comments[$n]);
167 $documentation_line = $comment_lines[$n] - scalar(@lines) + 1;
168 $documentation = $comments[$n];
170 for(my $m=$n+1; $m <= $#comments; $m++) {
171 if($comments[$m] =~ /^\/\*\*+\/$/ ||
172 $comments[$m] =~ /^\/\*\s*(?:\!)?defined/) # FIXME: Kludge
174 @argument_documentations = ();
177 push @argument_documentations, $comments[$m];
188 s/^([^\{\}\'\"]*)//s;
192 while(/^./ && !s/^\'//) {
209 while(/^./ && !s/^\"//) {
230 print "+1: \{$_\n" if $options->debug >= 2;
234 $line .= "}" if $level > 1;
235 print "-1: \}$_\n" if $options->debug >= 2;
237 if($level == -1 && $extern_c) {
243 if(!defined($statements)) {
247 if($line !~ /^\s*$/) {
248 $statements .= "$line\n";
251 if($internal_name && $level == 0) {
255 } elsif(/(extern\s+|static\s+)?((struct\s+|union\s+|enum\s+)?\w+((\s*\*)+\s*|\s+))
256 ((__cdecl|__stdcall|CDECL|VFWAPIV|VFWAPI|WINAPIV|WINAPI|CALLBACK)\s+)?
257 (\w+(\(\w+\))?)\s*\(([^\)]*)\)\s*(\{|\;)/sx)
259 my @lines = split(/\n/, $&);
260 my $function_line = $. - scalar(@lines) + 1;
269 my $return_type = $2;
270 my $calling_convention = $7;
274 if(!defined($linkage)) {
278 if(!defined($calling_convention)) {
279 $calling_convention = "";
282 $linkage =~ s/\s*$//;
284 $return_type =~ s/\s*$//;
285 $return_type =~ s/\s*\*\s*/*/g;
286 $return_type =~ s/(\*+)/ $1/g;
288 if($regs_entrypoints{$name}) {
289 $name = $regs_entrypoints{$name};
292 $arguments =~ y/\t\n/ /;
293 $arguments =~ s/^\s*(.*?)\s*$/$1/;
294 if($arguments eq "") { $arguments = "..." }
298 my @arguments = split(/,/, $arguments);
299 foreach my $n (0..$#arguments) {
300 my $argument_type = "";
301 my $argument_name = "";
302 my $argument = $arguments[$n];
303 $argument =~ s/^\s*(.*?)\s*$/$1/;
304 # print " " . ($n + 1) . ": '$argument'\n";
305 $argument =~ s/^(IN OUT(?=\s)|IN(?=\s)|OUT(?=\s)|\s*)\s*//;
306 $argument =~ s/^(const(?=\s)|CONST(?=\s)|\s*)\s*//;
307 if($argument =~ /^\.\.\.$/) {
308 $argument_type = "...";
309 $argument_name = "...";
310 } elsif($argument =~ /^
311 ((?:struct\s+|union\s+|enum\s+|(?:signed\s+|unsigned\s+)
312 (?:short\s+(?=int)|long\s+(?=int))?)?\w+)\s*
313 ((?:const)?\s*(?:\*\s*?)*)\s*
314 (?:WINE_UNUSED\s+)?(\w*)\s*(?:\[\]|\s+OPTIONAL)?/x)
316 $argument_type = "$1";
318 $argument_type .= " $2";
322 $argument_type =~ s/\s*const\s*/ /;
323 $argument_type =~ s/^\s*(.*?)\s*$/$1/;
325 $argument_name =~ s/^\s*(.*?)\s*$/$1/;
327 die "$file: $.: syntax error: '$argument'\n";
329 $argument_types[$n] = $argument_type;
330 $argument_names[$n] = $argument_name;
331 # print " " . ($n + 1) . ": '" . $argument_types[$n] . "', '" . $argument_names[$n] . "'\n";
333 if($#argument_types == 0 && $argument_types[0] =~ /^void$/i) {
334 $#argument_types = -1;
335 $#argument_names = -1;
338 if($options->debug) {
339 print "$file: $return_type $calling_convention $name(" . join(",", @arguments) . ")\n";
342 &$function_begin($documentation_line, $documentation,
343 $function_line, $linkage, $return_type, $calling_convention, $name,
344 \@argument_types,\@argument_names,\@argument_documentations);
348 } elsif(/__ASM_GLOBAL_FUNC\(\s*(.*?)\s*,/s) {
351 &$function_begin($documentation_line, $documentation,
352 $function_line, "", "void", "__asm", $1, \@arguments);
354 } elsif(/DC_(GET_X_Y|GET_VAL_16)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
356 my @arguments = ("HDC16");
357 &$function_begin($documentation_line, $documentation,
358 $function_line, "", $2, "WINAPI", $3, \@arguments);
360 } elsif(/DC_(GET_VAL)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,.*?\)/s) {
362 my $return16 = $3 . "16";
364 my $name16 = $2 . "16";
366 my @arguments16 = ("HDC16");
367 my @arguments32 = ("HDC");
369 if($name16 eq "COLORREF16") { $name16 = "COLORREF"; }
371 &$function_begin($documentation_line, $documentation,
372 $function_line, "", $name16, "WINAPI", $return16, \@arguments16);
374 &$function_begin($documentation_line, $documentation,
375 $function_line, "", $name32, "WINAPI", $return32, \@arguments32);
377 } elsif(/DC_(GET_VAL_EX)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
379 my @arguments16 = ("HDC16", "LP" . $5 . "16");
380 my @arguments32 = ("HDC", "LP" . $5);
381 &$function_begin($documentation_line, $documentation,
382 $function_line, "", "BOOL16", "WINAPI", $2 . "16", \@arguments16);
384 &$function_begin($documentation_line, $documentation,
385 $function_line, "", "BOOL", "WINAPI", $2, \@arguments32);
387 } elsif(/DC_(SET_MODE)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
389 my @arguments16 = ("HDC16", "INT16");
390 my @arguments32 = ("HDC", "INT");
391 &$function_begin($documentation_line, $documentation,
392 $function_line, "", "INT16", "WINAPI", $2 . "16", \@arguments16);
394 &$function_begin($documentation_line, $documentation,
395 $function_line, "", "INT", "WINAPI", $2, \@arguments32);
397 } elsif(/WAVEIN_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
399 my @arguments16 = ("HWAVEIN16");
400 my @arguments32 = ("HWAVEIN");
401 &$function_begin($documentation_line, $documentation,
402 $function_line, "", "UINT16", "WINAPI", "waveIn" . $1 . "16", \@arguments16);
404 &$function_begin($documentation_line, $documentation,
405 $function_line, "", "UINT", "WINAPI", "waveIn" . $1, \@arguments32);
407 } elsif(/WAVEOUT_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
409 my @arguments16 = ("HWAVEOUT16");
410 my @arguments32 = ("HWAVEOUT");
411 &$function_begin($documentation_line, $documentation,
412 $function_line, "", "UINT16", "WINAPI", "waveOut" . $1 . "16", \@arguments16);
414 &$function_begin($documentation_line, $documentation,
415 $function_line, "", "UINT", "WINAPI", "waveOut" . $1, \@arguments32);
417 } elsif(/WAVEOUT_SHORTCUT_(1|2)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
420 my @arguments16 = ("HWAVEOUT16", $4);
421 my @arguments32 = ("HWAVEOUT", $4);
422 &$function_begin($documentation_line, $documentation,
423 $function_line, "", "UINT16", "WINAPI", "waveOut" . $2 . "16", \@arguments16);
425 &$function_begin($documentation_line, $documentation,
426 $function_line, "", "UINT", "WINAPI", "waveOut" . $2, \@arguments32);
429 my @arguments16 = ("UINT16", $4);
430 my @arguments32 = ("UINT", $4);
431 &$function_begin($documentation_line, $documentation,
432 $function_line, "", "UINT16", "WINAPI", "waveOut". $2 . "16", \@arguments16);
434 &$function_begin($documentation_line, $documentation,
435 $function_line, "", "UINT", "WINAPI", "waveOut" . $2, \@arguments32);
438 } elsif(/DEFINE_REGS_ENTRYPOINT_\d+\(\s*(\S*)\s*,\s*([^\s,\)]*).*?\)/s) {
440 $regs_entrypoints{$2} = $1;
441 } elsif(/DEFAULT_DEBUG_CHANNEL\s*\((\S+)\)/s) {
443 unshift @$debug_channels, $1;
444 } elsif(/(DEFAULT|DECLARE)_DEBUG_CHANNEL\s*\((\S+)\)/s) {
446 push @$debug_channels, $1;
447 } elsif(/\'[^\']*\'/s) {
449 } elsif(/\"[^\"]*\"/s) {
453 } elsif(/extern\s+"C"\s+{/s) {
457 print "+1: $_\n" if $options->debug >= 2;
464 print STDERR "done\n" if $options->verbose;
465 $output->write("$file: not at toplevel at end of file\n") unless $level == 0;