Moved mode setting out of .spec file into Makefile.
[wine/gsoc_dplay.git] / tools / winapi / winapi_cleanup
blob05b50f2279728440d0d85fb8e3762759e6936922
1 #! /usr/bin/perl -w
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
20 use strict;
22 BEGIN {
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_extract_options qw($options);
31 if($options->progress) {
32 $output->enable_progress;
33 } else {
34 $output->disable_progress;
37 ########################################################################
38 # edit_file
40 sub edit_file {
41 my $filename = shift;
42 my $function = shift;
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, @_);
49 close(IN);
50 close(OUT);
52 if($result) {
53 unlink($filename);
54 rename("$filename.tmp", $filename);
55 } else {
56 unlink("$filename.tmp");
59 return $result;
62 ########################################################################
63 # cleanup_file
65 sub cleanup_file {
66 local *IN = shift;
67 local *OUT = shift;
69 my $modified = 0;
71 while (<IN>) {
72 chomp;
73 if(s/(.*?)\s+$/$1/) {
74 $modified = 1;
77 print OUT "$_\n";
80 return $modified;
83 ########################################################################
84 # main
86 my @h_files = $options->h_files;
87 my @c_files = $options->c_files;
89 my $progress_output;
90 my $progress_current = 0;
91 my $progress_max = scalar(@h_files) + scalar(@c_files);
93 foreach my $file (@h_files) {
94 $progress_current++;
95 $output->progress("$file (file $progress_current of $progress_max)");
97 if (edit_file($file, \&cleanup_file, @_)) {
98 $output->write("$file: modified\n");
102 foreach my $file (@c_files) {
103 $progress_current++;
104 $output->progress("$file (file $progress_current of $progress_max)");
106 if (edit_file($file, \&cleanup_file, @_)) {
107 $output->write("$file: modified\n");