#!/usr/local/bin/perl -- # -*- Perl -*-
#
# forhtml.pl: HTML formatter
#
# [1996/05/28] OSHIRO Naoki.
# [1997/06/28] OSHIRO Naoki.
# ヘッダ部でもリンクを表示するようにした.
# [1997/06/29] OSHIRO Naoki.
# リンク表示で改行を入れられるようにした.
#
# $Log:$
#
#
# To use:
# please use after notation on first line of list file
# or argment of call forhtml.
#
# # FORHTML: title, body_title, email, [\@heading_image,] links...
#
# links means := url, title, url, title,...
#
package forhtml;
$date=&ctime(time);
$com_name=&main'basename($0);
$title="HTML generated by $com_name";
$heading_image="";
$body_title="なんちゃらりすと";
$email="";
@links=();
sub main'forhtml {
local($_)=@_;
unless (/^#\s*FORHTML:\s*/i) {
print "Error: Please HTML making infomation put first line of file.\n";
print " like this '# FORHTML: title, body_title, email, [\@heading_image,] links'\n";
return 0;
}
@links=split('\s*[,]\s*', $');
$title=shift(@links);
$body_title=shift(@links);
$heading_image=shift(@links) if ($links[0]=~s/^@//);
$email=shift(@links);
return 1;
}
sub main'print_header {
local($body_opt)=@_;
print "\n";
print "\n";
print "\n";
print "\n";
# print "\n";
print "\n";
print "
\n";
print "\n";
print "$title\n";
print "\n";
print "\n";
print "\n";
if (!$body_opt) {
print "\n";
} else {
print "\n";
}
print "\n";
print "
\n" if ($heading_image);
print "$body_title\n";
print "
\n";
print "最終更新: [$date]\n";
print "\n";
print "
\n";
print "\n";
&print_links(@links);
}
sub main'print_footer {
print "\n
\n";
&print_links(@links);
if ($email ne '') {
print "\n";
print "\n";
print "Mail-to:\n";
print "\n";
print "$email\n";
print "\n";
print "\n";
print "\n";
}
print "\n";
print "\n";
}
sub print_links {
local(@links)=@_;
if (@links) {
print "\n";
print "||\n";
for ($i=0; $i<$#links; $i+=2) {
if ($links[$i]=~/\\n/) { # [1997/06/29] OSHIRO Naoki.
print "
\n||";
$i++;
}
if ($links[$i] ne "") {
print "\n";
print "$links[$i+1]||\n";
} else {
print "$links[$i+1]||\n";
}
}
print "\n";
print "
\n";
print "\n";
}
}
sub ctime {
package ctime;
local($time) = @_;
local($date);
local($[) = 0;
local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst);
local(@DoW, @MoY);
@DoW = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat');
@MoY = ('Jan','Feb','Mar','Apr','May','Jun',
'Jul','Aug','Sep','Oct','Nov','Dec');
# Determine what time zone is in effect.
# Use GMT if TZ is defined as null, local time if TZ undefined.
# There's no portable way to find the system default timezone.
$TZ = defined($ENV{'TZ'}) ? ( $ENV{'TZ'} ? $ENV{'TZ'} : 'GMT' ) : '';
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
($TZ eq 'GMT') ? gmtime($time) : localtime($time);
# Hack to deal with 'PST8PDT' format of TZ
# Note that this can't deal with all the esoteric forms, but it
# does recognize the most common: [:]STDoff[DST[off][,rule]]
if($TZ=~/^([^:\d+\-,]{3,})([+-]?\d{1,2}(:\d{1,2}){0,2})([^\d+\-,]{3,})?/){
$TZ = $isdst ? $4 : $1;
}
$TZ .= ' ' unless $TZ eq '';
$year += ($year < 70) ? 2000 : 1900;
$_=sprintf("%4d/%02d/%02d", $year, $mon+1, $mday);
$_.=" $TZ" if ($TZ);
return $_;
}
sub main'basename {
local($_)=@_;
$_=$1 if m#([^/]+/)\s*$#;
$_=$1 if m#([^/]+)(\.s?html?)?\s*$#;
s/\.s?html?//;
return $_;
}
1;