#!/usr/bin/perl
#
# This script is in public domain.
#
# xjman の html ツリーの index を作る.
#                              2000.3.4 NAKANO Takeo.
#

#
# definitions
#
$WWWROOT="xjman";
$th_seq = 20;
$th_dep = 3;
@secs = (1, 3, 5);

open IDX, "| nkf -j > $WWWROOT/index.html";
print IDX $idx_header;

foreach $sec (@secs){
    $secx = $sec . "x";
    @page = ();
    print IDX "<H2>セクション $sec</H2>\n";

    open LS, "ls $WWWROOT/man$sec/*.html |";
    while (<LS>) {
	chomp;
	unless (/man[1-8]\/([^\/]*)\.[1-8]x\.html$/){next;}
	push @page, $1;
    }
    close LS;

    $sh = "%";
    $sl = length($sh);

    for ($i = 0; $i<= $#page; $i++){
	if ($page[$i] !~ /^$sh/) {
	    $schg = "true";
	    while($sl > 0){
		$sl--;
		$sh = substr($sh, 0, $sl);
		if ($page[$i] =~ /^$sh/) {
		    $sl++;
		    $sh = substr($page[$i], 0, $sl);
		    last;
		}
	    }
        }

	while($sl < $th_dep && $sl <= length($page[$i])){
            if ($page[$i+$th_seq] !~ /^$sh/){
		last;
	    }
	    $sl++;
	    $sh = substr($page[$i], 0, $sl);
            $schg = "true";
        }

	if ($schg eq "true"){
	    print IDX "\n<H3>$sh</H3>\n";
	    $schg = "false";
	}
	print IDX "<A HREF=\"man$sec/$page[$i].$secx.html\">$page[$i].$secx</A>\n";
    }
}    
print IDX $idx_footer;
close IDX;
#
# == end of the script ==

BEGIN {
#########################################################
# ページヘッダ
#
   $idx_header = <<'EOM';
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>xjman/web INDEX</title>
<LINK REV=MADE HREF="mailto:xjman-ml@dsl.gr.jp">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-2022-jp">
<link rel=stylesheet type="text/css" href="http://xjman.dsl.gr.jp/xjman.css">
</head>
<body>
<h1>xjman/web INDEX</h1>
EOM

#########################################################
# ページフッタ
#
   $idx_footer = <<'EOM';
  <HR>
  <ADDRESS>
   翻訳に関するコメントは:
    X Japanese Documentation Project &lt;xjman-ml@dsl.gr.jp&gt; まで.<BR>
   本ページ・検索システムに関するコメントは:
    NAKANO Takeo &lt;nakano@apm.seikei.ac.jp&gt; まで.
  </ADDRESS>

  <A HREF="../index.html">戻る</A>
</body>
</html>
EOM
}
