9 my $function_found_callback = shift;
10 my $preprocessor_found_callback = shift;
13 my $debug_channels = [];
20 my $calling_convention;
24 my $argument_documentations;
27 my $function_begin = sub {
28 $documentation = shift;
31 $calling_convention = shift;
33 $argument_types = shift;
34 $argument_names = shift;
35 $argument_documentations = shift;
37 if($#$argument_names == -1) {
38 foreach my $n (0..$#$argument_types) {
39 push @
$argument_names, "";
43 if($#$argument_documentations == -1) {
44 foreach my $n (0..$#$argument_documentations) {
45 push @
$argument_documentations, "";
51 my $function_end = sub {
52 &$function_found_callback($line_number,$debug_channels,$documentation,$linkage,$return_type,
53 $calling_convention,$function,$argument_types,
54 $argument_names,$argument_documentations,$statements);
63 my $lookahead_count = 0;
65 print STDERR
"Processing file '$file' ... " if $options->verbose;
66 open(IN
, "< $file") || die "<internal>: $file: $!\n";
68 while($again || defined(my $line = <IN
>)) {
80 print " $level($lookahead_count): $line\n" if $options->debug >= 2;
81 print "*** $_\n" if $options->debug >= 3;
87 # Merge conflicts in file?
88 if(/^(<<<<<<<|=======|>>>>>>>)/) {
89 $output->write("$file: merge conflicts in file\n");
94 if(s/^(.*?)(\/\*.*?\*\/)(.*)$/$1 $3/s) { push @comments, $2; $again = 1; next }
100 # remove C++ comments
101 while(s/^(.*?)\/\/.*?
$/$1\n/s) { $again = 1 }
105 if(/^\s*$/) { next; }
107 # remove preprocessor directives
112 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
114 &$preprocessor_found_callback($1, $3);
116 &$preprocessor_found_callback($1, "");
123 if(s/^\s*extern\s+"C"\s+\{//m) {
130 my @argument_documentations = ();
133 while($n >= 0 && ($comments[$n] !~ /^\/\
*\
*/ ||
134 $comments[$n] =~ /^\/\
*\
*+\
/$/))
139 if(defined($comments[$n]) && $n >= 0) {
140 $documentation = $comments[$n];
141 for(my $m=$n+1; $m <= $#comments; $m++) {
142 if($comments[$m] =~ /^\/\
*\
*+\
/$/ ||
143 $comments[$m] =~ /^\/\
*\s
*(?
:\
!)?
defined/) # FIXME: Kludge
145 @argument_documentations = ();
148 push @argument_documentations, $comments[$m];
159 s/^([^\{\}\'\"]*)//s;
163 while(/^./ && !s/^\'//) {
180 while(/^./ && !s/^\"//) {
201 print "+1: \{$_\n" if $options->debug >= 2;
205 $line .= "}" if $level > 1;
206 print "-1: \}$_\n" if $options->debug >= 2;
208 if($level == -1 && $extern_c) {
214 if($line !~ /^\s*$/) {
215 $statements .= "$line\n";
218 if($function && $level == 0) {
222 } elsif(/(extern\s
+|static\s
+)?
((struct\s
+|union\s
+|enum\s
+)?\w
+((\s
*\
*)+\s
*|\s
+))
223 ((__cdecl
|__stdcall
|CDECL
|VFWAPIV
|VFWAPI
|WINAPIV
|WINAPI
|CALLBACK
)\s
+)?
224 (\w
+(\
(\w
+\
))?
)\s
*\
(([^\
)]*)\
)\s
*(\
{|\
;)/sx
)
226 $line_number = $. - $lookahead_count;
235 my $return_type = $2;
236 my $calling_convention = $7;
240 if(!defined($linkage)) {
244 if(!defined($calling_convention)) {
245 $calling_convention = "";
248 $linkage =~ s/\s*$//;
250 $return_type =~ s/\s*$//;
251 $return_type =~ s/\s*\*\s*/*/g;
252 $return_type =~ s/(\*+)/ $1/g;
254 if($regs_entrypoints{$name}) {
255 $name = $regs_entrypoints{$name};
258 $arguments =~ y/\t\n/ /;
259 $arguments =~ s/^\s*(.*?)\s*$/$1/;
260 if($arguments eq "") { $arguments = "void" }
264 my @arguments = split(/,/, $arguments);
265 foreach my $n (0..$#arguments) {
266 my $argument_type = "";
267 my $argument_name = "";
268 my $argument = $arguments[$n];
269 $argument =~ s/^\s*(.*?)\s*$/$1/;
270 # print " " . ($n + 1) . ": '$argument'\n";
271 $argument =~ s/^(IN OUT(?=\s)|IN(?=\s)|OUT(?=\s)|\s*)\s*//;
272 $argument =~ s/^(const(?=\s)|CONST(?=\s)|\s*)\s*//;
273 if($argument =~ /^\.\.\.$/) {
274 $argument_type = "...";
275 $argument_name = "...";
276 } elsif($argument =~ /^
277 ((?:struct\s+|union\s+|enum\s+|(?:signed\s+|unsigned\s+)
278 (?:short\s+(?=int)|long\s+(?=int))?)?\w+)\s*
279 ((?:const)?\s*(?:\*\s*?)*)\s*
280 (?:WINE_UNUSED\s+)?(\w*)\s*(?:\[\]|\s+OPTIONAL)?/x)
282 $argument_type = "$1";
284 $argument_type .= " $2";
288 $argument_type =~ s/\s*const\s*/ /;
289 $argument_type =~ s/^\s*(.*?)\s*$/$1/;
291 $argument_name =~ s/^\s*(.*?)\s*$/$1/;
293 die "$file: $.: syntax error: '$argument'\n";
295 $argument_types[$n] = $argument_type;
296 $argument_names[$n] = $argument_name;
297 # print " " . ($n + 1) . ": '" . $argument_types[$n] . "', '" . $argument_names[$n] . "'\n";
299 if($#argument_types == 0 && $argument_types[0] =~ /^void$/i) {
300 $#argument_types = -1;
301 $#argument_names = -1;
304 if($options->debug) {
305 print "$file: $return_type $calling_convention $name(" . join(",", @arguments) . ")\n";
308 &$function_begin($documentation,$linkage,$return_type,$calling_convention,$name,\@argument_types,\@argument_names,\@argument_documentations);
312 } elsif(/__ASM_GLOBAL_FUNC\(\s*(.*?)\s*,/s) {
315 &$function_begin($documentation, "", "void", "__asm", $1, \
@arguments);
317 } elsif(/DC_(GET_X_Y|GET_VAL_16)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
319 my @arguments = ("HDC16");
320 &$function_begin($documentation, "", $2, "WINAPI", $3, \@arguments);
322 } elsif(/DC_(GET_VAL)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,.*?\)/s) {
324 my $return16 = $3 . "16";
326 my $name16 = $2 . "16";
328 my @arguments16 = ("HDC16");
329 my @arguments32 = ("HDC");
331 if($name16 eq "COLORREF16") { $name16 = "COLORREF"; }
333 &$function_begin($documentation, "", $name16, "WINAPI", $return16, \
@arguments16);
335 &$function_begin($documentation, "", $name32, "WINAPI", $return32, \
@arguments32);
337 } elsif(/DC_(GET_VAL_EX)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
339 my @arguments16 = ("HDC16", "LP" . $5 . "16");
340 my @arguments32 = ("HDC", "LP" . $5);
341 &$function_begin($documentation, "", "BOOL16", "WINAPI", $2 . "16", \@arguments16);
343 &$function_begin($documentation, "", "BOOL", "WINAPI", $2, \@arguments32);
345 } elsif(/DC_(SET_MODE)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
347 my @arguments16 = ("HDC16", "INT16");
348 my @arguments32 = ("HDC", "INT");
349 &$function_begin($documentation, "", "INT16", "WINAPI", $2 . "16", \
@arguments16);
351 &$function_begin($documentation, "", "INT", "WINAPI", $2, \
@arguments32);
353 } elsif(/WAVEIN_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
355 my @arguments16 = ("HWAVEIN16");
356 my @arguments32 = ("HWAVEIN");
357 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveIn" . $1 . "16", \@arguments16);
359 &$function_begin($documentation, "", "UINT", "WINAPI", "waveIn" . $1, \@arguments32);
361 } elsif(/WAVEOUT_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
363 my @arguments16 = ("HWAVEOUT16");
364 my @arguments32 = ("HWAVEOUT");
365 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut" . $1 . "16", \
@arguments16);
367 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $1, \
@arguments32);
369 } elsif(/WAVEOUT_SHORTCUT_(1|2)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
372 my @arguments16 = ("HWAVEOUT16", $4);
373 my @arguments32 = ("HWAVEOUT", $4);
374 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut" . $2 . "16", \@arguments16);
376 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $2, \@arguments32);
379 my @arguments16 = ("UINT16", $4);
380 my @arguments32 = ("UINT", $4);
381 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut". $2 . "16", \@arguments16);
383 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $2, \@arguments32);
386 } elsif(/DEFINE_REGS_ENTRYPOINT_\d+\(\s*(\S*)\s*,\s*([^\s,\)]*).*?\)/s) {
388 $regs_entrypoints{$2} = $1;
389 } elsif(/DEFAULT_DEBUG_CHANNEL\s*\((\S+)\)/s) {
391 unshift @$debug_channels, $1;
392 } elsif(/(DEFAULT|DECLARE)_DEBUG_CHANNEL\s*\((\S+)\)/s) {
394 push @
$debug_channels, $1;
395 } elsif(/\'[^\']*\'/s) {
397 } elsif(/\"[^\"]*\"/s) {
401 } elsif(/extern\s+"C"\s+{/s) {
405 print "+1: $_\n" if $options->debug >= 2;
412 print STDERR "done\n" if $options->verbose;
413 $output->write("$file: not at toplevel at end of file\n") unless $level == 0;