3 # Copyright 2000 Patrik Stridvall
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 while(defined($_ = shift)) {
32 if(!defined($pattern)) {
40 foreach my $file (@files) {
48 while($again || defined(my $line = <IN
>)) {
62 if(s/^(.*?)(\/\*.*?\*\/)(.*)$/$1 $3/s) {
65 } elsif(/^(.*?)\/\
*/s
) {
71 while(s/^(.*?)\/\/.*?
$/$1\n/s) { $again = 1; }
77 # remove preprocessor directives
82 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
88 if(s/^\s*extern\s+"C"\s+\{//m) {
102 while(/^./ && !s/^\'//) {
119 while(/^./ && !s/^\"//) {
143 $line .= "}" if $level > 1;
145 if($level == -1 && $extern_c) {
152 } elsif(/^class[^\}]*{/) {
156 } elsif(/^class[^\}]*$/) {
159 } elsif(/^typedef[^\}]*;/) {
161 } elsif(/(extern\s+|static\s+)?
162 (?:__inline__\s+|__inline\s+|inline\s+)?
163 ((struct\s+|union\s+|enum\s+)?(?:\w+(?:\:\:(?:\s*operator\s*[^\)\s]+)?)?)+((\s*(?:\*|\&))+\s*|\s+))
164 ((__cdecl|__stdcall|CDECL|VFWAPIV|VFWAPI|WINAPIV|WINAPI|CALLBACK)\s+)?
165 ((?:\w+(?:\:\:)?)+(\(\w+\))?)\s*\(([^\)]*)\)\s*
166 (?:\w+(?:\s*\([^\)]*\))?\s*)*\s*
175 my $return_type = $2;
176 my $calling_convention = $7;
180 if(!defined($linkage)) {
184 if(!defined($calling_convention)) {
185 $calling_convention = "";
188 $linkage =~ s/\s*$//;
190 $return_type =~ s/\s*$//;
191 $return_type =~ s/\s*\*\s*/*/g;
192 $return_type =~ s/(\*+)/ $1/g;
194 $arguments =~ y/\t\n/ /;
195 $arguments =~ s/^\s*(.*?)\s*$/$1/;
196 if($arguments eq "") { $arguments = "void" }
200 my @arguments = split(/,/, $arguments);
201 foreach my $n (0..$#arguments) {
202 my $argument_type = "";
203 my $argument_name = "";
204 my $argument = $arguments[$n];
205 $argument =~ s/^\s*(.*?)\s*$/$1/;
206 # print " " . ($n + 1) . ": '$argument'\n";
207 $argument =~ s/^(IN OUT(?=\s)|IN(?=\s)|OUT(?=\s)|\s*)\s*//;
208 $argument =~ s/^(const(?=\s)|CONST(?=\s)|__const(?=\s)|__restrict(?=\s)|\s*)\s*//;
209 if($argument =~ /^\.\.\.$/) {
210 $argument_type = "...";
211 $argument_name = "...";
212 } elsif($argument =~ /^
213 ((?
:struct\s
+|union\s
+|enum\s
+|(?
:signed\s
+|unsigned\s
+)
214 (?
:short\s
+(?
=int)|long\s
+(?
=int))?
)?
(?
:\w
+(?
:\
:\
:)?
)+)\s
*
215 ((?
:const
(?
=\s
)|CONST
(?
=\s
)|__const
(?
=\s
)|__restrict
(?
=\s
))?\s
*(?
:\
*\s
*?
)*)\s
*
216 (?
:const
(?
=\s
)|CONST
(?
=\s
)|__const
(?
=\s
)|__restrict
(?
=\s
))?\s
*
218 (?
:\
[\
]|\s
+OPTIONAL
)?
/x
)
220 $argument_type = "$1";
222 $argument_type .= " $2";
226 $argument_type =~ s/\s*const\s*/ /;
227 $argument_type =~ s/^\s*(.*?)\s*$/$1/;
229 $argument_name =~ s/^\s*(.*?)\s*$/$1/;
231 die "$file: $.: syntax error: '$argument'\n";
233 $argument_types[$n] = $argument_type;
234 $argument_names[$n] = $argument_name;
235 # print " " . ($n + 1) . ": '$argument_type': '$argument_name'\n";
237 if($#argument_types == 0 && $argument_types[0] =~ /^void$/i) {
238 $#argument_types = -1;
239 $#argument_names = -1;
243 foreach my $n (0..$#argument_types) {
244 if($argument_names[$n] && $argument_names[$n] ne "...") {
245 if($argument_types[$n] !~ /\*$/) {
246 $arguments[$n] = $argument_types[$n] . " " . $argument_names[$n];
248 $arguments[$n] = $argument_types[$n] . $argument_names[$n];
251 $arguments[$n] = $argument_types[$n];
255 $arguments = join(", ", @arguments);
256 if(!$arguments) { $arguments = "void"; }
258 if((!$invert && $name =~ /$pattern/) || ($invert && $name !~ /$pattern/)) {
259 if($calling_convention) {
260 print "$return_type $calling_convention $name($arguments)\n";
262 if($return_type =~ /\*$/) {
263 print "$return_type$name($arguments)\n";
265 print "$return_type $name($arguments)\n";
269 } elsif(/\'[^\']*\'/s) {
271 } elsif(/\"[^\"]*\"/s) {
275 } elsif(/extern\s+"C"\s+{/s) {