From: rjung Date: Sun, 8 May 2011 12:20:33 +0000 (+0000) Subject: Stylistic improvements to MIME type sync script. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=97bb0f11f6828c158ca8dfe94dc98db5791021a1;p=tomcat7.0 Stylistic improvements to MIME type sync script. Based on a patch provided by Felix Schumacher. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@1100724 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/res/scripts/check-mime.pl b/res/scripts/check-mime.pl index f5ce06bce..d1d625ae4 100755 --- a/res/scripts/check-mime.pl +++ b/res/scripts/check-mime.pl @@ -60,7 +60,7 @@ use Getopt::Std; ################### BEGIN VARIABLES WHICH MUST BE MAINTAINED ##################### # Script version, printed via getopts with "--version" -$main::VERSION = '1.0'; +our $VERSION = '1.1'; # Locale used via LC_COLLATE when sorting extensions my $LOCALE = 'en.UTF-8'; @@ -137,13 +137,19 @@ my $tomcat_pre; my $tomcat_post; # Helper variables my $i; my $line; -my @cols; +my $mimetype; +my @extensions; my $extension; my $type; my $comment; my $commented; -my $check; my $msg; +my $previous; +my $current; +# File handles +my $mimetypes_fh; +my $webxml_fh; +my $output_fh; # Usage/Help @@ -163,7 +169,7 @@ sub HELP_MESSAGE { # -o: output web.xml file (gets generated and overwritten) $Getopt::Std::STANDARD_HELP_VERSION = 1; -our($opt_m, $opt_i, $opt_o); +our ($opt_m, $opt_i, $opt_o); getopts('m:i:o:'); @@ -178,33 +184,33 @@ if ($opt_m eq '' || $opt_i eq '' || $opt_o eq '') { setlocale(LC_COLLATE, $LOCALE); # Read and parse httpd mime.types, build up hash extension->mime-type -open(MIMETYPES, "<$opt_m") or die "Could not open file '$opt_m' for read - Aborting!"; -while () { +open($mimetypes_fh, '<', $opt_m) or die "Could not open file '$opt_m' for read - Aborting!"; +while (<$mimetypes_fh>) { chomp($_); $line = $_; $line =~ s/#.*//; $line =~ s/^\s+//; if ($line ne '') { - @cols = split(/\s+/, $line); - if ($#cols > 0) { - for ($i=1; $i <= $#cols; $i++) { - $httpd{$cols[$i]} = $cols[0]; + ($mimetype, @extensions) = split(/\s+/, $line); + if (@extensions > 0) { + for $extension (@extensions) { + $httpd{$extension} = $mimetype; } } else { print STDERR "WARN mime.types line ignored: $_\n"; } } } -close(MIMETYPES); +close($mimetypes_fh); # Read and parse web.xml, build up hash extension->mime-type # and store the file parts form before and after mime mappings. -open(WEBXML, "<$opt_i") or die "Could not open file '$opt_i' for read - Aborting!"; +open($webxml_fh, '<', $opt_i) or die "Could not open file '$opt_i' for read - Aborting!"; # Skip and record all lines before the first mime type definition. # Because of comment handling we need to read one line ahead. $line = ''; -while () { +while (<$webxml_fh>) { if ($_ !~ //) { $tomcat_pre .= $line; } else { @@ -231,12 +237,12 @@ if ($line =~ /^\s*\s*$/) { $comment = $1; - $_ = ; + $_ = <$webxml_fh>; chomp($_); } if ($_ =~ /^\s*([^<]*)<\/extension>\s*$/ ) { @@ -246,10 +252,10 @@ while ($_ =~ /^\s*\s*$/) { } else { print STDERR "ERROR Parse error in Tomcat mime-mapping line $.\n"; print STDERR "ERROR Expected ...', got '$_' - Aborting!\n"; - close(WEBXML); + close($webxml_fh); exit 2; } - $_ = ; + $_ = <$webxml_fh>; chomp($_); if ($_ =~ /^\s*([^<]*)<\/mime-type>\s*$/ ) { $type = $1; @@ -272,28 +278,28 @@ while ($_ =~ /^\s*\s*$/) { } else { print STDERR "ERROR Parse error in Tomcat mime-mapping line $.\n"; print STDERR "ERROR Expected ...', got '$_' - Aborting!\n"; - close(WEBXML); + close($webxml_fh); exit 3; } - $_ = ; + $_ = <$webxml_fh>; chomp($_); if ($_ !~ /^\s*<\/mime-mapping>\s*$/) { print STDERR "ERROR Parse error in Tomcat mime-mapping line $.\n"; print STDERR "ERROR Expected '', got '$_' - Aborting!\n"; - close(WEBXML); + close($webxml_fh); exit 4; } - $_ = ; + $_ = <$webxml_fh>; # Check for comment closure if ($commented && $_ =~ /^[^<]*-->\s*$/) { $commented = 0; - $_ = ; + $_ = <$webxml_fh>; } # Check for comment opening if ($_ =~ /^\s*\n"; + print $output_fh " \n"; } - print NEW " $extension\n"; - print NEW " $httpd{$extension}\n"; - print NEW " \n"; + print $output_fh " $extension\n"; + print $output_fh " $httpd{$extension}\n"; + print $output_fh " \n"; if (exists($tomcat_commented{$extension})) { - print NEW " -->\n"; + print $output_fh " -->\n"; } } -print NEW $tomcat_post; -close(NEW); +print $output_fh $tomcat_post; +close($output_fh); print "New file '$opt_o' has been written.\n"; diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index d90c131ad..913ea74f1 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -42,6 +42,16 @@ General, Catalina, Coyote, Jasper, Cluster, Web applications, Extras, Tribes, Other --> +
+ + + + Stylistic improvements to MIME type sync script. + Based on a patch provided by Felix Schumacher. (rjung) + + + +