-> [Go to the download page] -> [Download Now]
@rem = ('--*-Perl-*-- @echo off if exist %0.bat perl %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 if not exist %0.bat perl -S %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9 goto exit ') if 0; #!/usr/local/bin/perl # # File Name: "t2hp.bat" - Text TO xHtml Parts BATch for perl # # Copyright: Public Domain Software (NOT TO BE SHAREWARE OR FREEWARE) # # Version (??: secondary series; can be revised by somebodies) # *.*?? by *** May be revised for something # # Version (ps: primary series; reserved for S. ) # 1.?ps by S. Revised to support additional documents. # 1.?ps by S. Revised to generate XHTML documents. # 1.0ps by S. Created for perl4 or later version. # # Related Softwares (required): # # - perl 5, version 16, subversion 3 (v5.16.3) built for MSWin32-x64-multi-thread (freeware, 64bit) # http://www.activestate.com/activeperl/downloads # http://downloads.activestate.com/ActivePerl/releases/5.16.3.1603/ActivePerl-5.16.3.1603-MSWin32-x64-296746.msi # (used: "perl.exe" and "perl516.dll") # sub: Smart Include sub sinc { local($subin, *stab) = @_; local($key, $val, $eval = ''); if (-s $subin) { if (%stab) { foreach $key (keys %stab) { $val = eval($stab{$key}); if ($val ne '') { $key =~ s/([^\w\s])/\\$1/g; $val =~ s/([^\w\s])/\\$1/g; $eval .= "s/$key/$val/g;\n"; } } } open(SUBIN, $subin) || die "Can't open \"$subin\": $!\a\n"; while (<SUBIN>) { eval($eval); print; } } } # main: Setup { if ($ARGV[0] =~ /^(-h|--help)$/) { print <<'EOD'; Usage: t2hp [-h|--help] [-omd:N] [-tab:N] [-phf:PHF] [-shf:SHF] [">OHF"] [ITF..] -omd:0 Operation Mode for IE with Tabs to Spaces conversion -omd:1 Operation Mode for IE/Firefox (default) -omd:2 Operation Mode for IE/Opera -tab:N Tab Size N (default:8, with -omd:0 operator) PHF: Prefix XHTML File SHF: Suffix XHTML File OHF: Output XHTML File ITF: Input Text Files e.g. t2hp -omd:0 -tab:8 ">out.htm" in1.txt in2.txt e.g. t2hp -omd:1 -phf:pre.htm -shf:suf.htm ">out.htm" in1.txt EOD exit; } $omd = 1; # default Operation Mode @ARGV = grep(/^-omd:?(.*)/ ? ($omd = $1, 0) : 1, @ARGV); $tab = 8; # default Tab Size @ARGV = grep(/^-tab:(.+)/ ? ($tab = $1, 0) : 1, @ARGV); $phf = ''; # default Prefix XHTML File @ARGV = grep(/^-phf:?(.*)/ ? ($phf = $1, 0) : 1, @ARGV); $shf = ''; # default Suffix XHTML File @ARGV = grep(/^-shf:?(.*)/ ? ($shf = $1, 0) : 1, @ARGV); $outfile = '>-'; # default: STDOUT @ARGV = grep(/^>/ ? ($outfile = $_, 0) : 1, @ARGV); open(STDOUT, $outfile) || die "Can't open \"$outfile\": $!\a\n"; $ohf = $outfile eq '>-' ? 'STDOUT' : $outfile; $ohf =~ s/^>\s*(.*[\/\\:])?//; # Output XHTML File name $oht = 'No Title'; # default Output XHTML Title name $stab{'{$t2hp.filename}'} = '$ohf'; # Substitute Table $stab{'{$t2hp.title}'} = '$oht'; # Substitute Table } # main: Main Routine { $apmk = '>'.'__A_P_P_E_N_D__'.'>'; # Append Mark $oseq = 0; # Output Sequence $obuf = ''; # Output Buffer $lcnt = 10; # Line Count $id = ''; # Link ID $cont = ''; # Contents List $stat = 0; # Prefix Status $pref = "\n"; # Prefix String $n = ''; # New Line Control if ($omd > 1) { $n = "\n"; print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">', "\n"; } while (($_ = <ARGV>) ne '') { # $obuf .= '<!-- start of XHTML parts --><div class="pds" style="border:solid 1px;padding:0 0.5em;font-family:monospace">' if $. == 1; ;; $obuf .= '<!-- start of XHTML parts --><div class="pds" style="border:solid 0px;padding:0 0.5em;font-family:monospace">' if $. == 1; # next if /^!/; # Comment Line s/&/&/g; s/</</g; s/>/>/g; 1 while !$omd && s/\t+/' ' x (length($&) * $tab - length($`) % $tab)/e; # Tabs to Spaces $oseq++ if $oseq == 0 && (/^([:#]*\s*Subject:|[:#]+\s*File Name:|help ")\s*(.*)/ && ($oht = $2) || $. >= $lcnt || eof()); s!\[img\]([^[]*)\[/img\]!<a href="$1" target="_blank"><img src="$1" alt="[img]$1[/img]" /></a>!g; s/>>/$apmk/g; s!\b((https?|ftp)://[^\s"'>]+)!<a href="$1" target="_blank">$1</a>!g; s/$apmk/>>/g; s!(\w[\w.-]*@\w[\w.-]*\.\w+)!<a href="mailto:$1">$1</a>!g; if (/^\$\s*([\d.]*\d)/) { $id = $1; $id =~ s/\./_/g; chop; s/ / /g; $cont .= "\n<h3><a href=\"#sect$id\" id=\"cont$id\" name=\"cont$id\">$_</a></h3>"; $pref = $omd && $stat ? "$n</pre>" : "\n"; $_ = "$pref<h3><a href=\"#cont$id\" id=\"sect$id\" name=\"sect$id\">$_</a></h3>"; $stat = 0; } elsif (/^(Subject|Title):/) { chop; s/ / /g; $pref = $omd && $stat ? "$n</pre>" : "\n"; $_ = "$pref<h2>$_</h2>"; $stat = 0; } else { chop; if (!$omd) { s/ / /g; s/^ / /; } $pref = ''; $pref = '<pre>' if $omd && !$stat; $pref = '<br />' if !$omd && $stat; $_ = "$pref\n$_"; $stat = 1; } if ($oseq == 0) { $obuf .= $_; } elsif ($oseq == 1) { $obuf .= $_; &sinc($phf, *stab); print $obuf; $obuf = ''; $oseq++; } else { print; } if (eof()) { if (!$stat) { print "\n"; } elsif ($omd) { print "\n</pre>\n"; } elsif (!$cont) { print "<br />\n"; } print '<h2>Contents</h2>', $cont, "\n" if $cont; print <<'EOD'; </div><div style="font-size:90%"> /* Copyright: Public Domain (free contents) for the contents in the just above element. */<br /> /* Everyone can copy, revise and distribute/publish the contents in the just above element. */<br /> /* Everyone can copy, paste, save and use the contents in the just above element. */<br /> </div><!-- end of XHTML parts --> EOD } } &sinc($phf, *stab) if $oseq == 0; &sinc($shf, *stab); } @rem = (' :exit ') if 0;