#!/usr/local/bin/perl -w
# bbs2web: translate bbs' article to html and insert it to plain text database
#
# written by fcamel 2004/08/03
#
# last update: 2005/05/31
# fixed bug : regexp for
in sprint
#
##############################################################################
#
# fixed bug:
# big5 problem => use perl 5.8.1 or higher's feature (use encoding 'big5')
# hyper link => add RE rule
#
##############################################################################
use strict;
use encoding 'big5'; #, STDIN => 'big5', STDOUT => 'big5';
sub usage
{
print </>/g;
}
return @t;
}
# normal print, simular to print
sub nprint
{
print POUT @_;
}
# space print, output for / +/
sub pprint
{
my $pat = $_[0];
#$pat =~ s/ /$space/g;
nprint $pat;
}
# special print, output some html tags if need
# support:
# hyper link :
# ==+ :
# [note] : colorful
sub sprint
{
my $pat = $_[0];
if ($pat =~ m#(^\S+?://.*)(\s+)(.*)#) {
nprint "";
pprint $1;
nprint "";
pprint $2;
nprint $3;
} elsif ($pat =~ m#(^\S+?://.*)#) {
nprint "";
pprint $1;
nprint "";
} elsif ($pat =~ m#(.*\s+)(.+://.*)(\s+)(.*)#) {
pprint $1;
nprint "";
pprint $2;
nprint "";
pprint $3;
nprint $4;
} elsif ($pat =~ m#(.*\s+)(.+://.*)#) {
pprint $1;
nprint "";
pprint $2;
nprint "";
} elsif ($pat =~ /^==+/) {
nprint "
";
} elsif ($pat =~ /\[note\](.*)/i) {
nprint "[NOTE]";
pprint "$1";
} else {
pprint "$pat";
}
}
# input: ANSI color argus, ex: 1;33;46 (ignore error argument)
# like ANSI color, it won't reset untill you set it, or give no argument
my $isLight = 0; my $fg = 7; my $bg = 16;
sub color
{
my $format = $_[0];
my $hasArgu = 0;
@_ = split /\;/, $format;
nprint "";
foreach (sort @_)
{
if ($_ eq "") { # null field, reset
($isLight, $fg, $bg) = (0, 7, 16);
}
($isLight, $hasArgu) = (1, 1) if $_ eq 1;
($fg, $hasArgu) = ($_%10, 1) if /3\d/;
($bg, $hasArgu) = ($_%10+16, 1) if /4\d/;
}
$fg |= 8 if $isLight;
# check if no argu (reset)
($isLight, $fg, $bg) = (0, 7, 16) if $hasArgu == 0;
nprint "";
}
# output html header and pre-setting
sub header
{
nprint <
TITLE_TO_SUBSTITUDE
EOF
}
# output html tailer and post-setting
sub tailer
{
nprint <
|