]> granicus.if.org Git - docbook-dsssl/commitdiff
Support multiple filenames on a single run
authorNorman Walsh <ndw@nwalsh.com>
Sun, 29 Dec 2002 14:43:34 +0000 (14:43 +0000)
committerNorman Walsh <ndw@nwalsh.com>
Sun, 29 Dec 2002 14:43:34 +0000 (14:43 +0000)
cvstools/untidy

index 944a31c549c4074a41093b26586ae30a2878ce46..05ca151081df873c6f19e7b3f77b2bced67aeffc 100755 (executable)
@@ -1,27 +1,57 @@
 #!/usr/bin/perl -w -- # -*- Perl -*-
 
-my $filename = pop @ARGV;
-my $opts = join(" ", @ARGV);
+my @filenames = ();
+my $opts = "";
 
-my $content = "";
-
-open (F, "/usr/bin/tidy $opts $filename |");
-while (<F>) {
-    $content .= $_;
+while (@ARGV) {
+    $_ = shift @ARGV;
+    if (@filenames || !/^-/) {
+       push (@filenames, $_);
+    } else {
+       $opts .= " " if $opts ne "";
+       $opts .= $_;
+    }
 }
-close (F);
 
-if ($content eq '') {
-    # we must have done an "in-place" tidy
-    if (open (F, $filename)) {
-       read (F, $content, -s $filename);
+if ($#filenames == 0) {
+    my $filename = shift @filenames;
+    my $content = "";
+
+    open (F, "/usr/bin/tidy $opts $filename |");
+    while (<F>) {
+       $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 =~ s/(<a\s[^>]+>)\s+/$1/sg;
+    $content =~ s/\s+(<\/a>)/$1/sg;
+
+    open (F, ">$filename");
+    print F $content;
+    close (F);
+} else {
+    system ("/usr/bin/tidy $opts " . join(" ", @filenames));
+    foreach my $filename (@filenames) {
+       if (open (F, $filename)) {
+           read (F, $content, -s $filename);
+           close (F);
+       }
+
+       $content =~ s/(<a\s[^>]+>)\s+/$1/sg;
+       $content =~ s/\s+(<\/a>)/$1/sg;
+
+       open (F, ">$filename");
+       print F $content;
        close (F);
     }
 }
 
-$content =~ s/(<a\s[^>]+>)\s+/$1/sg;
-$content =~ s/\s+(<\/a>)/$1/sg;
 
-open (F, ">$filename");
-print F $content;
-close (F);