@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.0ps by S.	Created for perl4 or later version
#
# Related Softwares (required):
#
# - perl 5, version 12, subversion 2 (v5.12.2) built for MSWin32-x64-multi-thread (freeware, 64bit)
#   http://www.activestate.com/activeperl/downloads
#   http://downloads.activestate.com/ActivePerl/releases/5.12.2.1202/ActivePerl-5.12.2.1202-MSWin32-x64-293621.msi

{
	if ($ARGV[0] =~ /^(-h|--help)$/) {
		print "Usage: t2hp [-h|--help] [\">OUTFILE\"] [INFILES ..]\n";
		exit;
	}
	$outfile = '>-';	# default: STDOUT
	@ARGV = grep(/^>/ ? ($outfile = $_, 0) : 1, @ARGV);
	open(STDOUT, $outfile) || die "Can't open \"$outfile\": $!\a\n";
}
{
	$cont = '';
	print "<div class=\"pds\" style=\"border:solid 1px;padding:0 0.5em\"><pre>";
	while (<>) {
#		next if /^!/;	# comment line
		s/&/&amp;/g;
		s/</&lt;/g;
		s/>/&gt;/g;
		s!\b((https?|ftp)://\S+)!<a href="$1" target="_blank">$1</a>!g;
		s!(\w[\w.-]*@\w[\w.-]*)!<a href="mailto:$1">$1</a>!g;
		if (/^\$\s*([\d.]*\d)/) {
			$id = $1;
			$id =~ s/\./_/g;
			chop;
			s/  / &nbsp;/g;
			$cont .= "\n<h3><a href=\"#sect$id\" id=\"cont$id\" name=\"cont$id\">$_</a></h3>";
			$_ = "</pre><h3><a href=\"#cont$id\" id=\"sect$id\" name=\"sect$id\">$_</a></h3><pre>";
		} elsif (/^(Subject|Title):/) {
			chop;
			s/  / &nbsp;/g;
			$_ = "\n<h2>$_</h2>";
		} else {
			chop;
			$_ = "\n$_";
		}
		print;
	}
	print "\n</pre>";
	print "\n<h3>Contents</h3>$cont" if $cont;
	print "\n/* Copyright: Public Domain (free contents) for the inside of this border. */<br />";
	print "\n/* Everyone can copy, revise and distribute/publish the contents in the inside of this border. */<br />";
	print "\n</div>\n";
}

@rem = ('
:exit ') if 0;
/* Copyright: Public Domain (free contents) for the inside of this border. */
/* Everyone can copy, revise and distribute/publish the contents in the inside of this border. */