9 my $function_found_callback = shift;
10 my $preprocessor_found_callback = shift;
15 my $calling_convention;
21 my $function_begin = sub {
22 $documentation = shift;
25 $calling_convention = shift;
27 $argument_types = shift;
28 $argument_names = shift;
30 if($#$argument_names == -1) {
31 foreach my $n (0..$#$argument_types) {
32 push @$argument_names, "";
38 my $function_end = sub {
39 &$function_found_callback($documentation,$linkage,$return_type,$calling_convention,
40 $function,$argument_types,$argument_names,$statements);
50 my $lookahead_count = 0;
52 print STDERR "Processing file '$file' ... " if $options->verbose;
53 open(IN, "< $file") || die "<internal>: $file: $!\n";
55 while($again || defined(my $line = <IN>)) {
67 print " $level($lookahead_count): $line\n" if $options->debug >= 2;
68 print "*** $_\n" if $options->debug >= 3;
74 # Merge conflicts in file?
75 if(/^(<<<<<<<|=======|>>>>>>>)/) {
76 $output->write("$file: merge conflicts in file\n");
81 if(s/^(.*?)(\/\*.*?\*\/)(.*)$/$1 $3/s) { push @comments, $2; $again = 1; next };
90 # remove preprocessor directives
95 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
97 &$preprocessor_found_callback($1, $3);
99 &$preprocessor_found_callback($1, "");
106 if(s/^\s*extern\s+"C"\s+\{//m) {
115 while($n >= 0 && ($comments[$n] !~ /^\/\*\*/ || $comments[$n] =~ /^\/\*\*+\//)) { $n-- }
116 if(defined($comments[$n]) && $n >= 0) {
117 $documentation = $comments[$n];
127 s/^([^\{\}\'\"]*)//s;
131 while(/^./ && !s/^\'//) {
148 while(/^./ && !s/^\"//) {
169 print "+1: \{$_\n" if $options->debug >= 2;
173 $line .= "}" if $level > 1;
174 print "-1: \}$_\n" if $options->debug >= 2;
176 if($level == -1 && $extern_c) {
182 if($line !~ /^\s*$/) {
183 $statements .= "$line\n";
186 if($function && $level == 0) {
190 } elsif(/(extern\s+|static\s+)?((struct\s+|union\s+|enum\s+)?\w+((\s*\*)+\s*|\s+))((__cdecl|__stdcall|VFWAPIV|VFWAPI|WINAPIV|WINAPI|CALLBACK)\s+)?(\w+(\(\w+\))?)\s*\(([^\)]*)\)\s*(\{|\;)/s) {
198 my $return_type = $2;
199 my $calling_convention = $7;
203 if(!defined($linkage)) {
207 if(!defined($calling_convention)) {
208 $calling_convention = "";
211 $linkage =~ s/\s*$//;
213 $return_type =~ s/\s*$//;
214 $return_type =~ s/\s*\*\s*/*/g;
215 $return_type =~ s/(\*+)/ $1/g;
217 if($regs_entrypoints{$name}) {
218 $name = $regs_entrypoints{$name};
221 $arguments =~ y/\t\n/ /;
222 $arguments =~ s/^\s*(.*?)\s*$/$1/;
223 if($arguments eq "") { $arguments = "void" }
227 my @arguments = split(/,/, $arguments);
228 foreach my $n (0..$#arguments) {
229 my $argument_type = "";
230 my $argument_name = "";
231 my $argument = $arguments[$n];
232 $argument =~ s/^\s*(.*?)\s*$/$1/;
233 # print " " . ($n + 1) . ": '$argument'\n";
234 $argument =~ s/^(IN OUT(?=\s)|IN(?=\s)|OUT(?=\s)|\s*)\s*//;
235 $argument =~ s/^(const(?=\s)|CONST(?=\s)|\s*)\s*//;
236 if($argument =~ /^\.\.\.$/) {
237 $argument_type = "...";
238 $argument_name = "...";
239 } elsif($argument =~ /^((?:struct\s+|union\s+|enum\s+|(?:signed\s+|unsigned\s+)(?:short\s+(?=int)|long\s+(?=int))?)?\w+)\s*((?:const)?\s*(?:\*\s*?)*)\s*(?:WINE_UNUSED\s+)?(\w*)\s*(?:\[\]|\s+OPTIONAL)?/) {
240 $argument_type = "$1";
242 $argument_type .= " $2";
246 $argument_type =~ s/\s*const\s*/ /;
247 $argument_type =~ s/^\s*(.*?)\s*$/$1/;
249 $argument_name =~ s/^\s*(.*?)\s*$/$1/;
251 die "$file: $.: syntax error: '$argument'\n";
253 $argument_types[$n] = $argument_type;
254 $argument_names[$n] = $argument_name;
255 # print " " . ($n + 1) . ": '" . $argument_types[$n] . "', '" . $argument_names[$n] . "'\n";
257 if($#argument_types == 0 && $argument_types[0] =~ /^void$/i) {
258 $#argument_types = -1;
259 $#argument_names = -1;
262 if($options->debug) {
263 print "$file: $return_type $calling_convention $name(" . join(",", @arguments) . ")\n";
266 &$function_begin($documentation,$linkage,$return_type,$calling_convention,$name,\@argument_types,\@argument_names);
270 } elsif(/DC_(GET_X_Y|GET_VAL_16)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
272 my @arguments = ("HDC16");
273 &$function_begin($documentation, "", $2, "WINAPI", $3, \@arguments);
275 } elsif(/DC_(GET_VAL_32)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,.*?\)/s) {
277 my @arguments = ("HDC");
278 &$function_begin($documentation, "", $2, "WINAPI", $3, \@arguments);
280 } elsif(/DC_(GET_VAL_EX)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
282 my @arguments16 = ("HDC16", "LP" . $5 . "16");
283 my @arguments32 = ("HDC", "LP" . $5);
284 &$function_begin($documentation, "", "BOOL16", "WINAPI", $2 . "16", \@arguments16);
286 &$function_begin($documentation, "", "BOOL", "WINAPI", $2, \@arguments32);
288 } elsif(/DC_(SET_MODE)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
290 my @arguments16 = ("HDC16", "INT16");
291 my @arguments32 = ("HDC", "INT");
292 &$function_begin($documentation, "", "INT16", "WINAPI", $2 . "16", \@arguments16);
294 &$function_begin($documentation, "", "INT", "WINAPI", $2, \@arguments32);
296 } elsif(/WAVEIN_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
298 my @arguments16 = ("HWAVEIN16");
299 my @arguments32 = ("HWAVEIN");
300 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveIn" . $1 . "16", \@arguments16);
302 &$function_begin($documentation, "", "UINT", "WINAPI", "waveIn" . $1, \@arguments32);
304 } elsif(/WAVEOUT_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
306 my @arguments16 = ("HWAVEOUT16");
307 my @arguments32 = ("HWAVEOUT");
308 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut" . $1 . "16", \@arguments16);
310 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $1, \@arguments32);
312 } elsif(/WAVEOUT_SHORTCUT_(1|2)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
315 my @arguments16 = ("HWAVEOUT16", $4);
316 my @arguments32 = ("HWAVEOUT", $4);
317 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut" . $2 . "16", \@arguments16);
319 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $2, \@arguments32);
322 my @arguments16 = ("UINT16", $4);
323 my @arguments32 = ("UINT", $4);
324 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut". $2 . "16", \@arguments16);
326 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $2, \@arguments32);
329 } elsif(/DEFINE_REGS_ENTRYPOINT_\d+\(\s*(\S*)\s*,\s*([^\s,\)]*).*?\)/s) {
331 $regs_entrypoints{$2} = $1;
332 } elsif(/\'[^\']*\'/s) {
334 } elsif(/\"[^\"]*\"/s) {
338 } elsif(/extern\s+"C"\s+{/s) {
342 print "+1: $_\n" if $options->debug >= 2;
349 print STDERR "done\n" if $options->verbose;
350 $output->write("$file: not at toplevel at end of file\n") unless $level == 0;