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
98 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
104 if(s/^\s*extern\s+"C"\s+\{//m) {
114 s/^([^\{\}\'\"]*)//s;
118 while(/^./ && !s/^\'//) {
135 while(/^./ && !s/^\"//) {
159 $line .= "}" if $level > 1;
161 if($level == -1 && $extern_c) {
168 } elsif(/^class[^\}]*{/) {
172 } elsif(/^class[^\}]*$/) {
175 } elsif(/^typedef[^\}]*;/) {
177 } elsif(/(extern\s+|static\s+)?
178 (?:__inline__\s+|__inline\s+|inline\s+)?
179 ((struct\s+|union\s+|enum\s+)?(?:\w+(?:\:\:(?:\s*operator\s*[^\)\s]+)?)?)+((\s*(?:\*|\&))+\s*|\s+))
180 ((__cdecl|__stdcall|CDECL|VFWAPIV|VFWAPI|WINAPIV|WINAPI|CALLBACK)\s+)?
181 ((?:\w+(?:\:\:)?)+(\(\w+\))?)\s*\(([^\)]*)\)\s*
182 (?:\w+(?:\s*\([^\)]*\))?\s*)*\s*
191 my $return_type = $2;
192 my $calling_convention = $7;
196 if(!defined($linkage)) {
200 if(!defined($calling_convention)) {
201 $calling_convention = "";
204 $linkage =~ s/\s*$//;
206 $return_type =~ s/\s*$//;
207 $return_type =~ s/\s*\*\s*/*/g;
208 $return_type =~ s/(\*+)/ $1/g;
210 $arguments =~ y/\t\n/ /;
211 $arguments =~ s/^\s*(.*?)\s*$/$1/;
212 if($arguments eq "") { $arguments = "void" }
216 my @arguments = split(/,/, $arguments);
217 foreach my $n (0..$#arguments) {
218 my $argument_type = "";
219 my $argument_name = "";
220 my $argument = $arguments[$n];
221 $argument =~ s/^\s*(.*?)\s*$/$1/;
222 # print " " . ($n + 1) . ": '$argument'\n";
223 $argument =~ s/^(IN OUT(?=\s)|IN(?=\s)|OUT(?=\s)|\s*)\s*//;
224 $argument =~ s/^(const(?=\s)|CONST(?=\s)|__const(?=\s)|__restrict(?=\s)|\s*)\s*//;
225 if($argument =~ /^\.\.\.$/) {
226 $argument_type = "...";
227 $argument_name = "...";
228 } elsif($argument =~ /^
229 ((?
:struct\s
+|union\s
+|enum\s
+|(?
:signed\s
+|unsigned\s
+)
230 (?
:short\s
+(?
=int)|long\s
+(?
=int))?
)?
(?
:\w
+(?
:\
:\
:)?
)+)\s
*
231 ((?
:const
(?
=\s
)|CONST
(?
=\s
)|__const
(?
=\s
)|__restrict
(?
=\s
))?\s
*(?
:\
*\s
*?
)*)\s
*
232 (?
:const
(?
=\s
)|CONST
(?
=\s
)|__const
(?
=\s
)|__restrict
(?
=\s
))?\s
*
234 (?
:\
[\
]|\s
+OPTIONAL
)?
/x
)
236 $argument_type = "$1";
238 $argument_type .= " $2";
242 $argument_type =~ s/\s*const\s*/ /;
243 $argument_type =~ s/^\s*(.*?)\s*$/$1/;
245 $argument_name =~ s/^\s*(.*?)\s*$/$1/;
247 die "$file: $.: syntax error: '$argument'\n";
249 $argument_types[$n] = $argument_type;
250 $argument_names[$n] = $argument_name;
251 # print " " . ($n + 1) . ": '$argument_type': '$argument_name'\n";
253 if($#argument_types == 0 && $argument_types[0] =~ /^void$/i) {
254 $#argument_types = -1;
255 $#argument_names = -1;
259 foreach my $n (0..$#argument_types) {
260 if($argument_names[$n] && $argument_names[$n] ne "...") {
261 if($argument_types[$n] !~ /\*$/) {
262 $arguments[$n] = $argument_types[$n] . " " . $argument_names[$n];
264 $arguments[$n] = $argument_types[$n] . $argument_names[$n];
267 $arguments[$n] = $argument_types[$n];
271 $arguments = join(", ", @arguments);
272 if(!$arguments) { $arguments = "void"; }
274 if((!$invert && $name =~ /$pattern/) || ($invert && $name !~ /$pattern/)) {
275 if($calling_convention) {
276 print "$return_type $calling_convention $name($arguments)\n";
278 if($return_type =~ /\*$/) {
279 print "$return_type$name($arguments)\n";
281 print "$return_type $name($arguments)\n";
285 } elsif(/\'(?:[^\\\']*|\\.)*\'/s) {
287 } elsif(/\"(?:[^\\\"]*|\\.)*\"/s) {
291 } elsif(/extern\s+"C"\s+{/s) {