9 my $function_found_callback = shift;
10 my $preprocessor_found_callback = shift;
15 my $calling_convention;
19 my $argument_documentations;
22 my $function_begin = sub {
23 $documentation = shift;
26 $calling_convention = shift;
28 $argument_types = shift;
29 $argument_names = shift;
30 $argument_documentations = shift;
32 if($#$argument_names == -1) {
33 foreach my $n (0..$#$argument_types) {
34 push @
$argument_names, "";
38 if($#$argument_documentations == -1) {
39 foreach my $n (0..$#$argument_documentations) {
40 push @
$argument_documentations, "";
46 my $function_end = sub {
47 &$function_found_callback($documentation,$linkage,$return_type,
48 $calling_convention,$function,$argument_types,
49 $argument_names,$argument_documentations,$statements);
59 my $lookahead_count = 0;
61 print STDERR
"Processing file '$file' ... " if $options->verbose;
62 open(IN
, "< $file") || die "<internal>: $file: $!\n";
64 while($again || defined(my $line = <IN
>)) {
76 print " $level($lookahead_count): $line\n" if $options->debug >= 2;
77 print "*** $_\n" if $options->debug >= 3;
83 # Merge conflicts in file?
84 if(/^(<<<<<<<|=======|>>>>>>>)/) {
85 $output->write("$file: merge conflicts in file\n");
90 if(s/^(.*?)(\/\*.*?\*\/)(.*)$/$1 $3/s) { push @comments, $2; $again = 1; next }
97 while(s/^(.*?)\/\/.*?
$/$1\n/s) { $again = 1 }
101 if(/^\s*$/) { next; }
103 # remove preprocessor directives
108 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
110 &$preprocessor_found_callback($1, $3);
112 &$preprocessor_found_callback($1, "");
119 if(s/^\s*extern\s+"C"\s+\{//m) {
126 my @argument_documentations = ();
129 while($n >= 0 && ($comments[$n] !~ /^\/\
*\
*/ ||
130 $comments[$n] =~ /^\/\
*\
*+\
/$/))
135 if(defined($comments[$n]) && $n >= 0) {
136 $documentation = $comments[$n];
137 for(my $m=$n+1; $m <= $#comments; $m++) {
138 if($comments[$m] =~ /^\/\
*\
*+\
/$/ ||
139 $comments[$m] =~ /^\/\
*\s
*(?
:\
!)?
defined/) # FIXME: Kludge
141 @argument_documentations = ();
144 push @argument_documentations, $comments[$m];
155 s/^([^\{\}\'\"]*)//s;
159 while(/^./ && !s/^\'//) {
176 while(/^./ && !s/^\"//) {
197 print "+1: \{$_\n" if $options->debug >= 2;
201 $line .= "}" if $level > 1;
202 print "-1: \}$_\n" if $options->debug >= 2;
204 if($level == -1 && $extern_c) {
210 if($line !~ /^\s*$/) {
211 $statements .= "$line\n";
214 if($function && $level == 0) {
218 } elsif(/(extern\s
+|static\s
+)?
((struct\s
+|union\s
+|enum\s
+)?\w
+((\s
*\
*)+\s
*|\s
+))
219 ((__cdecl
|__stdcall
|CDECL
|VFWAPIV
|VFWAPI
|WINAPIV
|WINAPI
|CALLBACK
)\s
+)?
220 (\w
+(\
(\w
+\
))?
)\s
*\
(([^\
)]*)\
)\s
*(\
{|\
;)/sx
)
229 my $return_type = $2;
230 my $calling_convention = $7;
234 if(!defined($linkage)) {
238 if(!defined($calling_convention)) {
239 $calling_convention = "";
242 $linkage =~ s/\s*$//;
244 $return_type =~ s/\s*$//;
245 $return_type =~ s/\s*\*\s*/*/g;
246 $return_type =~ s/(\*+)/ $1/g;
248 if($regs_entrypoints{$name}) {
249 $name = $regs_entrypoints{$name};
252 $arguments =~ y/\t\n/ /;
253 $arguments =~ s/^\s*(.*?)\s*$/$1/;
254 if($arguments eq "") { $arguments = "void" }
258 my @arguments = split(/,/, $arguments);
259 foreach my $n (0..$#arguments) {
260 my $argument_type = "";
261 my $argument_name = "";
262 my $argument = $arguments[$n];
263 $argument =~ s/^\s*(.*?)\s*$/$1/;
264 # print " " . ($n + 1) . ": '$argument'\n";
265 $argument =~ s/^(IN OUT(?=\s)|IN(?=\s)|OUT(?=\s)|\s*)\s*//;
266 $argument =~ s/^(const(?=\s)|CONST(?=\s)|\s*)\s*//;
267 if($argument =~ /^\.\.\.$/) {
268 $argument_type = "...";
269 $argument_name = "...";
270 } elsif($argument =~ /^
271 ((?:struct\s+|union\s+|enum\s+|(?:signed\s+|unsigned\s+)
272 (?:short\s+(?=int)|long\s+(?=int))?)?\w+)\s*
273 ((?:const)?\s*(?:\*\s*?)*)\s*
274 (?:WINE_UNUSED\s+)?(\w*)\s*(?:\[\]|\s+OPTIONAL)?/x)
276 $argument_type = "$1";
278 $argument_type .= " $2";
282 $argument_type =~ s/\s*const\s*/ /;
283 $argument_type =~ s/^\s*(.*?)\s*$/$1/;
285 $argument_name =~ s/^\s*(.*?)\s*$/$1/;
287 die "$file: $.: syntax error: '$argument'\n";
289 $argument_types[$n] = $argument_type;
290 $argument_names[$n] = $argument_name;
291 # print " " . ($n + 1) . ": '" . $argument_types[$n] . "', '" . $argument_names[$n] . "'\n";
293 if($#argument_types == 0 && $argument_types[0] =~ /^void$/i) {
294 $#argument_types = -1;
295 $#argument_names = -1;
298 if($options->debug) {
299 print "$file: $return_type $calling_convention $name(" . join(",", @arguments) . ")\n";
302 &$function_begin($documentation,$linkage,$return_type,$calling_convention,$name,\@argument_types,\@argument_names,\@argument_documentations);
306 } elsif(/__ASM_GLOBAL_FUNC\(\s*(.*?)\s*,/s) {
309 &$function_begin($documentation, "", "void", "__asm", $1, \
@arguments);
311 } elsif(/DC_(GET_X_Y|GET_VAL_16)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
313 my @arguments = ("HDC16");
314 &$function_begin($documentation, "", $2, "WINAPI", $3, \@arguments);
316 } elsif(/DC_(GET_VAL)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,.*?\)/s) {
318 my $return16 = $3 . "16";
320 my $name16 = $2 . "16";
322 my @arguments16 = ("HDC16");
323 my @arguments32 = ("HDC");
325 if($name16 eq "COLORREF16") { $name16 = "COLORREF"; }
327 &$function_begin($documentation, "", $name16, "WINAPI", $return16, \
@arguments16);
329 &$function_begin($documentation, "", $name32, "WINAPI", $return32, \
@arguments32);
331 } elsif(/DC_(GET_VAL_EX)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
333 my @arguments16 = ("HDC16", "LP" . $5 . "16");
334 my @arguments32 = ("HDC", "LP" . $5);
335 &$function_begin($documentation, "", "BOOL16", "WINAPI", $2 . "16", \@arguments16);
337 &$function_begin($documentation, "", "BOOL", "WINAPI", $2, \@arguments32);
339 } elsif(/DC_(SET_MODE)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
341 my @arguments16 = ("HDC16", "INT16");
342 my @arguments32 = ("HDC", "INT");
343 &$function_begin($documentation, "", "INT16", "WINAPI", $2 . "16", \
@arguments16);
345 &$function_begin($documentation, "", "INT", "WINAPI", $2, \
@arguments32);
347 } elsif(/WAVEIN_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
349 my @arguments16 = ("HWAVEIN16");
350 my @arguments32 = ("HWAVEIN");
351 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveIn" . $1 . "16", \@arguments16);
353 &$function_begin($documentation, "", "UINT", "WINAPI", "waveIn" . $1, \@arguments32);
355 } elsif(/WAVEOUT_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
357 my @arguments16 = ("HWAVEOUT16");
358 my @arguments32 = ("HWAVEOUT");
359 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut" . $1 . "16", \
@arguments16);
361 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $1, \
@arguments32);
363 } elsif(/WAVEOUT_SHORTCUT_(1|2)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
366 my @arguments16 = ("HWAVEOUT16", $4);
367 my @arguments32 = ("HWAVEOUT", $4);
368 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut" . $2 . "16", \@arguments16);
370 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $2, \@arguments32);
373 my @arguments16 = ("UINT16", $4);
374 my @arguments32 = ("UINT", $4);
375 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut". $2 . "16", \@arguments16);
377 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $2, \@arguments32);
380 } elsif(/DEFINE_REGS_ENTRYPOINT_\d+\(\s*(\S*)\s*,\s*([^\s,\)]*).*?\)/s) {
382 $regs_entrypoints{$2} = $1;
383 } elsif(/\'[^\']*\'/s) {
385 } elsif(/\"[^\"]*\"/s) {
389 } elsif(/extern\s+"C"\s+{/s) {
393 print "+1: $_\n" if $options->debug >= 2;
400 print STDERR "done\n" if $options->verbose;
401 $output->write("$file: not at toplevel at end of file\n") unless $level == 0;