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
30 while(defined($_ = shift)) {
33 } elsif (/^--?(\?|h|help)$/) {
36 print STDERR
"$name0:error: unknown option '$_'\n";
39 } elsif(!defined($pattern)) {
47 print "Usage: $name0 [--help] [-v] pattern files...\n";
49 print "--help Prints this help message\n";
50 print "-v Return functions that do not match pattern\n";
51 print "pattern A regular expression for the function name\n";
52 print "files... A list of files to search the function in\n";
56 foreach my $file (@files) {
64 while($again || defined(my $line = <IN
>)) {
78 if(s/^(|.*?[^\/])(\/\
*.*?\
*\
/)(.*)$/$1 $3/s
) {
81 } elsif(/^(.*?)\/\
*/s
) {
87 while(s/^(.*?)\/\/.*?
$/$1\n/s) { $again = 1; }
93 # remove preprocessor directives
95 if(/^\#[.\n\r]*?\\$/m) {
98 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
104 if(s/^\s*extern[\s\n]+"C"[\s\n]+\{//m) {
108 } elsif(m/^\s*extern[\s\n]+"C"/m) {
117 s/^([^\{\}\'\"]*)//s;
121 while(/^./ && !s/^\'//) {
138 while(/^./ && !s/^\"//) {
162 $line .= "}" if $level > 1;
164 if($level == -1 && $extern_c) {
171 } elsif(/^class[^\}]*{/) {
175 } elsif(/^class[^\}]*$/) {
178 } elsif(/^typedef[^\}]*;/) {
180 } elsif(/(extern\s+|static\s+)?
181 (?:__inline__\s+|__inline\s+|inline\s+)?
182 ((struct\s+|union\s+|enum\s+)?(?:\w+(?:\:\:(?:\s*operator\s*[^\)\s]+)?)?)+((\s*(?:\*|\&))+\s*|\s+))
183 ((__cdecl|__stdcall|CDECL|VFWAPIV|VFWAPI|WINAPIV|WINAPI|CALLBACK)\s+)?
184 ((?:\w+(?:\:\:)?)+(\(\w+\))?)\s*\(([^\)]*)\)\s*
185 (?:\w+(?:\s*\([^\)]*\))?\s*)*\s*
194 my $return_type = $2;
195 my $calling_convention = $7;
199 if(!defined($linkage)) {
203 if(!defined($calling_convention)) {
204 $calling_convention = "";
207 $linkage =~ s/\s*$//;
209 $return_type =~ s/\s*$//;
210 $return_type =~ s/\s*\*\s*/*/g;
211 $return_type =~ s/(\*+)/ $1/g;
213 $arguments =~ y/\t\n/ /;
214 $arguments =~ s/^\s*(.*?)\s*$/$1/;
215 if($arguments eq "") { $arguments = "void" }
219 my @arguments = split(/,/, $arguments);
220 foreach my $n (0..$#arguments) {
221 my $argument_type = "";
222 my $argument_name = "";
223 my $argument = $arguments[$n];
224 $argument =~ s/^\s*(.*?)\s*$/$1/;
225 # print " " . ($n + 1) . ": '$argument'\n";
226 $argument =~ s/^(IN OUT(?=\s)|IN(?=\s)|OUT(?=\s)|\s*)\s*//;
227 $argument =~ s/^(const(?=\s)|CONST(?=\s)|__const(?=\s)|__restrict(?=\s)|\s*)\s*//;
228 if($argument =~ /^\.\.\.$/) {
229 $argument_type = "...";
230 $argument_name = "...";
231 } elsif($argument =~ /^
232 ((?
:struct\s
+|union\s
+|enum\s
+|(?
:signed\s
+|unsigned\s
+)
233 (?
:short\s
+(?
=int)|long\s
+(?
=int))?
)?
(?
:\w
+(?
:\
:\
:)?
)+)\s
*
234 ((?
:const
(?
=\s
)|CONST
(?
=\s
)|__const
(?
=\s
)|__restrict
(?
=\s
))?\s
*(?
:\
*\s
*?
)*)\s
*
235 (?
:const
(?
=\s
)|CONST
(?
=\s
)|__const
(?
=\s
)|__restrict
(?
=\s
))?\s
*
237 (?
:\
[\
]|\s
+OPTIONAL
)?
/x
)
239 $argument_type = "$1";
241 $argument_type .= " $2";
245 $argument_type =~ s/\s*const\s*/ /;
246 $argument_type =~ s/^\s*(.*?)\s*$/$1/;
248 $argument_name =~ s/^\s*(.*?)\s*$/$1/;
250 die "$file: $.: syntax error: '$argument'\n";
252 $argument_types[$n] = $argument_type;
253 $argument_names[$n] = $argument_name;
254 # print " " . ($n + 1) . ": '$argument_type': '$argument_name'\n";
256 if($#argument_types == 0 && $argument_types[0] =~ /^void$/i) {
257 $#argument_types = -1;
258 $#argument_names = -1;
262 foreach my $n (0..$#argument_types) {
263 if($argument_names[$n] && $argument_names[$n] ne "...") {
264 if($argument_types[$n] !~ /\*$/) {
265 $arguments[$n] = $argument_types[$n] . " " . $argument_names[$n];
267 $arguments[$n] = $argument_types[$n] . $argument_names[$n];
270 $arguments[$n] = $argument_types[$n];
274 $arguments = join(", ", @arguments);
275 if(!$arguments) { $arguments = "void"; }
277 if((!$invert && $name =~ /$pattern/) || ($invert && $name !~ /$pattern/)) {
278 if($calling_convention) {
279 print "$return_type $calling_convention $name($arguments)\n";
281 if($return_type =~ /\*$/) {
282 print "$return_type$name($arguments)\n";
284 print "$return_type $name($arguments)\n";
288 } elsif(/\'(?:[^\\\']*|\\.)*\'/s) {
290 } elsif(/\"(?:[^\\\"]*|\\.)*\"/s) {
294 } elsif(/extern\s+"C"\s+{/s) {