doc/ja/ports/portindex
1998-10-01 16:54:37 +00:00

255 lines
7.1 KiB
Perl
Executable file

#!/usr/bin/perl
# convert a ports INDEX file to HTML
#
# by John Fieber <jfieber@freebsd.org>
# Mon May 13 10:31:58 EST 1996
# $Id: portindex,v 1.12 1998-10-01 16:54:37 motoyuki Exp $
# The FreeBSD Japanese Documentation Project
# Original revision: 1.19
############################################################
# Load local config file. You can override in portindex.conf
# the variables for the default web and the ftp server. This
# make it easy to maintain a local web mirror and let the
# URL point to yourself and not to the standard FreeBSD FTP server.
$config = $0 . '.' . 'conf';
do $config if -f $config;
# This is the base of where we ftp stuff from
if ($ENV{'MASTER_FTP_SERVER'}) {
$ftpserver = $ENV{'MASTER_FTP_SERVER'};
} else {
$ftpserver = 'ftp://ftp.freebsd.org' if !$ftpserver;
}
$base = "$ftpserver/pub/FreeBSD/FreeBSD-current" if !$base;
$baseHTTP = $base if !$baseHTTP;
$urlcgi = 'http://www.freebsd.org/cgi/url.cgi' if !$urlcgi;
$packagesURL = "$ftpserver/pub/FreeBSD/packages-stable/All/"
if !$packagesURL;
# support tar on the fly or gzip'ed tar on the fly
$ftparchive = 'tar' if !$ftparchive;
# better layout and link to the sources
if ($urlcgi) {
$baseHTTP = $urlcgi . '?' . $baseHTTP;
}
$today = &getdate;
&packages_exist('packages.exists', *packages);
&main;
sub getdate {
# @months = ("January", "February", "March", "April", "May","June",
# "July", "August", "September", "October", "November", "December");
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$year += 1900;
# return "Updated $months[$mon] $mday, $year";
$mon++;
return "$year 年 $mon 月 $mday 日に更新されました.";
}
sub header {
local ($fh, $htext) = @_;
print $fh "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 3.2//EN\" [\n";
print $fh "<!ENTITY base CDATA '..'>";
print $fh "<!ENTITY date \"<em>$today</em>\">\n";
print $fh "<!ENTITY title '$htext'>";
print $fh "<!ENTITY blurb SYSTEM \"ports.inc\">\n";
print $fh "<!ENTITY % includes SYSTEM \"../includes.sgml\">\n";
print $fh "<!ENTITY email 'ports'>";
print $fh "%includes;\n";
print $fh "]>\n";
print $fh "<html>&header;\n";
}
sub footer {
local ($fh, $ftext) = @_;
print $fh "\n$ftext\n";
print $fh "&footer;\n";
print $fh "</BODY>\n</HTML>\n";
}
sub packages_exist {
local($file, *p) = @_;
open(P, $file) || do {
warn "open $file: $!\n";
warn "Cannot create packages links\n";
return 1;
};
while(<P>) {
chop;
$p{$_} = 1;
}
close P;
return 0;
}
sub main {
$sep = "<B>:</B>";
# 'category' translation database
if (open(CATF, "categories.ja_JP.EUC")) {
while (<CATF>) {
($a, $b) = split('\|');
next if !defined($b);
chop($b);
$catsLANG{$a} = $b;
}
}
# 'COMMENT' translation database
if (open(COMF, "comments.ja")) {
while (<COMF>) {
($a, $b) = split('\|');
next if !defined($b);
chop($b);
$b =~ s/&/&amp;/g;
$b =~ s/</&lt;/g;
$b =~ s/>/&gt;/g;
$descLANG{$a} = $b;
}
}
while (<>) {
chop;
s/&/&amp;/g;
s/</&lt;/g;
s/>/&gt;/g;
# Read a record
($name, $loc, $prefix, $desc, $ldesc, $owner, $cats,
$keys, $bdep, $rdep) = split('\|');
# Check for double hyphens in the name (--).
$name =~ s/--/-/g;
# Split the categories into an array
@cat = split("[ \t]+", $cats);
$catkey{$name} = $cat[0];
# desc translation
($lloc = $loc) =~ s@^/usr/ports/@@;
$desc = $descLANG{$lloc}
if ($descLANG{$lloc} ne '');
foreach $i (@cat) {
$stats{$i}++;
# figure out the FTP url
$loc =~ s/\/usr/$base/;
$ldesc =~ s/\/usr/$baseHTTP/;
# The name description and maintainer
$data{$i} .= "<DT><B><A NAME=\"$name\"></A><A HREF=\"$loc.$ftparchive\">$name</A></B> ";
$data{$i} .= "<DD>$desc<BR><A HREF=\"$ldesc\">詳しい説明</A>";
if ($packages{"$name.tgz"}) {
$data{$i} .= qq{ | <a href="$packagesURL$name.tgz">パッケージ</a>};
}
$ownerurl = $owner;
$ownerurl =~ s/&lt;/</g;
$owenrurl =~ s/&gt;/>/g;
$data{$i} .=
"<BR><I>保守担当者:</I> <A HREF=\"mailto:$ownerurl\">$owner</A>";
# If there are any dependencies, list them
if ($bdep ne "" || $rdep ne "") {
$data{$i} .= "<BR><I>必要なもの:</I> ";
@dep = split(/ /, "$bdep $rdep");
foreach $j (@dep) {
$data{$i} .= " <A HREF=\"##$j##.html#$j\">$j</A>,";
}
# remove the trailing comma
chop $data{$i};
}
# If the port is listed in more than one category, throw
# in some cross references
if ($#cat > 0) {
$data{$i} .= "<BR><EM>ここにも含まれています:</EM> ";
foreach $j (@cat) {
if ($j ne $i) {
if ($j eq $cat[0]) {
$data{$i} .= " <STRONG><A HREF=\"$j.html#$name\">\u$j</A></STRONG>,";
}
else {
$data{$i} .= " <A HREF=\"$j.html#$name\">\u$j</A>,";
}
}
}
# remove the trailing comma
chop($data{$i});
}
$data{$i} .= "<P></P></DD>\n"
}
# Add an entry to the master index
# workaround for SGML bug, `--' is not allowed in comments
local($sname) = $name;
$sname =~ s/--/-=/g;
$master[$portnumber] =
"<!-- $sname --><STRONG><A HREF=\"$cat[0].html#$name\">$name</A></STRONG> " .
" -- <EM>$desc</EM><BR>\n";
$portnumber++;
}
open(MOUTF, ">index.sgml");
&header(MOUTF, "FreeBSD Ports");
# print MOUTF "<!--#include virtual=\"./ports.inc\" -->\n";
print MOUTF "&blurb;";
print MOUTF "<hr><P>FreeBSD Ports コレクションには, 現時点で $portnumber 個の ports が提供されています. <br> <A HREF=\"$base/ports.tar.gz\">全ての $portnumber 個の ports を tar でまとめて gzip したもの</A> (およそ 5 メガバイト) をダウンロードするか, 以下の分類からたどってください:\n";
print MOUTF "<UL>\n";
@foos = sort(keys %stats);
foreach $key (@foos) {
# For translation
$subkey = "";
$subkey = " ($catsLANG{$key})"
if ($catsLANG{$key} ne '');
# For the master file...
print MOUTF
"<LI><A HREF=\"$key.html\">\u$key$subkey</A> <em>($stats{$key})</em></LI>";
# Create the category file
open(OUTF, ">$key.sgml");
$subkey = "";
$subkey = " / $catsLANG{$key}"
if ($catsLANG{$key} ne '');
&header(OUTF, "FreeBSD Ports: \u$key$subkey");
print OUTF "<DL>\n";
$d = join("\n", sort(split(/\n/, $data{$key})));
$d =~ s/##([^#]*)##/$catkey{$1}/g;
print OUTF $d;
print OUTF "</DL>\n";
&footer(OUTF, "<HR><A HREF=\"index.html\">Port の分類</A>" .
" -- <A HREF=\"master-index.html\">一覧</A><HR>");
close(OUTF);
}
print MOUTF "</UL>\n";
print MOUTF
"<UL><LI><A HREF=\"master-index.html\">$portnumber 個の ports 全てをアルファベット順に並べた一覧</A></LI></UL>\n";
&footer(MOUTF, "");
close(MOUTF);
# Create the master index file
open(MINDEX, ">master-index.sgml");
&header(MINDEX, "FreeBSD Ports コレクション 一覧");
print MINDEX "<P>\n";
print MINDEX sort @master;
print MINDEX "</P>";
&footer(MINDEX, "<HR><A HREF=\"index.html\">Port の分類</A><HR>");
close(MINDEX);
}