9 my $function_found_callback = shift;
10 my $preprocessor_found_callback = shift;
14 my $calling_convention;
19 my $function_begin = sub {
20 $documentation = shift;
22 $calling_convention = shift;
28 my $function_end = sub {
29 &$function_found_callback($documentation,$return_type,$calling_convention,$function,$arguments,$statements);
38 my $lookahead_count = 0;
40 print STDERR "Processing file '$file' ... " if $options->verbose;
41 open(IN, "< $file") || die "<internal>: $file: $!\n";
43 while($again || defined(my $line = <IN>)) {
55 print "$level: $line\n" if $options->debug >= 2;
61 # Merge conflicts in file?
62 if(/^(<<<<<<<|=======|>>>>>>>)/) {
63 $output->write("$file: merge conflicts in file\n");
68 if(s/^(.*?)(\/\*.*?\*\/)(.*)$/$1 $3/s) { push @comments, $2; $again = 1; next };
77 # remove preprocessor directives
82 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
84 &$preprocessor_found_callback($1, $3);
86 &$preprocessor_found_callback($1, "");
96 while($n >= 0 && $comments[$n] !~ /\/\*\*/) { $n-- }
97 if(defined($comments[$n]) && $n >= 0) {
98 $documentation = $comments[$n];
112 print "+1: $_\n" if $options->debug >= 2;
116 $line .= $1 if $level > 1;
117 print "-1: $_\n" if $options->debug >= 2;
120 if($line !~ /^\s*$/) {
121 $statements .= "$line\n";
123 if($function && $level == 0) {
127 } elsif(/((struct\s+|union\s+|enum\s+)?\w+((\s*\*)+\s*|\s+))((__cdecl|__stdcall|VFWAPIV|VFWAPI|WINAPIV|WINAPI)\s+)?(\w+(\(\w+\))?)\s*\(([^\)]*)\)\s*(\{|\;)/s) {
132 } elsif($10 eq "{") {
136 my $return_type = $1;
137 my $calling_convention = $6;
141 if(!defined($calling_convention)) {
142 $calling_convention = "";
145 $return_type =~ s/\s*$//;
146 $return_type =~ s/\s*\*\s*/*/g;
147 $return_type =~ s/(\*+)/ $1/g;
149 $name =~ s/^REGS_FUNC\((.*?)\)/$1/;
151 $arguments =~ y/\t\n/ /;
152 $arguments =~ s/^\s*(.*?)\s*$/$1/;
153 if($arguments eq "") { $arguments = "void" }
155 my @arguments = split(/,/, $arguments);
156 foreach my $n (0..$#arguments) {
157 my $argument = $arguments[$n];
158 $argument =~ s/^\s*(.*?)\s*$/$1/;
159 #print " " . ($n + 1) . ": '$argument'\n";
160 $argument =~ s/^(IN OUT(?=\s)|IN(?=\s)|OUT(?=\s)|\s*)\s*//;
161 $argument =~ s/^(const(?=\s)|\s*)\s*//;
162 if($argument =~ /^...$/) {
164 } elsif($argument =~ /^((struct\s+|union\s+|enum\s+)?\w+)\s*((\*\s*?)*)\s*/) {
170 die "$file: $.: syntax error: '$argument'\n";
172 $arguments[$n] = $argument;
173 #print " " . ($n + 1) . ": '" . $arguments[$n] . "'\n";
175 if($#arguments == 0 && $arguments[0] =~ /^void$/i) { $#arguments = -1; }
177 if($options->debug) {
178 print "$file: $return_type $calling_convention $name(" . join(",", @arguments) . ")\n";
180 &$function_begin($documentation,$return_type,$calling_convention,$name,\@arguments);
182 } elsif(/DC_(GET_X_Y|GET_VAL_16)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
184 my @arguments = ("HDC16");
185 &$function_begin($documentation,$2, "WINAPI", $3, \@arguments);
187 } elsif(/DC_(GET_VAL_32)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,.*?\)/s) {
189 my @arguments = ("HDC");
190 &$function_begin($documentation,$2, "WINAPI", $3, \@arguments);
192 } elsif(/DC_(GET_VAL_EX)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
194 my @arguments16 = ("HDC16", "LP" . $5 . "16");
195 my @arguments32 = ("HDC", "LP" . $5);
196 &$function_begin($documentation,"BOOL16", "WINAPI", $2 . "16", \@arguments16);
198 &$function_begin($documentation,"BOOL", "WINAPI", $2, \@arguments32);
200 } elsif(/DC_(SET_MODE)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
202 my @arguments16 = ("HDC16", "INT16");
203 my @arguments32 = ("HDC", "INT");
204 &$function_begin($documentation,"INT16", "WINAPI", $2 . "16", \@arguments16);
206 &$function_begin($documentation,"INT", "WINAPI", $2, \@arguments32);
208 } elsif(/WAVEIN_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
210 my @arguments16 = ("HWAVEIN16");
211 my @arguments32 = ("HWAVEIN");
212 &$function_begin($documentation,"UINT16", "WINAPI", "waveIn" . $1 . "16", \@arguments16);
214 &$function_begin($documentation,"UINT", "WINAPI", "waveIn" . $1, \@arguments32);
216 } elsif(/WAVEOUT_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
218 my @arguments16 = ("HWAVEOUT16");
219 my @arguments32 = ("HWAVEOUT");
220 &$function_begin($documentation,"UINT16", "WINAPI", "waveOut" . $1 . "16", \@arguments16);
222 &$function_begin($documentation,"UINT", "WINAPI", "waveOut" . $1, \@arguments32);
224 } elsif(/WAVEOUT_SHORTCUT_(1|2)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
227 my @arguments16 = ("HWAVEOUT16", $4);
228 my @arguments32 = ("HWAVEOUT", $4);
229 &$function_begin($documentation,"UINT16", "WINAPI", "waveOut" . $2 . "16", \@arguments16);
231 &$function_begin($documentation,"UINT", "WINAPI", "waveOut" . $2, \@arguments32);
234 my @arguments16 = ("UINT16", $4);
235 my @arguments32 = ("UINT", $4);
236 &$function_begin($documentation,"UINT16", "WINAPI", "waveOut". $2 . "16", \@arguments16);
238 &$function_begin($documentation,"UINT", "WINAPI", "waveOut" . $2, \@arguments32);
245 print "+1: $_\n" if $options->debug >= 2;
252 print STDERR "done\n" if $options->verbose;
253 $output->write("$file: not at toplevel at end of file\n") unless $level == 0;