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);
41 my $lookahead_count = 0;
43 print STDERR
"Processing file '$file' ... " if $options->verbose;
44 open(IN
, "< $file") || die "<internal>: $file: $!\n";
46 while($again || defined(my $line = <IN
>)) {
58 print " $level: $line\n" if $options->debug >= 2;
64 # Merge conflicts in file?
65 if(/^(<<<<<<<|=======|>>>>>>>)/) {
66 $output->write("$file: merge conflicts in file\n");
71 if(s/^(.*?)(\/\*.*?\*\/)(.*)$/$1 $3/s) { push @comments, $2; $again = 1; next };
80 # remove preprocessor directives
85 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
87 &$preprocessor_found_callback($1, $3);
89 &$preprocessor_found_callback($1, "");
99 while($n >= 0 && ($comments[$n] !~ /^\/\
*\
*/ || $comments[$n] =~ /^\
/\*\*+\//)) { $n-- }
100 if(defined($comments[$n]) && $n >= 0) {
101 $documentation = $comments[$n];
111 s/^([^\{\}\'\"]*)//s;
115 while(/^./ && !s/^\'//) {
132 while(/^./ && !s/^\"//) {
153 print "+1: \{$_\n" if $options->debug >= 2;
157 $line .= "}" if $level > 1;
158 print "-1: \}$_\n" if $options->debug >= 2;
162 if($line !~ /^\s*$/) {
163 $statements .= "$line\n";
166 if($function && $level == 0) {
170 } 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) {
178 my $return_type = $2;
179 my $calling_convention = $7;
183 if(!defined($linkage)) {
187 if(!defined($calling_convention)) {
188 $calling_convention = "";
191 $linkage =~ s/\s*$//;
193 $return_type =~ s/\s*$//;
194 $return_type =~ s/\s*\*\s*/*/g;
195 $return_type =~ s/(\*+)/ $1/g;
197 if($regs_entrypoints{$name}) {
198 $name = $regs_entrypoints{$name};
201 $arguments =~ y/\t\n/ /;
202 $arguments =~ s/^\s*(.*?)\s*$/$1/;
203 if($arguments eq "") { $arguments = "void" }
205 my @arguments = split(/,/, $arguments);
206 foreach my $n (0..$#arguments) {
207 my $argument = $arguments[$n];
208 $argument =~ s/^\s*(.*?)\s*$/$1/;
209 #print " " . ($n + 1) . ": '$argument'\n";
210 $argument =~ s/^(IN OUT(?=\s)|IN(?=\s)|OUT(?=\s)|\s*)\s*//;
211 $argument =~ s/^(const(?=\s)|CONST(?=\s)|\s*)\s*//;
212 if($argument =~ /^...$/) {
214 } elsif($argument =~ /^((struct\s+|union\s+|enum\s+)?\w+)\s*((\*\s*?)*)\s*/) {
220 die "$file: $.: syntax error: '$argument'\n";
222 $arguments[$n] = $argument;
223 #print " " . ($n + 1) . ": '" . $arguments[$n] . "'\n";
225 if($#arguments == 0 && $arguments[0] =~ /^void$/i) { $#arguments = -1; }
227 if($options->debug) {
228 print "$file: $return_type $calling_convention $name(" . join(",", @arguments) . ")\n";
231 &$function_begin($documentation,$linkage,$return_type,$calling_convention,$name,\@arguments);
235 } elsif(/DC_(GET_X_Y|GET_VAL_16)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
237 my @arguments = ("HDC16");
238 &$function_begin($documentation, "", $2, "WINAPI", $3, \
@arguments);
240 } elsif(/DC_(GET_VAL_32)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,.*?\)/s) {
242 my @arguments = ("HDC");
243 &$function_begin($documentation, "", $2, "WINAPI", $3, \@arguments);
245 } elsif(/DC_(GET_VAL_EX)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
247 my @arguments16 = ("HDC16", "LP" . $5 . "16");
248 my @arguments32 = ("HDC", "LP" . $5);
249 &$function_begin($documentation, "", "BOOL16", "WINAPI", $2 . "16", \
@arguments16);
251 &$function_begin($documentation, "", "BOOL", "WINAPI", $2, \
@arguments32);
253 } elsif(/DC_(SET_MODE)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
255 my @arguments16 = ("HDC16", "INT16");
256 my @arguments32 = ("HDC", "INT");
257 &$function_begin($documentation, "", "INT16", "WINAPI", $2 . "16", \@arguments16);
259 &$function_begin($documentation, "", "INT", "WINAPI", $2, \@arguments32);
261 } elsif(/WAVEIN_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
263 my @arguments16 = ("HWAVEIN16");
264 my @arguments32 = ("HWAVEIN");
265 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveIn" . $1 . "16", \
@arguments16);
267 &$function_begin($documentation, "", "UINT", "WINAPI", "waveIn" . $1, \
@arguments32);
269 } elsif(/WAVEOUT_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
271 my @arguments16 = ("HWAVEOUT16");
272 my @arguments32 = ("HWAVEOUT");
273 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut" . $1 . "16", \@arguments16);
275 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $1, \@arguments32);
277 } elsif(/WAVEOUT_SHORTCUT_(1|2)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
280 my @arguments16 = ("HWAVEOUT16", $4);
281 my @arguments32 = ("HWAVEOUT", $4);
282 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut" . $2 . "16", \
@arguments16);
284 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $2, \
@arguments32);
287 my @arguments16 = ("UINT16", $4);
288 my @arguments32 = ("UINT", $4);
289 &$function_begin($documentation, "", "UINT16", "WINAPI", "waveOut". $2 . "16", \
@arguments16);
291 &$function_begin($documentation, "", "UINT", "WINAPI", "waveOut" . $2, \
@arguments32);
294 } elsif(/DEFINE_REGS_ENTRYPOINT_\d+\(\s*(\S*)\s*,\s*([^\s,\)]*).*?\)/s) {
296 $regs_entrypoints{$2} = $1;
297 } elsif(/\'[^\']*\'/s) {
299 } elsif(/\"[^\"]*\"/s) {
305 print "+1: $_\n" if $options->debug >= 2;
312 print STDERR "done\n" if $options->verbose;
313 $output->write("$file: not at toplevel at end of file\n") unless $level == 0;