updated git and svn scripts
[xrzperl.git] / html2unix
blobc76bda7e1f170054b07608f45544d03b437afd8f
1 #!/usr/bin/perl -w
2 ###APPNAME: html2unix
3 ###APPAUTHOR: xiaoranzzz
4 ###APPDATE: Wed Apr 28 02:26:38 2010
5 ###APPVER: 0.1
6 ###APPDESC: html2unix convert \"href\" \"src\" to lowercase
7 ###APPUSAGE:
8 ###APPEXAMPLE: html2unix
9 ###APPOPTION:
10 use strict;
12 #ENV variable MUST be defined somewhere,
13 #FOR perl to search modules from,
14 #OR nothing will work
15 use lib $ENV{XR_PERL_MODULE_DIR};
17 use MyPlace::Script::Usage qw/help_required help_even_empty/;
18 #exit 0 if(help_required($0,@ARGV));
19 exit 0 if(help_even_empty($0,@ARGV));
20 use HTML::TreeBuilder;
23 sub lc_links {
24 my $tree = shift;
25 foreach my $attr (qw/src href/) {
26 my @elms = $tree->look_down($attr,qr/./);
27 map {$_->attr($attr,lc($_->attr($attr)))} @elms;
29 return $tree;
32 foreach my $file (@ARGV) {
33 if($file eq '-') {
34 my $tree = HTML::TreeBuilder->new_from_content(<STDIN>);
35 lc_links($tree);
36 print FO $tree->as_HTML();
37 $tree->delete();
39 elsif(-f $file and $file =~ m/\.(?:html|htm|xml|xhtml)$/) {
40 print STDERR "Converting $file...";
41 my $tree = HTML::TreeBuilder->new_from_file($file);
42 lc_links($tree);
43 open FO,">".$file or die("$!\n");
44 print FO $tree->as_HTML();
45 close FO;
46 $tree->delete();
47 print STDERR "\t [OK]\n";
49 else {
50 print STDERR "\"$file\" Ingored.\n";