#**************************************************************************************** # §module FixXHTMLTags #---------------------------------------------------------------------------------------- # §description Fixes the missing end of html tags (nowrap -> nowrap="nowrap",
-> br/> #**************************************************************************************** require 5.000; require Exporter; use Config; use strict; use Cwd; use Getopt::Long; use Util::Output qw( InitOutput PrintData PrintDebugData PrintError PrintMessage ); use Util::Files qw( GetFileList ReadFile WriteFile ); use Util::ClearCase qw( CheckoutElements ); my @tags = ( { 'name' => '\bselected\s*[^="]', replacement => 'selected="selected"' }, { 'name' => '\breadonly\s*[^="]', replacement => 'readonly="readonly"' }, { 'name' => '\bchecked\s*[^="]', replacement => 'checked="checked"' }, { 'name' => '\bdisabled\s*[^="]', replacement => 'disabled="disabled"' }, { 'name' => '\bnowrap\s*[^="]', replacement => 'nowrap="nowrap"' }, { 'name' => '\bnoresize\s*[^="]', replacement => 'noresize="noresize"' }, { 'name' => '\bcompact\s*[^="]', replacement => 'compact="compact"' }, { 'name' => '\bdeclare\s*[^="]', replacement => 'declare="declare"' }, { 'name' => '\bdefer\s*[^="]', replacement => 'defer="defer"' }, { 'name' => '\bismap\s*[^="]', replacement => 'ismap="ismap"' }, { 'name' => '\bnohref\s*[^="]', replacement => 'nohref="nohref"' }, { 'name' => '\bnoshade\s*[^="]', replacement => 'noshade="noshade"' }, { 'name' => '\bmultiple\s*[^="]', replacement => 'multiple="multiple"' }, ); #======================================================================================== # §function Usage #---------------------------------------------------------------------------------------- # §syntax Usage( ) #---------------------------------------------------------------------------------------- # §description prints information about program parameters #---------------------------------------------------------------------------------------- # §ret always 1 #======================================================================================== sub Usage { print <<'USAGE'; Use FixXHTMLTags Directory where the Parameters are: Directory: Path to search in to search in all isml files and replaces the wrong tags. USAGE return 1; } #======================================================================================== # §function Main # #---------------------------------------------------------------------------------------- # §description control function #---------------------------------------------------------------------------------------- # # §ret 0 for ok, else error number #======================================================================================== sub Main { my $dir; my %params; my $files; my $file; my $content; my $countFiles; my $countInFile; my $found; my $tag; my $line; my $counter; print "Handling templates...\n"; print " Check Parameters...\n"; $dir = $ARGV[0]; if ( $dir eq '.' ) { $dir = cwd(); } $dir =~ s/\\/\//g; if ( ! -d $dir ) { Usage(); print "$dir could not be found.\n"; return 1; } print " ...ok\n"; print " Searching for files...\n"; $files = GetFileList( $dir, ".isml", 1, 1 ); if ( ! defined $files ) { return 2; } print " Found " . scalar @$files . " files\n"; print " ...ok\n"; print " Searching in files...\n"; $countFiles = 0; NEXTFILE: foreach $file ( @$files ) { print " $file...\n"; if ( ! open FILE, $file ) { print "Could not open $file for read purposes: $!."; next; } $content = join '', ; close FILE; $file =~ s/\//\\/g; $found = 0; $counter = 1; foreach $line ( split "\n", $content ) { foreach $tag ( @tags ) { if ( $line =~ /$tag->{'name'}/ ) { # if ( ! -w $file ) # { # print " Checking out...\n"; # my $return = CheckoutElements( [ $file ] ); # if ( ! defined $return ) { # print "Failed checking out '$file'.\n"; # next NEXTFILE; # } # if ( ! open FILE, $file ) { # print "Could not open $file for read purposes: $!."; # return 3; # } # $content = join '', ; # close FILE; # } print " $counter: $tag->{'name'}: $line\n"; $found = 1; } } $counter++; } # if ( $found ) { # print " Changing...\n"; # foreach $tag ( @tags ) { # $content =~ s/\b$tag->{'name'}\s*\(/$tag->{'replacement'}\(/g; # } # if ( ! open FILE, ">$file" ) { # print "Could not open $file for write purposes: $!."; # next; # } # print FILE $content; # close FILE; # } } print " Found $countFiles files\n"; print " ...ok\n"; print "...ok\n"; return 0; } exit( Main( $ARGV[0] ) ); 1;