9 my $function_found_callback = shift;
10 my $preprocessor_found_callback = shift;
15 my $calling_convention;
20 my $function_begin = sub {
21 $documentation = shift;
24 $calling_convention = shift;
30 my $function_end = sub {
31 &$function_found_callback($documentation,$linkage,$return_type,$calling_convention,$function,$arguments,$statements);
42 my $lookahead_count = 0;
44 print STDERR
"Processing file '$file' ... " if $options->verbose;
45 open(IN
, "< $file") || die "<internal>: $file: $!\n";
47 while($again || defined(my $line = <IN
>)) {
59 print " $level($lookahead_count): $line\n" if $options->debug >= 2;
60 print "*** $_\n" if $options->debug >= 3;
66 # Merge conflicts in file?
67 if(/^(<<<<<<<|=======|>>>>>>>)/) {
68 $output->write("$file: merge conflicts in file\n");
73 if(s/^(.*?)(\/\*.*?\*\/)(.*)$/$1 $3/s) { push @comments, $2; $again = 1; next };
82 # remove preprocessor directives
87 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
89 &$preprocessor_found_callback($1, $3);
91 &$preprocessor_found_callback($1, "");
98 if(s/^\s*extern\s+"C"\s+\{//m) {
107 while($n >= 0 && ($comments[$n] !~ /^\/\
*\
*/ || $comments[$n] =~ /^\
/\*\*+\//)) { $n-- }
108 if(defined($comments[$n]) && $n >= 0) {
109 $documentation = $comments[$n];
119 s/^([^\{\}\'\"]*)//s;
123 while(/^./ && !s/^\'//) {
140 while(/^./ && !s/^\"//) {
161 print "+1: \{$_\n" if $options->debug >= 2;
165 $line .= "}" if $level > 1;
166 print "-1: \}$_\n" if $options->debug >= 2;
168 if($level == -1 && $extern_c) {
174 if($line !~ /^\s*$/) {
175 $statements .= "$line\n";
178 if($function && $level == 0) {
182 } elsif(/(extern\s+|static\s+)?((struct\s+|union\s+|enum\s+)?\w+((\s*\*)+\s*|\s+))((__cdecl|__stdcall|VFWAPIV|VFWAPI|WINAPIV|WINAPI)\s+)?(\w+(\(\w+\))?)\s*\(([^\)]*)\)\s*(\{|\;)/s) {
190 my $return_type = $2;
191 my $calling_convention = $7;
195 if(!defined($linkage)) {
199 if(!defined($calling_convention)) {
200 $calling_convention = "";
203 $linkage =~ s/\s*$//;
205 $return_type =~ s/\s*$//;
206 $return_type =~ s/\s*\*\s*/*/g;
207 $return_type =~ s/(\*+)/ $1/g;
209 if($regs_entrypoints{$name}) {
210 $name = $regs_entrypoints{$name};
213 $arguments =~ y/\t\n/ /;
214 $arguments =~ s/^\s*(.*?)\s*$/$1/;
215 if($arguments eq "") { $arguments = "void" }
217 my @arguments = split(/,/, $arguments);
218 foreach my $n (0..$#arguments) {
219 my $argument = $arguments[$n];
220 $argument =~ s/^\s*(.*?)\s*$/$1/;
221 #print " " . ($n + 1) . ": '$argument'\n";
222 $argument =~ s/^(IN OUT(?=\s)|IN(?=\s)|OUT(?=\s)|\s*)\s*//;
223 $argument =~ s/^(const(?=\s)|CONST(?=\s)|\s*)\s*//;
224 if($argument =~ /^...$/) {
226 } elsif($argument =~ /^((struct\s+|union\s+|enum\s+)?\w+)\s*((\*\s*?)*)\s*/) {
232 die "$file: $.: syntax error: '$argument'\n";
234 $arguments[$n] = $argument;
235 #print " " . ($n + 1) . ": '" . $arguments[$n] . "'\n";
237 if($#arguments == 0 && $arguments[0] =~ /^void$/i) { $#arguments = -1; }
239 if($options->debug) {
240 print "$file: $return_type $calling_convention $name(" . join(",", @arguments) . ")\n";
243 &$function_begin($documentation,$linkage,$return_type,$calling_convention,$name,\@arguments);
247 } elsif(/DC_(GET_X_Y|GET_VAL_16)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
249 my @arguments = ("HDC16");
250 &$function_begin($documentation, "", $2, "WINAPI", $3, \
@arguments);
252 } elsif(/DC_(GET_VAL_32)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,.*?\)/s) {
254 my @arguments = ("HDC");
255 &$function_begin($documentation, "", $2, "WINAPI", $3, \@arguments);
257 } elsif(/DC_(GET_VAL_EX)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
259 my @arguments16 = ("HDC16", "LP" . $5 . "16");
260 my @arguments32 = ("HDC", "LP" . $5);
261 &$function_begin($documentation, "", "BOOL16", "WINAPI", $2 . "16", \
@arguments16);
263 &$function_begin($documentation, "", "BOOL", "WINAPI", $2, \
@arguments32);
265 } elsif(/DC_(SET_MODE)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
267 my @arguments16 = ("HDC16", "INT16");
268 my @arguments32 = ("HDC", "INT");
269 &$function_begin($documentation, "", "INT16", "WINAPI", $2 . "16", \@arguments16);
271 &$function_begin($documentation, "", "INT", "WINAPI", $2, \@arguments32);
273 } elsif(/WAVEIN_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
275 my @arguments16 = ("HWAVEIN16");
276 my @arguments32 = ("HWAVEIN");
277 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveIn" . $1 . "16", \
@arguments16);
279 &$function_begin($documentation, "", "UINT", "WINAPI", "waveIn" . $1, \
@arguments32);
281 } elsif(/WAVEOUT_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
283 my @arguments16 = ("HWAVEOUT16");
284 my @arguments32 = ("HWAVEOUT");
285 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut" . $1 . "16", \@arguments16);
287 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $1, \@arguments32);
289 } elsif(/WAVEOUT_SHORTCUT_(1|2)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
292 my @arguments16 = ("HWAVEOUT16", $4);
293 my @arguments32 = ("HWAVEOUT", $4);
294 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut" . $2 . "16", \
@arguments16);
296 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $2, \
@arguments32);
299 my @arguments16 = ("UINT16", $4);
300 my @arguments32 = ("UINT", $4);
301 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut". $2 . "16", \
@arguments16);
303 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $2, \
@arguments32);
306 } elsif(/DEFINE_REGS_ENTRYPOINT_\d+\(\s*(\S*)\s*,\s*([^\s,\)]*).*?\)/s) {
308 $regs_entrypoints{$2} = $1;
309 } elsif(/\'[^\']*\'/s) {
311 } elsif(/\"[^\"]*\"/s) {
315 } elsif(/extern\s+"C"\s+{/s) {
319 print "+1: $_\n" if $options->debug >= 2;
326 print STDERR
"done\n" if $options->verbose;
327 $output->write("$file: not at toplevel at end of file\n") unless $level == 0;