From e298097640285ce42929c585ebce9fd4c8e0d1af Mon Sep 17 00:00:00 2001 From: Patrik Stridvall Date: Thu, 12 Sep 2002 20:42:44 +0000 Subject: [PATCH] - Made remove trailing whitespace a default off option. - Add support for C++ to C comment conversion. --- tools/winapi/winapi_cleanup | 80 ++++++++++++++++++++++++-- tools/winapi/winapi_cleanup_options.pm | 5 +- 2 files changed, 80 insertions(+), 5 deletions(-) diff --git a/tools/winapi/winapi_cleanup b/tools/winapi/winapi_cleanup index 05b50f2279..2f61703697 100755 --- a/tools/winapi/winapi_cleanup +++ b/tools/winapi/winapi_cleanup @@ -26,7 +26,7 @@ BEGIN { use config qw($current_dir $wine_dir); use output qw($output); -use winapi_extract_options qw($options); +use winapi_cleanup_options qw($options); if($options->progress) { $output->enable_progress; @@ -66,17 +66,89 @@ sub cleanup_file { local *IN = shift; local *OUT = shift; - my $modified = 0; + my $indent; + my @comments = (); + my $format_comments = sub { + local $_ = ""; + if ($#comments == 0) { + my $comment = $comments[0]; + + $_ = "$indent/*$comment */"; + } elsif ($#comments > 0) { + $_ = "$indent/*\n"; + foreach my $comment (@comments) { + $_ .= "$indent *$comment\n"; + } + $_ .= "$indent */"; + } + $indent = ""; + @comments = (); + return $_; + }; + + my $in_comment = 0; + my $modified = 0; while () { chomp; - if(s/(.*?)\s+$/$1/) { - $modified = 1; + + if ($options->trailing_whitespace) { + s/(.*?)\s+$/$1/ && do { $modified = 1; }; + } else { + s/(.*?)\r$/$1/ && do { $modified = 1; }; + } + + if ($options->cpp_comments) { + if ($in_comment) { + if(/^.*?\*\//) { + $in_comment = 0; + } + } elsif (/^([^\"\/]*?(?:\"[^\"]*?\"[^\"]*?)*?)\/\*(.*?)$/) { + my $indent2 = $1; + my $comment = $2; + if($comment !~ /^.*?\*\//) { + $in_comment = 1; + } + } elsif (/^([^\"\/]*?(?:\"[^\"]*?\"[^\"]*?)*?)\/\/(.*?)\s*$/) { + my $indent2 = $1; + my $comment = $2; + + if ($indent2 =~ /^\s*$/) { + if (!$indent || $indent eq $indent2) { + $indent = $indent2; + push @comments, $comment; + next; + } else { + $_ .= "$indent2/*$comment */"; + } + } else { + my $comments = &$format_comments(); + if ($comments) { + $_ = "$comments\n$indent2/*$comment */"; + } else { + $_ = "$indent2/*$comment */"; + } + + $modified = 1; + } + } else { + my $comments = &$format_comments(); + if ($comments) { + $_ = "$comments\n$_"; + $modified = 1; + } + } } print OUT "$_\n"; } + my $comments = &$format_comments(); + if ($comments) { + print OUT "$comments\n"; + $modified = 1; + } + return $modified; } diff --git a/tools/winapi/winapi_cleanup_options.pm b/tools/winapi/winapi_cleanup_options.pm index 6e889b44b1..c8e261a6a2 100644 --- a/tools/winapi/winapi_cleanup_options.pm +++ b/tools/winapi/winapi_cleanup_options.pm @@ -16,7 +16,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -package winapi_extract_options; +package winapi_cleanup_options; use base qw(options); use strict; @@ -36,6 +36,9 @@ my %options_long = ( "verbose" => { default => 0, description => "verbose mode" }, "progress" => { default => 1, description => "show progress" }, + + "cpp-comments" => { default => 1, description => "converts C++ comments to C comments" }, + "trailing-whitespace" => { default => 0, description => "remove trailing whitespace" }, ); my %options_short = (