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);
28 use output qw($output);
29 use winapi_cleanup_options qw($options);
31 if($options->progress) {
32 $output->enable_progress;
34 $output->disable_progress;
37 ########################################################################
44 open(IN, "< $filename") || die "Can't open file '$filename'";
45 open(OUT, "> $filename.tmp") || die "Can't open file '$filename.tmp'";
47 my $result = &$function(\*IN, \*OUT, @_);
54 rename("$filename.tmp", $filename);
56 unlink("$filename.tmp");
62 ########################################################################
71 my $format_comments = sub {
73 if ($#comments == 0) {
74 my $comment = $comments[0];
76 $_ = "$indent/*$comment */";
77 } elsif ($#comments > 0) {
79 foreach my $comment (@comments) {
80 $_ .= "$indent *$comment\n";
95 if ($options->trailing_whitespace) {
96 s/(.*?)\s+$/$1/ && do { $modified = 1; };
98 s/(.*?)\r$/$1/ && do { $modified = 1; };
101 if ($options->cpp_comments) {
106 } elsif (/^([^\"\/]*?(?:\"[^\"]*?\"[^\"]*?)*?)\/\*(.*?)$/) {
109 if($comment !~ /^.*?\*\//) {
112 } elsif (/^([^\"\/]*?(?:\"[^\"]*?\"[^\"]*?)*?)\/\/(.*?)\s*$/) {
116 if ($indent2 =~ /^\s*$/) {
117 if (!$indent || $indent eq $indent2) {
119 push @comments, $comment;
122 $_ .= "$indent2/*$comment */";
125 my $comments = &$format_comments();
127 $_ = "$comments\n$indent2/*$comment */";
129 $_ = "$indent2/*$comment */";
135 my $comments = &$format_comments();
137 $_ = "$comments\n$_";
146 my $comments = &$format_comments();
148 print OUT "$comments\n";
155 ########################################################################
158 my @h_files = $options->h_files;
159 my @c_files = $options->c_files;
162 my $progress_current = 0;
163 my $progress_max = scalar(@h_files) + scalar(@c_files);
165 foreach my $file (@h_files) {
167 $output->progress("$file (file $progress_current of $progress_max)");
169 if (edit_file($file, \&cleanup_file, @_)) {
170 $output->write("$file: modified\n");
174 foreach my $file (@c_files) {
176 $output->progress("$file (file $progress_current of $progress_max)");
178 if (edit_file($file, \&cleanup_file, @_)) {
179 $output->write("$file: modified\n");