home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / xampp / xampp-perl-addon-1.4.9-installer.exe / htmlclean.bat < prev    next >
Encoding:
DOS Batch File  |  2002-11-06  |  3.8 KB  |  171 lines

  1. @rem = '--*-Perl-*--
  2. @echo off
  3. if "%OS%" == "Windows_NT" goto WinNT
  4. perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9
  5. goto endofperl
  6. :WinNT
  7. perl -x -S %0 %*
  8. if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl
  9. if %errorlevel% == 9009 echo You do not have Perl in your PATH.
  10. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul
  11. goto endofperl
  12. @rem ';
  13. #!/usr/local/bin/perl
  14. #line 15
  15. # htmlclean
  16. # Copyright (C) 1998 by ITU
  17.  
  18. use strict;
  19.  
  20. sub usage {
  21.   print STDERR <<END;
  22.  usage: $0 file1 [file2 file3 ...]
  23. END
  24.   exit 1;
  25. }
  26.  
  27. sub print_version {
  28.   my($version) = $HTML::Clean::VERSION;
  29.   print "$0\n\tHTML::Clean::VERSION: $version\n\n";
  30.   exit 0;
  31. }
  32.  
  33. =head1 NAME
  34.  
  35. htmlclean - a small script to clean up existing HTML
  36.  
  37. =head1 SYNOPSIS
  38.  
  39. B<htmlclean [-v] [-V] file1 [file2 file3 ...]>
  40.  
  41. =head1 DESCRIPTION
  42.  
  43. This program provides a command-line interface to the HTML::Clean
  44. module, which can help you to provide more compatible, smaller HTML
  45. files at the expense of reducing the human readability of the HTML
  46. code.  In some cases you may be able to reduce the size of your HTML
  47. by up to 50%!
  48.  
  49. The HTML::Clean library provides a number of features that improve your
  50. HTML for browsing and serving:
  51.  
  52. B<htmlclean> passes each file given on the command line to the library
  53. and writes out the new HTML according to the specified options.  The
  54. default is to create a backup file and replace the file with cleaned HTML.
  55.  
  56. =over 6
  57.  
  58. =item Removing whitespace, Comments and other useless or redundant constructs
  59.  
  60. =item Insuring that font tags work across multiple operating systems
  61.  
  62. =back
  63.  
  64. For full details see the documentations for L<HTML::Clean> itself.
  65.  
  66.  
  67.  
  68. =head1 OPTIONS
  69.  
  70. =over 4
  71.  
  72. =item C<-V>
  73.  
  74. Print the version of the program.
  75.  
  76. =item C<-v>
  77.  
  78. Verbose mode. Print out the original and final file sizes, plus the
  79. compression percent.  For example:
  80.  
  81.   5261   4065 22% /tmp/development-es.html
  82.   5258   4061 22% /tmp/development-fr.html
  83.   4651   3683 20% /tmp/development.html
  84.  
  85. =back
  86.  
  87. =head1 SEE ALSO
  88.  
  89. For the library, see L<HTML::Clean>
  90.  
  91. =head1 AUTHOR
  92.  
  93. C<htmlclean> is written by Paul Lindner, <paul.lindner@itu.int>
  94.  
  95. =head1 COPYRIGHT
  96.  
  97. Copyright (c> 1998 by ITU under the same terms as Perl.
  98.  
  99. =cut
  100.  
  101. usage() if ($#ARGV == -1);
  102. usage() if ($#ARGV >=0 && $ARGV[0] eq '-?');
  103.  
  104.  
  105. use HTML::Clean;
  106. use Getopt::Long;
  107. my (%opts);
  108.  
  109. $Getopt::Long::getopt_compat = 1;   # avoid parsing +'s as options (doesn't work!)
  110. &Getopt::Long::config(qw(no_ignore_case no_getopt_compat));
  111. &GetOptions(\%opts, qw(v V t=s 1 2 3 4 5 6 7 8 9));
  112.  
  113. &print_version if ($opts{'V'});
  114. &usage if ($#ARGV == -1); # we MUST have at least one file
  115.  
  116. my($verbose) = $opts{'v'};
  117. my $level = 9;
  118. foreach my $i (1, 2, 3, 4, 5, 6, 7, 8, 9) {
  119.   $level = $i if ($opts{$i});
  120. }
  121.  
  122. &main($level, \@ARGV);
  123. exit 0;
  124.  
  125. sub main {
  126.   my($level, $files) = @_;
  127.  
  128.   my $h = new HTML::Clean(); # Just a empty holder..
  129.   print_error('initializing...') if (!$h);
  130.   $h->level($level);
  131.  
  132.   foreach my $f (@$files) {
  133.     my $result = $h->initialize($f); 
  134.     print_error($f) if ($result == 0);
  135.  
  136.     my $d = $h->data();
  137.     my $origlen = length($$d);
  138.  
  139.     # add options to control these...
  140.     $h->compat();
  141.     $h->strip();
  142.     
  143.     my $newlen = length($$d);
  144.     my $pct = 0;
  145.     if ($origlen > 0) {
  146.       $pct = (100 * ($origlen - $newlen)) / $origlen;
  147.     }
  148.     printf "%6d %6d %2d%% %s\n", $origlen, $newlen, $pct, $f if ($verbose);
  149.     
  150.     # Okay, now move the files around..
  151.     rename($f, "$f.bak") || die "Cannot rename '$f': $!\n";
  152.     open(output, ">$f") || die "Cannot overwrite '$f': $!\n";
  153.     print output $$d;
  154.     close(output);
  155.   }
  156. }
  157.  
  158.   
  159. sub print_error {
  160.   my($msg) = @_;
  161.   print STDERR <<END;
  162. $0: $msg ($!)
  163. END
  164. exit(1);
  165. }
  166.  
  167.  
  168.  
  169. __END__
  170. :endofperl
  171.