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);
39 my $lookahead_count = 0;
41 print STDERR "Processing file '$file' ... " if $options->verbose;
42 open(IN, "< $file") || die "<internal>: $file: $!\n";
44 while($again || defined(my $line = <IN>)) {
56 print "$level: $line\n" if $options->debug >= 2;
62 # Merge conflicts in file?
63 if(/^(<<<<<<<|=======|>>>>>>>)/) {
64 $output->write("$file: merge conflicts in file\n");
69 if(s/^(.*?)(\/\*.*?\*\/)(.*)$/$1 $3/s) { push @comments, $2; $again = 1; next };
78 # remove preprocessor directives
83 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
85 &$preprocessor_found_callback($1, $3);
87 &$preprocessor_found_callback($1, "");
97 while($n >= 0 && $comments[$n] !~ /\/\*\*/) { $n-- }
98 if(defined($comments[$n]) && $n >= 0) {
99 $documentation = $comments[$n];
113 print "+1: $_\n" if $options->debug >= 2;
117 $line .= $1 if $level > 1;
118 print "-1: $_\n" if $options->debug >= 2;
121 if($line !~ /^\s*$/) {
122 $statements .= "$line\n";
124 if($function && $level == 0) {
128 } elsif(/((struct\s+|union\s+|enum\s+)?\w+((\s*\*)+\s*|\s+))((__cdecl|__stdcall|VFWAPIV|VFWAPI|WINAPIV|WINAPI)\s+)?(\w+(\(\w+\))?)\s*\(([^\)]*)\)\s*(\{|\;)/s) {
133 } elsif($10 eq "{") {
137 my $return_type = $1;
138 my $calling_convention = $6;
142 if(!defined($calling_convention)) {
143 $calling_convention = "";
146 $return_type =~ s/\s*$//;
147 $return_type =~ s/\s*\*\s*/*/g;
148 $return_type =~ s/(\*+)/ $1/g;
150 if($regs_entrypoints{$name}) {
151 $name = $regs_entrypoints{$name};
154 $arguments =~ y/\t\n/ /;
155 $arguments =~ s/^\s*(.*?)\s*$/$1/;
156 if($arguments eq "") { $arguments = "void" }
158 my @arguments = split(/,/, $arguments);
159 foreach my $n (0..$#arguments) {
160 my $argument = $arguments[$n];
161 $argument =~ s/^\s*(.*?)\s*$/$1/;
162 #print " " . ($n + 1) . ": '$argument'\n";
163 $argument =~ s/^(IN OUT(?=\s)|IN(?=\s)|OUT(?=\s)|\s*)\s*//;
164 $argument =~ s/^(const(?=\s)|CONST(?=\s)|\s*)\s*//;
165 if($argument =~ /^...$/) {
167 } elsif($argument =~ /^((struct\s+|union\s+|enum\s+)?\w+)\s*((\*\s*?)*)\s*/) {
173 die "$file: $.: syntax error: '$argument'\n";
175 $arguments[$n] = $argument;
176 #print " " . ($n + 1) . ": '" . $arguments[$n] . "'\n";
178 if($#arguments == 0 && $arguments[0] =~ /^void$/i) { $#arguments = -1; }
180 if($options->debug) {
181 print "$file: $return_type $calling_convention $name(" . join(",", @arguments) . ")\n";
183 &$function_begin($documentation,$return_type,$calling_convention,$name,\@arguments);
185 } elsif(/DC_(GET_X_Y|GET_VAL_16)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
187 my @arguments = ("HDC16");
188 &$function_begin($documentation,$2, "WINAPI", $3, \@arguments);
190 } elsif(/DC_(GET_VAL_32)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,.*?\)/s) {
192 my @arguments = ("HDC");
193 &$function_begin($documentation,$2, "WINAPI", $3, \@arguments);
195 } elsif(/DC_(GET_VAL_EX)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
197 my @arguments16 = ("HDC16", "LP" . $5 . "16");
198 my @arguments32 = ("HDC", "LP" . $5);
199 &$function_begin($documentation,"BOOL16", "WINAPI", $2 . "16", \@arguments16);
201 &$function_begin($documentation,"BOOL", "WINAPI", $2, \@arguments32);
203 } elsif(/DC_(SET_MODE)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
205 my @arguments16 = ("HDC16", "INT16");
206 my @arguments32 = ("HDC", "INT");
207 &$function_begin($documentation,"INT16", "WINAPI", $2 . "16", \@arguments16);
209 &$function_begin($documentation,"INT", "WINAPI", $2, \@arguments32);
211 } elsif(/WAVEIN_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
213 my @arguments16 = ("HWAVEIN16");
214 my @arguments32 = ("HWAVEIN");
215 &$function_begin($documentation,"UINT16", "WINAPI", "waveIn" . $1 . "16", \@arguments16);
217 &$function_begin($documentation,"UINT", "WINAPI", "waveIn" . $1, \@arguments32);
219 } elsif(/WAVEOUT_SHORTCUT_0\s*\(\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
221 my @arguments16 = ("HWAVEOUT16");
222 my @arguments32 = ("HWAVEOUT");
223 &$function_begin($documentation,"UINT16", "WINAPI", "waveOut" . $1 . "16", \@arguments16);
225 &$function_begin($documentation,"UINT", "WINAPI", "waveOut" . $1, \@arguments32);
227 } elsif(/WAVEOUT_SHORTCUT_(1|2)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
230 my @arguments16 = ("HWAVEOUT16", $4);
231 my @arguments32 = ("HWAVEOUT", $4);
232 &$function_begin($documentation,"UINT16", "WINAPI", "waveOut" . $2 . "16", \@arguments16);
234 &$function_begin($documentation,"UINT", "WINAPI", "waveOut" . $2, \@arguments32);
237 my @arguments16 = ("UINT16", $4);
238 my @arguments32 = ("UINT", $4);
239 &$function_begin($documentation,"UINT16", "WINAPI", "waveOut". $2 . "16", \@arguments16);
241 &$function_begin($documentation,"UINT", "WINAPI", "waveOut" . $2, \@arguments32);
244 } elsif(/DEFINE_REGS_ENTRYPOINT_\d+\(\s*(\S*)\s*,\s*([^\s,\)]*).*?\)/s) {
246 $regs_entrypoints{$2} = $1;
251 print "+1: $_\n" if $options->debug >= 2;
258 print STDERR "done\n" if $options->verbose;
259 $output->write("$file: not at toplevel at end of file\n") unless $level == 0;