Declare SetLayeredWindowAttributes.
[wine/hacks.git] / tools / winedump / function_grep.pl
blob42183cfe0b3853e225c017d0744bd459d65fb92a
1 #! /usr/bin/perl -w
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
20 use strict;
22 my $name0=$0;
23 $name0 =~ s%^.*/%%;
25 my $invert = 0;
26 my $pattern;
27 my @files = ();
28 my $usage;
30 while(defined($_ = shift)) {
31 if (/^-v$/) {
32 $invert = 1;
33 } elsif (/^--?(\?|h|help)$/) {
34 $usage=0;
35 } elsif (/^-/) {
36 print STDERR "$name0:error: unknown option '$_'\n";
37 $usage=2;
38 last;
39 } elsif(!defined($pattern)) {
40 $pattern = $_;
41 } else {
42 push @files, $_;
45 if (defined $usage)
47 print "Usage: $name0 [--help] [-v] pattern files...\n";
48 print "where:\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";
53 exit $usage;
56 foreach my $file (@files) {
57 open(IN, "< $file");
59 my $level = 0;
60 my $extern_c = 0;
62 my $again = 0;
63 my $lookahead = 0;
64 while($again || defined(my $line = <IN>)) {
65 if(!$again) {
66 chomp $line;
67 if($lookahead) {
68 $lookahead = 0;
69 $_ .= "\n" . $line;
70 } else {
71 $_ = $line;
73 } else {
74 $again = 0;
77 # remove C comments
78 if(s/^(.*?)(\/\*.*?\*\/)(.*)$/$1 $3/s) {
79 $again = 1;
80 next;
81 } elsif(/^(.*?)\/\*/s) {
82 $lookahead = 1;
83 next;
86 # remove C++ comments
87 while(s/^(.*?)\/\/.*?$/$1\n/s) { $again = 1; }
88 if($again) { next; }
90 # remove empty rows
91 if(/^\s*$/) { next; }
93 # remove preprocessor directives
94 if(s/^\s*\#/\#/m) {
95 if(/^\#[.\n\r]*?\\$/m) {
96 $lookahead = 1;
97 next;
98 } elsif(s/^\#\s*(.*?)(\s+(.*?))?\s*$//m) {
99 next;
103 # Remove extern "C"
104 if(s/^\s*extern\s+"C"\s+\{//m) {
105 $extern_c = 1;
106 $again = 1;
107 next;
110 if($level > 0)
112 my $line = "";
113 while(/^[^\{\}]/) {
114 s/^([^\{\}\'\"]*)//s;
115 $line .= $1;
116 if(s/^\'//) {
117 $line .= "\'";
118 while(/^./ && !s/^\'//) {
119 s/^([^\'\\]*)//s;
120 $line .= $1;
121 if(s/^\\//) {
122 $line .= "\\";
123 if(s/^(.)//s) {
124 $line .= $1;
125 if($1 eq "0") {
126 s/^(\d{0,3})//s;
127 $line .= $1;
132 $line .= "\'";
133 } elsif(s/^\"//) {
134 $line .= "\"";
135 while(/^./ && !s/^\"//) {
136 s/^([^\"\\]*)//s;
137 $line .= $1;
138 if(s/^\\//) {
139 $line .= "\\";
140 if(s/^(.)//s) {
141 $line .= $1;
142 if($1 eq "0") {
143 s/^(\d{0,3})//s;
144 $line .= $1;
149 $line .= "\"";
153 if(s/^\{//) {
154 $_ = $'; $again = 1;
155 $line .= "{";
156 $level++;
157 } elsif(s/^\}//) {
158 $_ = $'; $again = 1;
159 $line .= "}" if $level > 1;
160 $level--;
161 if($level == -1 && $extern_c) {
162 $extern_c = 0;
163 $level = 0;
167 next;
168 } elsif(/^class[^\}]*{/) {
169 $_ = $'; $again = 1;
170 $level++;
171 next;
172 } elsif(/^class[^\}]*$/) {
173 $lookahead = 1;
174 next;
175 } elsif(/^typedef[^\}]*;/) {
176 next;
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*
183 (\{|\;)/sx)
185 $_ = $'; $again = 1;
186 if($11 eq "{") {
187 $level++;
190 my $linkage = $1;
191 my $return_type = $2;
192 my $calling_convention = $7;
193 my $name = $8;
194 my $arguments = $10;
196 if(!defined($linkage)) {
197 $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" }
214 my @argument_types;
215 my @argument_names;
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*
233 (\w*)\s*
234 (?:\[\]|\s+OPTIONAL)?/x)
236 $argument_type = "$1";
237 if($2 ne "") {
238 $argument_type .= " $2";
240 $argument_name = $3;
242 $argument_type =~ s/\s*const\s*/ /;
243 $argument_type =~ s/^\s*(.*?)\s*$/$1/;
245 $argument_name =~ s/^\s*(.*?)\s*$/$1/;
246 } else {
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;
258 @arguments = ();
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];
263 } else {
264 $arguments[$n] = $argument_types[$n] . $argument_names[$n];
266 } else {
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";
277 } else {
278 if($return_type =~ /\*$/) {
279 print "$return_type$name($arguments)\n";
280 } else {
281 print "$return_type $name($arguments)\n";
285 } elsif(/\'(?:[^\\\']*|\\.)*\'/s) {
286 $_ = $'; $again = 1;
287 } elsif(/\"(?:[^\\\"]*|\\.)*\"/s) {
288 $_ = $'; $again = 1;
289 } elsif(/;/s) {
290 $_ = $'; $again = 1;
291 } elsif(/extern\s+"C"\s+{/s) {
292 $_ = $'; $again = 1;
293 } elsif(/\{/s) {
294 $_ = $'; $again = 1;
295 $level++;
296 } else {
297 $lookahead = 1;
300 close(IN);