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($documentation);
66 $function->documentation_line($documentation_line);
67 $function->linkage($linkage);
68 $function->return_type($return_type);
69 $function->calling_convention($calling_convention);
70 $function->internal_name($internal_name);
71 $function->argument_types([@$argument_types]);
72 $function->argument_names([@$argument_names]);
73 $function->argument_documentations([@$argument_documentations]);
74 $function->statements($statements);
76 &$function_found_callback($function);
80 my @comment_lines = ();
86 my $lookahead_count = 0;
88 print STDERR "Processing file '$file' ... " if $options->verbose;
89 open(IN, "< $file") || die "<internal>: $file: $!\n";
91 while($again || defined(my $line = <IN>)) {
101 $lookahead_count = 0;
103 print " $level($lookahead_count): $line\n" if $options->debug >= 2;
104 print "*** $_\n" if $options->debug >= 3;
106 $lookahead_count = 0;
110 # CVS merge conflicts in file?
111 if(/^(<<<<<<<|=======|>>>>>>>)/) {
112 $output->write("$file: merge conflicts in file\n");
117 if(s/^(.*?)(\/\*.*?\*\/)(.*)$/$1 $3/s) {
118 push @comment_lines, $.;
128 # remove C++ comments
129 while(s/^(.*?)\/\/.*?$/$1\n/s) { $again = 1 }
133 if(/^\s*$/) { next; }
135 # remove preprocessor directives
140 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
142 &$preprocessor_found_callback($1, $3);
144 &$preprocessor_found_callback($1, "");
151 if(s/^\s*extern\s+"C"\s+\{//m) {
157 my $documentation_line;
159 my @argument_documentations = ();
162 while($n >= 0 && ($comments[$n] !~ /^\/\*\*/ ||
163 $comments[$n] =~ /^\/\*\*+\/$/))
168 if(defined($comments[$n]) && $n >= 0) {
169 my @lines = split(/\n/, $comments[$n]);
171 $documentation_line = $comment_lines[$n] - scalar(@lines) + 1;
172 $documentation = $comments[$n];
174 for(my $m=$n+1; $m <= $#comments; $m++) {
175 if($comments[$m] =~ /^\/\*\*+\/$/ ||
176 $comments[$m] =~ /^\/\*\s*(?:\!)?defined/) # FIXME: Kludge
178 @argument_documentations = ();
181 push @argument_documentations, $comments[$m];
192 s/^([^\{\}\'\"]*)//s;
196 while(/^./ && !s/^\'//) {
213 while(/^./ && !s/^\"//) {
234 print "+1: \{$_\n" if $options->debug >= 2;
238 $line .= "}" if $level > 1;
239 print "-1: \}$_\n" if $options->debug >= 2;
241 if($level == -1 && $extern_c) {
247 if(!defined($statements)) {
251 if($line !~ /^\s*$/) {
252 $statements .= "$line\n";
255 if($internal_name && $level == 0) {
259 } elsif(/(extern\s+|static\s+)?((struct\s+|union\s+|enum\s+)?\w+((\s*\*)+\s*|\s+))
260 ((__cdecl|__stdcall|CDECL|VFWAPIV|VFWAPI|WINAPIV|WINAPI|CALLBACK)\s+)?
261 (\w+(\(\w+\))?)\s*\(([^\)]*)\)\s*(\{|\;)/sx)
263 my @lines = split(/\n/, $&);
264 my $function_line = $. - scalar(@lines) + 1;
273 my $return_type = $2;
274 my $calling_convention = $7;
278 if(!defined($linkage)) {
282 if(!defined($calling_convention)) {
283 $calling_convention = "";
286 $linkage =~ s/\s*$//;
288 $return_type =~ s/\s*$//;
289 $return_type =~ s/\s*\*\s*/*/g;
290 $return_type =~ s/(\*+)/ $1/g;
292 if($regs_entrypoints{$name}) {
293 $name = $regs_entrypoints{$name};
296 $arguments =~ y/\t\n/ /;
297 $arguments =~ s/^\s*(.*?)\s*$/$1/;
298 if($arguments eq "") { $arguments = "..." }
302 my @arguments = split(/,/, $arguments);
303 foreach my $n (0..$#arguments) {
304 my $argument_type = "";
305 my $argument_name = "";
306 my $argument = $arguments[$n];
307 $argument =~ s/^\s*(.*?)\s*$/$1/;
308 # print " " . ($n + 1) . ": '$argument'\n";
309 $argument =~ s/^(IN OUT(?=\s)|IN(?=\s)|OUT(?=\s)|\s*)\s*//;
310 $argument =~ s/^(const(?=\s)|CONST(?=\s)|\s*)\s*//;
311 if($argument =~ /^\.\.\.$/) {
312 $argument_type = "...";
313 $argument_name = "...";
314 } elsif($argument =~ /^
315 ((?:struct\s+|union\s+|enum\s+|(?:signed\s+|unsigned\s+)
316 (?:short\s+(?=int)|long\s+(?=int))?)?\w+)\s*
317 ((?:const)?\s*(?:\*\s*?)*)\s*
318 (?:WINE_UNUSED\s+)?(\w*)\s*(?:\[\]|\s+OPTIONAL)?/x)
320 $argument_type = "$1";
322 $argument_type .= " $2";
326 $argument_type =~ s/\s*const\s*/ /;
327 $argument_type =~ s/^\s*(.*?)\s*$/$1/;
329 $argument_name =~ s/^\s*(.*?)\s*$/$1/;
331 die "$file: $.: syntax error: '$argument'\n";
333 $argument_types[$n] = $argument_type;
334 $argument_names[$n] = $argument_name;
335 # print " " . ($n + 1) . ": '" . $argument_types[$n] . "', '" . $argument_names[$n] . "'\n";
337 if($#argument_types == 0 && $argument_types[0] =~ /^void$/i) {
338 $#argument_types = -1;
339 $#argument_names = -1;
342 if($options->debug) {
343 print "$file: $return_type $calling_convention $name(" . join(",", @arguments) . ")\n";
346 &$function_begin($documentation_line, $documentation,
347 $function_line, $linkage, $return_type, $calling_convention, $name,
348 \@argument_types,\@argument_names,\@argument_documentations);
352 } elsif(/__ASM_GLOBAL_FUNC\(\s*(.*?)\s*,/s) {
355 &$function_begin($documentation_line, $documentation,
356 $function_line, "", "void", "__asm", $1, \@arguments);
358 } elsif(/DC_(GET_X_Y|GET_VAL_16)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
360 my @arguments = ("HDC16");
361 &$function_begin($documentation_line, $documentation,
362 $function_line, "", $2, "WINAPI", $3, \@arguments);
364 } elsif(/DC_(GET_VAL)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,.*?\)/s) {
366 my $return16 = $3 . "16";
368 my $name16 = $2 . "16";
370 my @arguments16 = ("HDC16");
371 my @arguments32 = ("HDC");
373 if($name16 eq "COLORREF16") { $name16 = "COLORREF"; }
375 &$function_begin($documentation_line, $documentation,
376 $function_line, "", $name16, "WINAPI", $return16, \@arguments16);
378 &$function_begin($documentation_line, $documentation,
379 $function_line, "", $name32, "WINAPI", $return32, \@arguments32);
381 } elsif(/DC_(GET_VAL_EX)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
383 my @arguments16 = ("HDC16", "LP" . $5 . "16");
384 my @arguments32 = ("HDC", "LP" . $5);
385 &$function_begin($documentation_line, $documentation,
386 $function_line, "", "BOOL16", "WINAPI", $2 . "16", \@arguments16);
388 &$function_begin($documentation_line, $documentation,
389 $function_line, "", "BOOL", "WINAPI", $2, \@arguments32);
391 } elsif(/DC_(SET_MODE)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
393 my @arguments16 = ("HDC16", "INT16");
394 my @arguments32 = ("HDC", "INT");
395 &$function_begin($documentation_line, $documentation,
396 $function_line, "", "INT16", "WINAPI", $2 . "16", \@arguments16);
398 &$function_begin($documentation_line, $documentation,
399 $function_line, "", "INT", "WINAPI", $2, \@arguments32);
401 } elsif(/WAVEIN_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
403 my @arguments16 = ("HWAVEIN16");
404 my @arguments32 = ("HWAVEIN");
405 &$function_begin($documentation_line, $documentation,
406 $function_line, "", "UINT16", "WINAPI", "waveIn" . $1 . "16", \@arguments16);
408 &$function_begin($documentation_line, $documentation,
409 $function_line, "", "UINT", "WINAPI", "waveIn" . $1, \@arguments32);
411 } elsif(/WAVEOUT_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
413 my @arguments16 = ("HWAVEOUT16");
414 my @arguments32 = ("HWAVEOUT");
415 &$function_begin($documentation_line, $documentation,
416 $function_line, "", "UINT16", "WINAPI", "waveOut" . $1 . "16", \@arguments16);
418 &$function_begin($documentation_line, $documentation,
419 $function_line, "", "UINT", "WINAPI", "waveOut" . $1, \@arguments32);
421 } elsif(/WAVEOUT_SHORTCUT_(1|2)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
424 my @arguments16 = ("HWAVEOUT16", $4);
425 my @arguments32 = ("HWAVEOUT", $4);
426 &$function_begin($documentation_line, $documentation,
427 $function_line, "", "UINT16", "WINAPI", "waveOut" . $2 . "16", \@arguments16);
429 &$function_begin($documentation_line, $documentation,
430 $function_line, "", "UINT", "WINAPI", "waveOut" . $2, \@arguments32);
433 my @arguments16 = ("UINT16", $4);
434 my @arguments32 = ("UINT", $4);
435 &$function_begin($documentation_line, $documentation,
436 $function_line, "", "UINT16", "WINAPI", "waveOut". $2 . "16", \@arguments16);
438 &$function_begin($documentation_line, $documentation,
439 $function_line, "", "UINT", "WINAPI", "waveOut" . $2, \@arguments32);
442 } elsif(/DEFINE_REGS_ENTRYPOINT_\d+\(\s*(\S*)\s*,\s*([^\s,\)]*).*?\)/s) {
444 $regs_entrypoints{$2} = $1;
445 } elsif(/DEFAULT_DEBUG_CHANNEL\s*\((\S+)\)/s) {
447 unshift @$debug_channels, $1;
448 } elsif(/(DEFAULT|DECLARE)_DEBUG_CHANNEL\s*\((\S+)\)/s) {
450 push @$debug_channels, $1;
451 } elsif(/\'[^\']*\'/s) {
453 } elsif(/\"[^\"]*\"/s) {
457 } elsif(/extern\s+"C"\s+{/s) {
461 print "+1: $_\n" if $options->debug >= 2;
468 print STDERR "done\n" if $options->verbose;
469 $output->write("$file: not at toplevel at end of file\n") unless $level == 0;