# # sub system_tidy_xhtml($infile,$outfile) # # Runs tidy on a XHTML file semi-safely (using a secondary file) # Converts HTML to XHTML if necessary # # Arguments: # $htmlfile : The filename to tidy # # Global variables: # $tidycmd : the location of the tidy executable # $tidyconfig : the location of the config file to use # $tidyxhtmlerrors : the filename to use to output errors # $tidysafety: the safety factor to use # # Returns the return value from tidy # Dies horribly if the return value is unexpected # # Expected return codes from tidy: # 0 - no errors # 1 - warnings only (leave errorfile) # 2 - errors (leave errorfile and htmlfile) # sub system_tidy_xhtml { my $infile; my $outfile; my @configopt = (); my $retval; ($infile,$outfile) = @_; die("system_tidy_xhtml called with no input file") if(!$infile); die("system_tidy_xhtml called with no output file") if(!$outfile); @configopt = ('-config',"$datapath/$tidyconfig") if(-f "$datapath/$tidyconfig"); $retval = system($tidycmd,@configopt, '-q','-utf8', '-asxhtml', '--doctype','transitional', '-f',$tidyxhtmlerrors, '-o',$outfile, $infile); # Some systems may return a two-byte code, so deal with that first if($retval >= 256) { $retval = $retval >> 8 }; if($retval == 0) { rename($outfile,$infile) if($tidysafety < 4); unlink($tidyxhtmlerrors); } elsif($retval == 1) { rename($outfile,$infile) if($tidysafety < 3); unlink($tidyxhtmlerrors) if($tidysafety < 2); } elsif($retval == 2) { print STDERR "WARNING: Tidy errors encountered. Check ",$tidyxhtmlerrors,"\n" if($tidysafety > 0); unlink($tidyxhtmlerrors) if($tidysafety < 1); } return $retval; }