From 440b021592dbd73270467dfd0fee7e7f879ac0d5 Mon Sep 17 00:00:00 2001 From: Patrik Stridvall Date: Wed, 28 Aug 2002 23:42:57 +0000 Subject: [PATCH] New tool winapi_cleanup for doing simple automatic cleanups. Currently it removes trailing white space from the .[ch] files. --- tools/winapi/Makefile.in | 1 + tools/winapi/winapi_cleanup | 109 +++++++++++++++++++++++++ tools/winapi/winapi_cleanup_options.pm | 51 ++++++++++++ 3 files changed, 161 insertions(+) create mode 100755 tools/winapi/winapi_cleanup create mode 100644 tools/winapi/winapi_cleanup_options.pm diff --git a/tools/winapi/Makefile.in b/tools/winapi/Makefile.in index 86870b8d91e..4c33b881949 100644 --- a/tools/winapi/Makefile.in +++ b/tools/winapi/Makefile.in @@ -11,6 +11,7 @@ install:: $(MKINSTALLDIRS) $(bindir) $(INSTALL_SCRIPT) $(SRCDIR)/trampoline $(bindir)/make_filter $(INSTALL_SCRIPT) $(SRCDIR)/trampoline $(bindir)/winapi_check + $(INSTALL_SCRIPT) $(SRCDIR)/trampoline $(bindir)/winapi_cleanup $(INSTALL_SCRIPT) $(SRCDIR)/trampoline $(bindir)/winapi_extract $(INSTALL_SCRIPT) $(SRCDIR)/trampoline $(bindir)/winapi_fixup diff --git a/tools/winapi/winapi_cleanup b/tools/winapi/winapi_cleanup new file mode 100755 index 00000000000..05b50f22797 --- /dev/null +++ b/tools/winapi/winapi_cleanup @@ -0,0 +1,109 @@ +#! /usr/bin/perl -w + +# Copyright 2002 Patrik Stridvall +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +use strict; + +BEGIN { + $0 =~ m%^(.*?/?tools)/winapi/winapi_cleanup$%; + require "$1/winapi/setup.pm"; +} + +use config qw($current_dir $wine_dir); +use output qw($output); +use winapi_extract_options qw($options); + +if($options->progress) { + $output->enable_progress; +} else { + $output->disable_progress; +} + +######################################################################## +# edit_file + +sub edit_file { + my $filename = shift; + my $function = shift; + + open(IN, "< $filename") || die "Can't open file '$filename'"; + open(OUT, "> $filename.tmp") || die "Can't open file '$filename.tmp'"; + + my $result = &$function(\*IN, \*OUT, @_); + + close(IN); + close(OUT); + + if($result) { + unlink($filename); + rename("$filename.tmp", $filename); + } else { + unlink("$filename.tmp"); + } + + return $result; +} + +######################################################################## +# cleanup_file + +sub cleanup_file { + local *IN = shift; + local *OUT = shift; + + my $modified = 0; + + while () { + chomp; + if(s/(.*?)\s+$/$1/) { + $modified = 1; + } + + print OUT "$_\n"; + } + + return $modified; +} + +######################################################################## +# main + +my @h_files = $options->h_files; +my @c_files = $options->c_files; + +my $progress_output; +my $progress_current = 0; +my $progress_max = scalar(@h_files) + scalar(@c_files); + +foreach my $file (@h_files) { + $progress_current++; + $output->progress("$file (file $progress_current of $progress_max)"); + + if (edit_file($file, \&cleanup_file, @_)) { + $output->write("$file: modified\n"); + } +} + +foreach my $file (@c_files) { + $progress_current++; + $output->progress("$file (file $progress_current of $progress_max)"); + + if (edit_file($file, \&cleanup_file, @_)) { + $output->write("$file: modified\n"); + } +} diff --git a/tools/winapi/winapi_cleanup_options.pm b/tools/winapi/winapi_cleanup_options.pm new file mode 100644 index 00000000000..6e889b44b10 --- /dev/null +++ b/tools/winapi/winapi_cleanup_options.pm @@ -0,0 +1,51 @@ +# +# Copyright 2002 Patrik Stridvall +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +package winapi_extract_options; +use base qw(options); + +use strict; + +use vars qw($VERSION @ISA @EXPORT @EXPORT_OK); +require Exporter; + +@ISA = qw(Exporter); +@EXPORT = qw(); +@EXPORT_OK = qw($options); + +use options qw($options &parse_comma_list); + +my %options_long = ( + "debug" => { default => 0, description => "debug mode" }, + "help" => { default => 0, description => "help mode" }, + "verbose" => { default => 0, description => "verbose mode" }, + + "progress" => { default => 1, description => "show progress" }, +); + +my %options_short = ( + "d" => "debug", + "?" => "help", + "v" => "verbose" +); + +my $options_usage = "usage: winapi_cleanup [--help] []\n"; + +$options = '_options'->new(\%options_long, \%options_short, $options_usage); + +1;