From: Norman Walsh Date: Fri, 9 Feb 2007 13:18:15 +0000 (+0000) Subject: Deal with stderr better X-Git-Tag: release/1.79.1~6^2~2277 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b544289da8dcd7fe4bca92dd8181bbac138e1ac2;p=docbook-dsssl Deal with stderr better --- diff --git a/cvstools/untidy b/cvstools/untidy index 8b375e908..57715478e 100755 --- a/cvstools/untidy +++ b/cvstools/untidy @@ -3,6 +3,9 @@ my @filenames = (); my $opts = ""; +my $tmpStdout = "/tmp/tidy.stdout.$$"; +my $tmpStderr = "/tmp/tidy.stderr.$$"; + while (@ARGV) { $_ = shift @ARGV; if (@filenames || !/^-/) { @@ -21,19 +24,25 @@ while (@ARGV) { foreach my $file (@filenames) { my $content = ""; - print STDERR "Tidy $file...\n"; - open (F, "/usr/bin/tidy -wrap 512 $opts $file |"); - while () { - $content .= $_; + system("/usr/bin/tidy -wrap 512 $opts $file > $tmpStdout 2>$tmpStderr"); + if (-s $tmpStderr != 0) { + print STDERR "Tidy $file...\n"; + open (F, $tmpStderr); + while () { + print $_; + } + close (F); } - close (F); - if ($content eq '') { + if (-s $tmpStdout == 0) { # we must have done an "in-place" tidy - if (open (F, $file)) { - read (F, $content, -s $file); - close (F); - } + open (F, $file); + read (F, $content, -s $file); + close (F); + } else { + open (F, $tmpStdout); + read (F, $content, -s $tmpStdout); + close (F); } $content = cleanupContent($content); @@ -43,45 +52,8 @@ foreach my $file (@filenames) { close (F); } -# the old way... -# if ($#filenames == 0) { -# my $filename = shift @filenames; -# my $content = ""; -# -# open (F, "/usr/bin/tidy -wrap 512 $opts $filename |"); -# while () { -# $content .= $_; -# } -# close (F); -# -# if ($content eq '') { -# # we must have done an "in-place" tidy -# if (open (F, $filename)) { -# read (F, $content, -s $filename); -# close (F); -# } -# } -# -# $content = cleanupContent($content); -# -# open (F, ">$filename"); -# print F $content; -# close (F); -# } else { -# system ("/usr/bin/tidy -wrap 512 $opts " . join(" ", @filenames)); -# foreach my $filename (@filenames) { -# if (open (F, $filename)) { -# read (F, $content, -s $filename); -# close (F); -# } -# -# $content = cleanupContent($content); -# -# open (F, ">$filename"); -# print F $content; -# close (F); -# } -# } +unlink $tmpStdout; +unlink $tmpStderr; sub cleanupContent { my $content = shift; @@ -107,6 +79,26 @@ sub cleanupContent { $content = $post; } + $content = $newContent . $content; + $newContent = ""; + + while ($content + =~ /^(.*?)(]+text\/javascript.*?>\s*\/\/.*)$/is) { + my $pre = $1; + my $scripttag = $2; + my $script = $3; + my $post = $4; + + # belt and suspenders is both unnecessary ... and WRONG + $script =~ s/\<//sg; + $script =~ s/\&/\&/sg; + + $newContent .= $pre . $scripttag . $script; + + $content = $post; + } + return $newContent . $content; }