mirror of
https://github.com/reactos/wine.git
synced 2024-11-29 06:30:37 +00:00
- Made remove trailing whitespace a default off option.
- Add support for C++ to C comment conversion.
This commit is contained in:
parent
ee3fdd8038
commit
e298097640
@ -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 (<IN>) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -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 = (
|
||||
|
Loading…
Reference in New Issue
Block a user