#!/usr/bin/perl
#
# display translation status.
#

use CGI;

$kauthorsent="build/doc/ko_KR.eucKR/books/handbook/kauthors.ent";
%anames=();
%aemail=();

$drophead="doc/ko_KR.eucKR/";

# read author entry.
open (KAUTHORS, $kauthorsent);
while (<KAUTHORS>)
{
  next unless /^<!ENTITY ([a-z\.]+) \"(.+)\s<email>(.*)<\/email>\">/;

  if ($1 ne "") {
#    print "$1 $2 $3\n";
    $anames{$1}=$2;
    $aemail{$1}=$3;
  }
}
close KAUTHORS;

@handbook=split(/[\s\n]/, `find build/doc/ko_KR.eucKR/books/handbook -type f \\( -name '*.sgml' -o -name '*.ent' \\)`);

use CGI;

$q = new CGI;


print $q->header(-type=>"text/html", -charset=>"euc-kr");

cat_file("/kfug/www/htdocs/prefix/header-cgi.html");

cat_file("/kfug/www/htdocs/projects/doc-kr/menu.shtml");

print "<h2 align=\"center\"><font color=\"#000080\">번역 상황표</font></h2>

아래 표는 doc-kr 프로젝트의 대상이 되는 여러 문서 파일의 번역 여부와
번역자, 그리고 번역중인 원문의 버전을 나타냅니다. 각 링크를 클릭하면
해당 파일을 볼 수 있습니다.<p>\n";
print "<center><table border width=100%>
<tr bgcolor=#ddddff>
  <th>파일명</th>
  <th>번역자</th>
  <th>원문 버전</th>
  <th>상황</th>
</tr>\n";
 
$afound=0;
$astat="번역안됨";
foreach $f (@handbook)
{
  print "<tr>\n";

  $sf=$f;
  $sf=~s/^build\/$drophead//g;
  print "<td><a href=\"http://www.kr.freebsd.org/cgi-bin/cvsweb.cgi/$drophead\/$sf?cvsroot=kfug\">$sf</a></td>\n";
  
  print "<td>";
  open(DOCFILE, $f);
  while(<DOCFILE>)
  {
     if (/\$FreeBSD.*,v\s([0-9\.]+)/){
       $over=$1;
     }
     if (/\$Id.*,v\s([0-9\.]+)/){
       $tver=$1;
     }
     if (/&(a\.kr\.[a-z]+)/){
       print "<a href=\"mailto:$aemail{$1}.no-spam\">$anames{$1}</a> ";
       $afound=1;
       $astat="번역중";
       last;
     }
  }
  close($f);
  if ($afound == 0){
    print "없음";
  }
  $afound=0;
  print "</td>";

  $of=$f;
  $of=~s/^build\///g;
  $of=~s/ko_KR\.eucKR/en_US\.ISO_8859-1/;
  print "<td>$over [<a href=\"http://www.kr.freebsd.org/cgi-bin/cvsweb.cgi/$of?rev=$over&content-type=text/x-cvsweb-markup\">원문보기</a>]</td>";

  # status should be improved...
  print "<td>$astat</td>\n";
  $astat="번역안됨";

  print "</tr>";
}
print "</table></center>";

cat_file("/kfug/www/htdocs/prefix/tailer-cgi.html");

sub cat_file
{
  my $path=$_[0];

  open(CAT_PATH, $path);
  while(<CAT_PATH>){
    print $_;
  }
  close(CAT_PATH);
}
