3 # Copyright 2002 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
23 $0 =~ m
%^(.*?
/?tools)/winapi
/winapi_cleanup
$%;
24 require "$1/winapi/setup.pm";
27 use config
qw($current_dir $wine_dir file_absolutize file_directory);
28 use output qw($output);
29 use winapi_cleanup_options qw($options);
31 use nativeapi qw($nativeapi);
32 use util qw(edit_file);
34 if($options->progress) {
35 $output->enable_progress;
37 $output->disable_progress;
40 ########################################################################
49 my $file2 = file_absolutize
($file);
50 my $dir = file_directory
($file2);
56 my $format_comments = sub {
58 if ($#comments == 0) {
59 my $comment = $comments[0];
61 $_ = "$indent/*$comment */";
62 } elsif ($#comments > 0) {
64 foreach my $comment (@comments) {
65 $_ .= "$indent *$comment\n";
80 if ($options->trailing_whitespace) {
81 s/(.*?)\s+$/$1/ && do { $modified = 1; };
83 s/(.*?)\r$/$1/ && do { $modified = 1; };
86 if ($options->cpp_comments) {
91 } elsif (/^([^\"\/]*?
(?
:\"[^\"]*?
\"[^\"]*?
)*?
)\
/\*(.*?)$/) {
94 if($comment !~ /^.*?\*\//) {
97 } elsif (/^([^\"\/]*?
(?
:\"[^\"]*?
\"[^\"]*?
)*?
)\
/\/(.*?
)\s
*$/) {
101 if ($indent2 =~ /^\s*$/) {
102 if (!$indent || $indent eq $indent2) {
104 push @comments, $comment;
107 $_ .= "$indent2/*$comment */";
110 my $comments = &$format_comments();
112 $_ = "$comments\n$indent2/*$comment */";
114 $_ = "$indent2/*$comment */";
120 my $comments = &$format_comments();
122 $_ = "$comments\n$_";
128 if ($options->include_quotes) {
130 if ($dir =~ m
%^$wine_dir/(?
:controls
|windows
)$%) {
132 } elsif ($dir =~ m
%^$wine_dir/(?
:graphics
)$%) {
134 } elsif ($dir =~ m
%^$wine_dir/(?:graphics|windows)/x11drv
$%) {
136 } elsif ($dir =~ m
%^$wine_dir/dlls/(.*?
)/.*?
$%) {
140 if (/^(\s*\#\s*include\s+)(?:<(.*?)>|\"(.*?)\")(.*?)\s*$/) {
142 my $header = $2 || $3;
143 my $local = !defined($2) && defined($3);
146 my $exists_system = 0; {
147 my @system_paths = qw(/usr/include /usr/local/include /usr/X11R6/include);
148 foreach my $path (@system_paths) {
149 $exists_system ||= (-e
"$path/$header" || 0);
151 $exists_system ||= $nativeapi->is_conditional_header($header);
154 my $exists_windows = 0; {
155 if ($header !~ m
%^wine
/% && $header ne "config.h") {
156 $exists_windows ||= (-e
"$wine_dir/include/$header" || 0);
160 my $exists_wine = 0; {
161 $exists_wine ||= ($header eq "config.h");
163 if ($header =~ m
%^wine
/%) {
164 $exists_wine ||= (-e
"$wine_dir/include/$header" || 0);
168 my $exists_local = 0; {
169 $exists_local ||= ($header eq "y.tab.h");
171 my @local_paths = ();
172 push @local_paths, "$dir" if $dir !~ m
%^$wine_dir/include
%;
173 push @local_paths, "$wine_dir/dlls/$module" if $module;
174 foreach my $path (@local_paths) {
175 $exists_local ||= (-e
"$path/$header" || 0);
179 if (!$exists_system && !$exists_windows && !$exists_wine && !$exists_local) {
180 $output->write("warning: header '$header': doesn't exist\n");
181 } elsif (($exists_system + $exists_windows + $exists_wine + $exists_local) > 1) {
182 if ($header !~ /^(?:async\.h|comcat\.h|sql(?:ext|types)?\.h|thread\.h|user\.h)$/) {
183 $output->write("warning: header '$header': more than one possibillity\n");
187 if (!$local && $exists_local) {
188 $_ = "$prefix\"$header\"$suffix";
190 } elsif ($local && !$exists_local && ($exists_system || $exists_windows || $exists_wine)) {
191 $_ = "$prefix<$header>$suffix";
200 my $comments = &$format_comments();
202 print OUT
"$comments\n";
209 ########################################################################
212 my @h_files = $options->h_files;
213 my @c_files = $options->c_files;
216 my $progress_current = 0;
217 my $progress_max = scalar(@h_files) + scalar(@c_files);
219 foreach my $file (@h_files) {
221 $output->progress("$file (file $progress_current of $progress_max)");
222 $output->prefix("$file: ");
224 if (edit_file
($file, \
&cleanup_file
, @_, $file)) {
225 $output->write("$file: modified\n");
229 foreach my $file (@c_files) {
231 $output->progress("$file (file $progress_current of $progress_max)");
232 $output->prefix("$file: ");
234 if (edit_file
($file, \
&cleanup_file
, $file)) {
235 $output->write("$file: modified\n");