based on bin/text.pl
# $Id: html.pl,v 1.1.1.7 2001/11/30 07:06:25 toshi Exp $
#
if (shift(@ARGV) =~ /j/) {
$jmode = 1;
} else {
$jmode = 0;
}
if (!@ARGV[0]) {
exit 2;
}
$filename = @ARGV[0];
for ($i = 0; $i < 30; $i++) {
$fbsdnum0{$i} = 0;
$fbsdnum1{$i} = 0;
$fbsdidx{$i} = $i;
}
# 1st pass
open(INPUT, $filename);
make_html(0);
# sorting by greater order
for ($i = 0; $i < $fbsdcount; $i++) {
for ($j = $i+1; $j < $fbsdcount; $j++) {
if ($fbsdrels{$fbsdidx{$i}} lt $fbsdrels{$fbsdidx{$j}}) {
$k = $fbsdidx{$i};
$fbsdidx{$i} = $fbsdidx{$j};
$fbsdidx{$j} = $k;
}
}
}
# output html header
print_head(STDOUT, 0, "");
for ($i = 0; $i < $fbsdcount; $i++) {
open_fbsdrel($i, 1);
print_head(RELOUT, $i+1, $fbsdrels{$i});
close(RELOUT);
}
# 2nd pass
seek(INPUT, 0, 0);
make_html(1);
close(INPUT);
# output html footer
print_tail(STDOUT);
for ($i = 0; $i < $fbsdcount; $i++) {
open_fbsdrel($i, 0);
print_tail(RELOUT);
close(RELOUT);
}
# output index
make_index();
sub make_html
{
local($pass) = @_;
while () {
if (/^\)ITEM$/) {
$name = $item{1};
$addr = $item{2};
$mcn = $item{3};
$cpu = $item{4};
$ram = $item{5};
$hdd = $item{6};
$bios = $item{7};
$fbsd = $item{8};
$fbsdv = $item{9};
$pccv = $item{10};
$apm = $item{11};
$apmv = $item{12};
$config= $item{13};
$pcic = $item{14};
$crd = $item{15};
$ngcrd = $item{16};
$misc = $item{17};
$miscj = $item{18};
$id = $item{19};
$date = $item{20};
$fbsdrel = "";
if ($fbsdv) {
if ($fbsdv =~ /[-a-zA-Z ]*([1-9](\.[0-9]){1,2}).*/) {
$fbsdrel = $1;
$fbsdrel =~ s/\./_/g;
$fbsdid = get_fbsdid($fbsdrel);
}
}
if (!$fbsdrel) {
$fbsdrel = "other";
$fbsdid = get_fbsdid("other");
}
if ($pass) {
if ($fbsdrel) {
open_fbsdrel($fbsdid, 0);
print_delim(RELOUT, $fbsdid+1);
}
print_delim(STDOUT, 0);
print_unit();
print "\n";
if ($fbsdrel) {
print RELOUT "\n";
close(RELOUT);
}
}
else {
$fbsdnums{0}{$fbsdnum0{0}++} = $id;
if ($fbsdrel) {
$fbsdnums{$fbsdid+1}{$fbsdnum0{$fbsdid+1}++} = $id;
}
}
}
elsif (/^\(ITEM$/) {
for ($i = 0; $i <= 20; $i++) {
$item{$i} = 0;
}
$crdcnt = 0;
$ngcrdcnt = 0;
}
elsif (/^\(NAME$/) {
$mode = 1;
}
elsif (/^\(ADDR$/) {
$mode = 2;
}
elsif (/^\(MCN$/) {
$mode = 3;
}
elsif (/^\(CPU$/) {
$mode = 4;
}
elsif (/^\(RAM$/) {
$mode = 5;
}
elsif (/^\(HDD$/) {
$mode = 6;
}
elsif (/^\(BIOS$/) {
$mode = 7;
}
elsif (/^\(FBSD$/) {
$mode = 8;
}
elsif (/^\(FBSDV$/) {
$mode = 9;
}
elsif (/^\(PCCV$/) {
$mode = 10;
}
elsif (/^\(APM$/) {
$mode = 11;
}
elsif (/^\(APMV$/) {
$mode = 12;
}
elsif (/^\(CONFIG$/) {
$mode = 13;
}
elsif (/^\(PCIC$/) {
$mode = 14;
}
elsif (/^\(CRD$/) {
$mode = 15;
}
elsif (/^\(NGCRD$/) {
$mode = 16;
}
elsif (/^\(MISC$/) {
$mode = 17;
}
elsif (/^\(MISCJ$/) {
$mode = 18;
}
elsif (/^\(ID$/) {
$mode = 19;
}
elsif (/^\(DATE$/) {
$mode = 20;
}
elsif (/^\(TYPE$/) {
$crdmode = 1;
}
elsif (/^\(CONF$/) {
$crdmode = 2;
}
if (/^-/) {
if ($mode == 15 || $mode == 16) {
if (!$item{$mode}) {
$item{$mode} = "";
}
s/^-\s*//;
chop;
s/^(\s|\\n)*//;
s/(\s|\\n)*$//;
if ($crdmode == 1) {
$item{$mode} .= sprintf("- %s\\n", $_);
}
elsif ($crdmode == 2) {
s/\\n/\\n\\011/g;
$item{$mode} .= ("\\011" . $_ . "\\n");
}
}
else {
s/^-\s*//;
chop;
s/\s+$//;
$item{$mode} = $_;
}
}
}
}
sub get_fbsdid
{
local($fbsdrel) = @_;
local($i);
for ($i = 0; $i < $fbsdcount; $i++) {
if ($fbsdrel eq $fbsdrels{$i}) {
return $i;
}
}
$fbsdrels{$fbsdcount++} = $fbsdrel;
return $fbsdcount-1;
}
sub open_fbsdrel
{
local($id, $new) = @_;
if ($new) {
if ($jmode) {
open(RELOUT, ">$fbsdrels{$id}\.jp\.html");
} else {
open(RELOUT, ">$fbsdrels{$id}\.html");
}
} else {
if ($jmode) {
open(RELOUT, ">>$fbsdrels{$id}\.jp\.html");
} else {
open(RELOUT, ">>$fbsdrels{$id}\.html");
}
}
}
sub print_unit
{
if ($addr) {
$name = sprintf("%s (%s)", $name, $addr);
}
&printitem("Name", $name);
if ($date) {
&printitem("Date", $date);
}
if ($mcn && $cpu && $ram && $hdd) {
$spec = sprintf("%s (CPU %s, HDD %s, RAM %s)",
$mcn, $cpu, $hdd, $ram);
&printitem("Machine", $spec);
}
else {
die "Incomplete Machine Spec.";
}
if ($fbsd) {
if ($fbsdv) {
$fbsdok = sprintf("%s (%s)", $fbsd, $fbsdv);
}
else {
$fbsdok = $fbsd;
}
&printitem("FreeBSD", $fbsdok);
}
if ($pccv) {
&printitem("Pccard Pkg", $pccv);
}
if ($apm) {
if ($apmv) {
$apmok = sprintf("%s (%s)", $apm, $apmv);
}
else {
$apmok = $apm;
}
&printitem("APM BIOS", $apmok);
}
if ($config) {
&printitem("Config Opt", $config);
}
if ($pcic) {
&printitem("PCIC", $pcic);
}
if ($crd) {
&printitem("Cards", $crd);
}
if ($ngcrd) {
&printitem("NG-Cards", $ngcrd);
}
if ($misc && (!$miscj || !$jmode)) {
&printitem("Misc Info", $misc);
}
if ($jmode && $miscj) {
&printitem("Misc Info", $miscj);
}
}
sub printitem
{
local($name, $item) = @_;
local($colon, $pritem);
if (!($item =~ /\\n/)) {
$item =~ s/\011//g;
$item =~ s/</g;
$item =~ s/>/>/g;
$colon = ":";
piloop: while (1) {
if (length($item) >= 60) {
$pritem = substr($item, 0, 60 - 1);
$pritem =~ s/\S+$//;
substr($item, 0, length($pritem)) = '';
$item =~ s/^\s*//;
}
else {
$pritem = $item;
printf("%-10s%s %s\n", $name, $colon, $pritem);
if ($fbsdrel) {
printf(RELOUT "%-10s%s %s\n", $name, $colon, $pritem);
}
last piloop;
}
printf("%-10s%s %s\n", $name, $colon, $pritem);
if ($fbsdrel) {
printf(RELOUT "%-10s%s %s\n", $name, $colon, $pritem);
}
$name = "";
$colon = " ";
}
}
else {
printf("%-10s:\n", $name);
$item =~ s/^(\\n)*//;
$item =~ s/(\\n)*$//;
$item =~ s/\\n/\n /g;
$item =~ s/\\011/\011/g;
$item =~ s/</g;
$item =~ s/>/>/g;
print " ", $item, "\n";
if ($fbsdrel) {
printf(RELOUT "%-10s:\n", $name);
print RELOUT " ", $item, "\n";
}
}
}
sub print_delim
{
local($out, $id) = @_;
local($num) = $fbsdnums{$id}{$fbsdnum1{$id}};
printf($out "
", $num);
if ($fbsdnum1{$id} <= 0) {
print $out "[Prev]";
} else {
printf($out "[Prev]",
$fbsdnums{$id}{$fbsdnum1{$id}-1});
}
printf($out "[%03d]", $num, $num);
if (++$fbsdnum1{$id} >= $fbsdnum0{$id}) {
print $out "[Next]";
} else {
printf($out "[Next]",
$fbsdnums{$id}{$fbsdnum1{$id}});
}
print $out "\n";
}
sub print_head
{
local($out, $id, $fbsdrel) = @_;
local($i, $j, $lang, $rel);
if ($fbsdrel) {
$fbsdrel =~ s/_/./g;
$fbsdrel =~ s/([1-9](\.[0-9]){1,2})/$1-RELEASE/;
}
else {
$fbsdrel = "All";
}
print $out "\n";
print $out "\n";
print $out "\n";
print $out "\n";
} else {
print $out "charset=iso-8859-1\">\n";
}
print $out "Laptop Survey / FreeBSD $fbsdrel\n";
print $out "\n";
print $out "\n";
print $out "
\n";
print $out "Laptop Survey / FreeBSD $fbsdrel
\n";
print $out "\n";
if ($jmode) {
print $out "[
PAO home page]\n";
print $out "[
Laptop Survey]
\n";
$lang = ".jp";
} else {
print $out "[
PAO home page]\n";
print $out "[
Laptop Survey]
\n";
$lang = "";
}
for ($i = 0; $i < $fbsdcount; $i++) {
$j = $fbsdidx{$i};
$rel = $fbsdrels{$j};
$rel =~ s/_/./g;
if ($id == $j+1) {
print $out "[$rel]\n";
} else {
print $out "[
$rel]\n";
}
}
print $out "
\n";
if ($id) {
printf($out "%d/%d items\n", $fbsdnum0{$id}, $fbsdnum0{0});
} else {
printf($out "%d items\n", $fbsdnum0{$id});
}
print $out "
Last Update: ",`date`,"
\n";
print $out "
Toshihiko ARAI <toshi\@jp.FreeBSD.org>\n";
print $out "
\n";
}
sub print_tail
{
local($out) = @_;
print $out "
\n";
print $out "Return to page top.\n";
print $out "Toshihiko ARAI <toshi\@jp.FreeBSD.org>\n";
print $out "\n";
}
sub make_index
{
local($i, $j, $lang, $rel);
if ($jmode) {
open(IDX, ">index.jp.out");
} else {
open(IDX, ">index.out");
}
print IDX "\t| All | ($fbsdnum0{0} items)\n";
print IDX "\t | Japanese\n";
print IDX "\t | English\n";
print IDX "\t | LTS.jp.txt\n";
print IDX "\t | LTS.txt\n";
for ($i = 0; $i < $fbsdcount; $i++) {
$j = $fbsdidx{$i};
$rel = $fbsdrels{$j};
$rel =~ s/_/./g;
print IDX "\t |
| $rel | ($fbsdnum0{$j+1} items)\n";
print IDX "\t | Japanese\n";
print IDX "\t | English\n";
}
close(IDX);
}
|