8 my $function_found_callback = shift;
13 my $lookahead_count = 0;
15 print STDERR "Processing file '$file' ... " if $options->verbose;
16 open(IN, "< $file") || die "<internal>: $file: $!\n";
18 while($again || defined(my $line = <IN>)) {
30 print "$level: $line\n" if $options->debug >= 2;
37 if(s/^(.*?)\/\*.*?\*\/(.*)$/$1 $2/s) { $again = 1; next };
46 # remove preprocessor directives
47 if(s/^\s*\#.*$//m) { $again = 1; next; }
54 print "+1: $_\n" if $options->debug >= 2;
58 print "-1: $_\n" if $options->debug >= 2;
62 } elsif(/((struct\s+|union\s+|enum\s+)?\w+((\s*\*)+\s*|\s+))(__cdecl|__stdcall|VFWAPIV|VFWAPI|WINAPIV|WINAPI)\s+(\w+(\(\w+\))?)\s*\(([^\)]*)\)\s*(\{|\;)/s) {
72 my $calling_convention = $5;
76 $return_type =~ s/\s*$//;
77 $return_type =~ s/\s*\*\s*/*/g;
78 $return_type =~ s/(\*+)/ $1/g;
80 $name =~ s/^REGS_FUNC\((.*?)\)/$1/;
82 $arguments =~ y/\t\n/ /;
83 $arguments =~ s/^\s*(.*?)\s*$/$1/;
84 if($arguments eq "") { $arguments = "void" }
86 my @arguments = split(/,/, $arguments);
87 foreach my $n (0..$#arguments) {
88 my $argument = $arguments[$n];
89 $argument =~ s/^\s*(.*?)\s*$/$1/;
90 #print " " . ($n + 1) . ": '$argument'\n";
91 $argument =~ s/^(const(?=\s)|IN(?=\s)|OUT(?=\s)|(\s*))\s*//;
92 if($argument =~ /^...$/) {
94 } elsif($argument =~ /^((struct\s+|union\s+|enum\s+)?\w+)\s*((\*\s*?)*)\s*/) {
100 die "$file: $.: syntax error: '$argument'\n";
102 $arguments[$n] = $argument;
103 #print " " . ($n + 1) . ": '" . $arguments[$n] . "'\n";
105 if($#arguments == 0 && $arguments[0] =~ /^void$/i) { $#arguments = -1; }
107 if($options->debug) {
108 print "$file: $return_type $calling_convention $name(" . join(",", @arguments) . ")\n";
110 &$function_found_callback($return_type,$calling_convention,$name,\@arguments);
112 } elsif(/DC_(GET_X_Y|GET_VAL_16)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
114 my @arguments = ("HDC16");
115 &$function_found_callback($2, "WINAPI", $3, \@arguments);
116 } elsif(/DC_(GET_VAL_32)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,.*?\)/s) {
118 my @arguments = ("HDC");
119 &$function_found_callback($2, "WINAPI", $3, \@arguments);
120 } elsif(/DC_(GET_VAL_EX)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
122 my @arguments16 = ("HDC16", "LP" . $5 . "16");
123 my @arguments32 = ("HDC", "LP" . $5);
124 &$function_found_callback("BOOL16", "WINAPI", $2 . "16", \@arguments16);
125 &$function_found_callback("BOOL", "WINAPI", $2, \@arguments32);
126 } elsif(/DC_(SET_MODE)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
128 my @arguments16 = ("HDC16", "INT16");
129 my @arguments32 = ("HDC", "INT");
130 &$function_found_callback("INT16", "WINAPI", $2 . "16", \@arguments16);
131 &$function_found_callback("INT", "WINAPI", $2, \@arguments32);
132 } elsif(/WAVEOUT_SHORTCUT_(1|2)\s*\(\s*(.*?)\s*,\s*(.*?)\s*,\s*(.*?)\s*\)/s) {
136 my @arguments16 = ("HWAVEOUT16", $4);
137 my @arguments32 = ("HWAVEOUT", $4);
138 &$function_found_callback("UINT16", "WINAPI", "waveOut" . $2 . "16", \@arguments16);
139 &$function_found_callback("UINT", "WINAPI", "waveOut" . $2, \@arguments32);
141 my @arguments16 = ("UINT16", $4);
142 my @arguments32 = ("UINT", $4);
143 &$function_found_callback("UINT16", "WINAPI", "waveOut". $2 . "16", \@arguments16);
144 &$function_found_callback("UINT", "WINAPI", "waveOut" . $2, \@arguments32)
150 print "+1: $_\n" if $options->debug >= 2;
157 print STDERR "done\n" if $options->verbose;
158 print "$file: <>: not at toplevel at end of file\n" unless $level == 0;