2002-08-29 01:42:57 +02:00
|
|
|
#! /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";
|
|
|
|
}
|
|
|
|
|
2003-01-03 04:05:41 +01:00
|
|
|
use config qw($current_dir $wine_dir file_absolutize file_directory);
|
2002-08-29 01:42:57 +02:00
|
|
|
use output qw($output);
|
2002-09-12 22:42:44 +02:00
|
|
|
use winapi_cleanup_options qw($options);
|
2002-08-29 01:42:57 +02:00
|
|
|
|
2003-01-03 04:05:41 +01:00
|
|
|
use nativeapi qw($nativeapi);
|
2002-10-01 20:10:54 +02:00
|
|
|
use util qw(edit_file);
|
|
|
|
|
2002-08-29 01:42:57 +02:00
|
|
|
if($options->progress) {
|
|
|
|
$output->enable_progress;
|
|
|
|
} else {
|
|
|
|
$output->disable_progress;
|
|
|
|
}
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
# cleanup_file
|
|
|
|
|
2004-10-26 02:12:21 +02:00
|
|
|
sub cleanup_file($$$) {
|
2002-08-29 01:42:57 +02:00
|
|
|
local *IN = shift;
|
|
|
|
local *OUT = shift;
|
|
|
|
|
2003-01-03 04:05:41 +01:00
|
|
|
my $file = shift;
|
|
|
|
my $dir = do {
|
|
|
|
my $file2 = file_absolutize($file);
|
|
|
|
my $dir = file_directory($file2);
|
|
|
|
"$wine_dir/$dir";
|
|
|
|
};
|
|
|
|
|
2002-09-12 22:42:44 +02:00
|
|
|
my $indent;
|
|
|
|
my @comments = ();
|
|
|
|
my $format_comments = sub {
|
|
|
|
local $_ = "";
|
|
|
|
if ($#comments == 0) {
|
|
|
|
my $comment = $comments[0];
|
2004-10-26 02:12:21 +02:00
|
|
|
|
|
|
|
$_ = "$indent/*$comment */";
|
2002-09-12 22:42:44 +02:00
|
|
|
} elsif ($#comments > 0) {
|
|
|
|
$_ = "$indent/*\n";
|
|
|
|
foreach my $comment (@comments) {
|
|
|
|
$_ .= "$indent *$comment\n";
|
|
|
|
}
|
|
|
|
$_ .= "$indent */";
|
|
|
|
}
|
|
|
|
$indent = "";
|
|
|
|
@comments = ();
|
|
|
|
|
|
|
|
return $_;
|
|
|
|
};
|
2002-08-29 01:42:57 +02:00
|
|
|
|
2002-09-12 22:42:44 +02:00
|
|
|
my $in_comment = 0;
|
|
|
|
my $modified = 0;
|
2002-08-29 01:42:57 +02:00
|
|
|
while (<IN>) {
|
|
|
|
chomp;
|
2002-09-12 22:42:44 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2002-08-29 01:42:57 +02:00
|
|
|
}
|
|
|
|
|
2003-01-03 04:05:41 +01:00
|
|
|
if ($options->include_quotes) {
|
|
|
|
my $module = "";
|
2004-08-31 03:10:08 +02:00
|
|
|
if ($dir =~ m%^$wine_dir/(?:windows)$%) {
|
2003-01-03 04:05:41 +01:00
|
|
|
$module = "user";
|
|
|
|
} elsif ($dir =~ m%^$wine_dir/dlls/(.*?)/.*?$%) {
|
|
|
|
$module = $1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (/^(\s*\#\s*include\s+)(?:<(.*?)>|\"(.*?)\")(.*?)\s*$/) {
|
|
|
|
my $prefix = $1;
|
|
|
|
my $header = $2 || $3;
|
|
|
|
my $local = !defined($2) && defined($3);
|
|
|
|
my $suffix = $4;
|
|
|
|
|
|
|
|
my $exists_system = 0; {
|
|
|
|
my @system_paths = qw(/usr/include /usr/local/include /usr/X11R6/include);
|
|
|
|
foreach my $path (@system_paths) {
|
|
|
|
$exists_system ||= (-e "$path/$header" || 0);
|
|
|
|
}
|
|
|
|
$exists_system ||= $nativeapi->is_conditional_header($header);
|
|
|
|
}
|
|
|
|
|
|
|
|
my $exists_windows = 0; {
|
|
|
|
if ($header !~ m%^wine/% && $header ne "config.h") {
|
|
|
|
$exists_windows ||= (-e "$wine_dir/include/$header" || 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my $exists_wine = 0; {
|
|
|
|
$exists_wine ||= ($header eq "config.h");
|
|
|
|
|
|
|
|
if ($header =~ m%^wine/%) {
|
|
|
|
$exists_wine ||= (-e "$wine_dir/include/$header" || 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my $exists_local = 0; {
|
|
|
|
$exists_local ||= ($header eq "y.tab.h");
|
|
|
|
|
|
|
|
my @local_paths = ();
|
|
|
|
push @local_paths, "$dir" if $dir !~ m%^$wine_dir/include%;
|
|
|
|
push @local_paths, "$wine_dir/dlls/$module" if $module;
|
|
|
|
foreach my $path (@local_paths) {
|
|
|
|
$exists_local ||= (-e "$path/$header" || 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$exists_system && !$exists_windows && !$exists_wine && !$exists_local) {
|
|
|
|
$output->write("warning: header '$header': doesn't exist\n");
|
|
|
|
} elsif (($exists_system + $exists_windows + $exists_wine + $exists_local) > 1) {
|
|
|
|
if ($header !~ /^(?:async\.h|comcat\.h|sql(?:ext|types)?\.h|thread\.h|user\.h)$/) {
|
|
|
|
$output->write("warning: header '$header': more than one possibillity\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$local && $exists_local) {
|
|
|
|
$_ = "$prefix\"$header\"$suffix";
|
|
|
|
$modified = 1;
|
|
|
|
} elsif ($local && !$exists_local && ($exists_system || $exists_windows || $exists_wine)) {
|
|
|
|
$_ = "$prefix<$header>$suffix";
|
|
|
|
$modified = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-08-29 01:42:57 +02:00
|
|
|
print OUT "$_\n";
|
|
|
|
}
|
|
|
|
|
2002-09-12 22:42:44 +02:00
|
|
|
my $comments = &$format_comments();
|
|
|
|
if ($comments) {
|
|
|
|
print OUT "$comments\n";
|
|
|
|
$modified = 1;
|
|
|
|
}
|
|
|
|
|
2002-08-29 01:42:57 +02:00
|
|
|
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)");
|
2003-01-03 04:05:41 +01:00
|
|
|
$output->prefix("$file: ");
|
2002-08-29 01:42:57 +02:00
|
|
|
|
2003-01-03 04:05:41 +01:00
|
|
|
if (edit_file($file, \&cleanup_file, @_, $file)) {
|
2002-08-29 01:42:57 +02:00
|
|
|
$output->write("$file: modified\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach my $file (@c_files) {
|
|
|
|
$progress_current++;
|
|
|
|
$output->progress("$file (file $progress_current of $progress_max)");
|
2003-01-03 04:05:41 +01:00
|
|
|
$output->prefix("$file: ");
|
2002-08-29 01:42:57 +02:00
|
|
|
|
2003-01-03 04:05:41 +01:00
|
|
|
if (edit_file($file, \&cleanup_file, $file)) {
|
2002-08-29 01:42:57 +02:00
|
|
|
$output->write("$file: modified\n");
|
|
|
|
}
|
|
|
|
}
|