3 # Copyright 2000 Patrik Stridvall
11 while(defined($_ = shift)) {
17 if(!defined($pattern)) {
25 foreach my $file (@files) {
33 while($again || defined(my $line = <IN
>)) {
47 if(s/^(.*?)(\/\*.*?\*\/)(.*)$/$1 $3/s) {
50 } elsif(/^(.*?)\/\
*/s
) {
56 while(s/^(.*?)\/\/.*?
$/$1\n/s) { $again = 1; }
62 # remove preprocessor directives
67 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
73 if(s/^\s*extern\s+"C"\s+\{//m) {
87 while(/^./ && !s/^\'//) {
104 while(/^./ && !s/^\"//) {
128 $line .= "}" if $level > 1;
130 if($level == -1 && $extern_c) {
137 } elsif(/^class[^\}]*{/) {
141 } elsif(/^class[^\}]*$/) {
144 } elsif(/^typedef[^\}]*;/) {
146 } elsif(/(extern\s+|static\s+)?
147 (?:__inline__\s+|__inline\s+|inline\s+)?
148 ((struct\s+|union\s+|enum\s+)?(?:\w+(?:\:\:(?:\s*operator\s*[^\)\s]+)?)?)+((\s*(?:\*|\&))+\s*|\s+))
149 ((__cdecl|__stdcall|CDECL|VFWAPIV|VFWAPI|WINAPIV|WINAPI|CALLBACK)\s+)?
150 ((?:\w+(?:\:\:)?)+(\(\w+\))?)\s*\(([^\)]*)\)\s*
151 (?:\w+(?:\s*\([^\)]*\))?\s*)*\s*
160 my $return_type = $2;
161 my $calling_convention = $7;
165 if(!defined($linkage)) {
169 if(!defined($calling_convention)) {
170 $calling_convention = "";
173 $linkage =~ s/\s*$//;
175 $return_type =~ s/\s*$//;
176 $return_type =~ s/\s*\*\s*/*/g;
177 $return_type =~ s/(\*+)/ $1/g;
179 $arguments =~ y/\t\n/ /;
180 $arguments =~ s/^\s*(.*?)\s*$/$1/;
181 if($arguments eq "") { $arguments = "void" }
185 my @arguments = split(/,/, $arguments);
186 foreach my $n (0..$#arguments) {
187 my $argument_type = "";
188 my $argument_name = "";
189 my $argument = $arguments[$n];
190 $argument =~ s/^\s*(.*?)\s*$/$1/;
191 # print " " . ($n + 1) . ": '$argument'\n";
192 $argument =~ s/^(IN OUT(?=\s)|IN(?=\s)|OUT(?=\s)|\s*)\s*//;
193 $argument =~ s/^(const(?=\s)|CONST(?=\s)|__const(?=\s)|__restrict(?=\s)|\s*)\s*//;
194 if($argument =~ /^\.\.\.$/) {
195 $argument_type = "...";
196 $argument_name = "...";
197 } elsif($argument =~ /^
198 ((?
:struct\s
+|union\s
+|enum\s
+|(?
:signed\s
+|unsigned\s
+)
199 (?
:short\s
+(?
=int)|long\s
+(?
=int))?
)?
(?
:\w
+(?
:\
:\
:)?
)+)\s
*
200 ((?
:const
(?
=\s
)|CONST
(?
=\s
)|__const
(?
=\s
)|__restrict
(?
=\s
))?\s
*(?
:\
*\s
*?
)*)\s
*
201 (?
:const
(?
=\s
)|CONST
(?
=\s
)|__const
(?
=\s
)|__restrict
(?
=\s
))?\s
*
203 (?
:\
[\
]|\s
+OPTIONAL
)?
/x
)
205 $argument_type = "$1";
207 $argument_type .= " $2";
211 $argument_type =~ s/\s*const\s*/ /;
212 $argument_type =~ s/^\s*(.*?)\s*$/$1/;
214 $argument_name =~ s/^\s*(.*?)\s*$/$1/;
216 die "$file: $.: syntax error: '$argument'\n";
218 $argument_types[$n] = $argument_type;
219 $argument_names[$n] = $argument_name;
220 # print " " . ($n + 1) . ": '$argument_type': '$argument_name'\n";
222 if($#argument_types == 0 && $argument_types[0] =~ /^void$/i) {
223 $#argument_types = -1;
224 $#argument_names = -1;
228 foreach my $n (0..$#argument_types) {
229 if($argument_names[$n] && $argument_names[$n] ne "...") {
230 if($argument_types[$n] !~ /\*$/) {
231 $arguments[$n] = $argument_types[$n] . " " . $argument_names[$n];
233 $arguments[$n] = $argument_types[$n] . $argument_names[$n];
236 $arguments[$n] = $argument_types[$n];
240 $arguments = join(", ", @arguments);
241 if(!$arguments) { $arguments = "void"; }
243 if((!$invert && $name =~ /$pattern/) || ($invert && $name !~ /$pattern/)) {
244 if($calling_convention) {
245 print "$return_type $calling_convention $name($arguments)\n";
247 if($return_type =~ /\*$/) {
248 print "$return_type$name($arguments)\n";
250 print "$return_type $name($arguments)\n";
254 } elsif(/\'[^\']*\'/s) {
256 } elsif(/\"[^\"]*\"/s) {
260 } elsif(/extern\s+"C"\s+{/s) {