From owner-man-jp@jp.FreeBSD.org Mon May  5 12:23:22 2003
Received: (from daemon@localhost)
	by castle.jp.FreeBSD.org (8.11.6p2+3.4W/8.11.3) id h453NM387984;
	Mon, 5 May 2003 12:23:22 +0900 (JST)
	(envelope-from owner-man-jp@jp.FreeBSD.org)
Received: from rwcrmhc52.attbi.com (rwcrmhc52.attbi.com [216.148.227.88])
	by castle.jp.FreeBSD.org (8.11.6p2+3.4W/8.11.3) with ESMTP/inet id h453NLY87979
	for <man-jp@jp.freebsd.org>; Mon, 5 May 2003 12:23:21 +0900 (JST)
	(envelope-from horikawa@jp.freebsd.org)
Received: from localhost (12-252-35-167.client.attbi.com[12.252.35.167])
          by rwcrmhc52.attbi.com (rwcrmhc52) with SMTP
          id <2003050503230905200atal1e>; Mon, 5 May 2003 03:23:10 +0000
Message-Id: <20030504.212055.71086198.horikawa@attbi.com>
To: man-jp@jp.FreeBSD.org
From: Kazuo Horikawa <horikawa@jp.FreeBSD.org>
In-Reply-To: <20001112040831S.horikawa@psinet.com>
References: <20001112040831S.horikawa@psinet.com>
X-Mailer: Mew version 3.1 on Emacs 21.2 / Mule 5.0 (SAKAKI)
Mime-Version: 1.0
Content-Type: Multipart/Mixed;
 boundary="--Next_Part(Sun_May__4_21:20:55_2003_680)--"
Content-Transfer-Encoding: 7bit
Reply-To: man-jp@jp.FreeBSD.org
Precedence: list
Date: Sun, 04 May 2003 21:20:55 -0600
X-Sequence: man-jp 4525
Subject: [man-jp 4525] Re: newsyncstat.pl summary.pl
Sender: owner-man-jp@jp.FreeBSD.org
X-Originator: horikawa@jp.FreeBSD.org
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+030405

----Next_Part(Sun_May__4_21:20:55_2003_680)--
Content-Type: Text/Plain; charset=iso-2022-jp
Content-Transfer-Encoding: 7bit

$BKY@n$G$9!#(B

http://home.jp.FreeBSD.org/man-jp/yoyaku/syncstat/ $B$N:n@.$K;HMQ$7$F(B
$B$$$k(B syncstat.pl $B$H(B summary.pl $B$K$D$$$F!#(B

$BDI=>BP>]$,!"%V%i%s%A(B (RELENG_4 $B$J$I(B) $B$G$O$J$/(B HEAD $B$N>l9g$KF0$$$F(B
$B$$$J$+$C$?$N$G!"(BHEAD $B$r;XDj$7$F$bF0$/$h$&$KD>$7$^$7$?!#(B

http://home.jp.FreeBSD.org/man-jp/yoyaku/syncstat/ $B$N>uBV$O@5$7$/(B
$B$J$C$F$$$k$O$:$G$9!#(B

$B$D$$$G$K!"%*%W%7%g%s$N@0M}$r$7$^$7$?!#(B
--
$BKY@nOBM:(B

----Next_Part(Sun_May__4_21:20:55_2003_680)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Description: 00README
Content-Disposition: inline; filename=00README

$Header: /home/cvs/man-jp/syncstat/00README,v 1.3 2003/05/05 01:44:43 horikawa Exp $

This is syncstat for jpman project, inspired by syncstat of doc-jp.

This syncstat needs checkout of translation (doc/ hierarchy)
and CVS repository of original (src/).

Usage: newsyncstat.pl
	--docdir=directory where translated manpages live (required)
	--cvsroot=CVS root where src/ directory lives (required)
	--releng=CVS branch tag like RELENG_4, HEAD and etc
	--htmlout=Output HTML file name (required)

Following crontab setting is for manjpadm:

	45 10 * * *     cvsup -g /proj/manjpadm/cvsup/doc-supfile > /dev/null
	0 11 * * *      cd $HOME/syncstat; for i in 1 2 3 4 5 6 7 8 9; do ./newsyncstat.pl --docdir=/proj/manjpadm/cvsup/doc/ja_JP.eucJP/man/man$i --cvsroot=/pub/cvsup/FreeBSD.cvs --htmlout=/proj/manjpadm/www/work/yoyaku/syncstat/$i.html; done

----Next_Part(Sun_May__4_21:20:55_2003_680)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Description: newsyncstat.pl
Content-Disposition: inline; filename="newsyncstat.pl"

#!/usr/bin/perl
#
# Copyright (C) 2000, 2003 Kazuo Horikawa <horikawa@jp.FreeBSD.org>
# All rights reserved 
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $Header: /home/cvs/man-jp/syncstat/newsyncstat.pl,v 1.5 2003/05/05 01:44:43 horikawa Exp $

$summary_generator =	"./summary.pl";
$releng =		"HEAD";				# default
$str_NotAvail =		'N/A';
$rev_pattern =		"\[\\d\\\.\]\+\\d\+";
$branch_pattern =	"\[\\d\\\.\]\+\\\.0\\\.\\d\+";
$debug =		0;

# Get original's revision number from translated files
# We will see `%FreeBSD: xx.xx', `%Id: xx.xx' and `Original Revision: xx.xx'.
# We do not see `jpman %Id: xx.xx'.
#
# If "xx.xx" found, return "xx.xx" else return "N/A".
sub rev_of_trans{
    my ($filename) = @_;
    my $revision = "";

    printf("filename = %s\n", $filename) if $debug;

    open(IN, "$filename") || die "cannot open $filename";
    while($_ = <IN>){
	if(/jpman\s\%Id:\s\S+,v\s($rev_pattern)/) {
	    # Ignore "jpman Id: xx.xx"
	    print "Ignore jpman\n" if $debug;
	    next;
	} elsif(/[Oo]riginal\s[Rr]evision:\s($rev_pattern)/) {
	    # Accept "Original Revision: xx.xx"
	    $revision = $1;
	    print "Original revision tag\n" if $debug;
	    last;			# "Original Revision" has priority
	} elsif(/%FreeBSD:\s\S+,v\s($rev_pattern)/) {
	    # Accept "FreeBSD: xx.xx"
	    print "Id: tag\n" if $debug;
	    $revision = $1;
	    next;			# "Original Revision" has priority
	} elsif(/%Id:\s\S+,v\s($rev_pattern)/) {
	    # Accept "Id: xx.xx"
	    print "Id: tag\n" if $debug;
	    $revision = $1 if($revision == "");
	    next;			# "Original Revision" has priority
	}
    }
    close(IN);

    $revision = $str_NotAvail unless $revision;		# "" becomes 'N/A'
    return $revision;
}

# Get revision number of original files
#
# We must able to find revision number.
sub rev_of_orig{
    my ($filename) = @_;
    my $branch_number ="";
    my $revision = "";

    printf("filename = %s\n", $filename) if $debug;

    if(!open(IN, "$opt_cvsroot/$filename,v")) {
	use File::Basename;
	my $basename, $path, $suffix;
	($basename, $path, $suffix) = fileparse($filename,"");
	printf "looking at Attic ... %s\n",
	    "$opt_cvsroot/$path"."Attic/$basename,v" ;
	open(IN, "$opt_cvsroot/$path/Attic/$basename,v")
	    ||die "cannot open $opt_cvsroot/$filename";
    }
    # First, find symbols line and convert $releng to branch number.
    if($releng eq "HEAD"){
	while($_ = <IN>){
	    if(/head\s+(\d+\.\d+)/){
		$revision = $1;
		close(IN);
		print "return $revision\n" if $debug;
		return $revision;
	    }
        }
    }
  FIND_BRANCH_LOOP: while($_ = <IN>){
	if(/symbols\s.*$releng:($rev_pattern)/){
	    printf("%s is %s\n", $releng, $1) if $debug;
	    $branch_number = $1;
	    last;
	}
	elsif(/symbols/){
	    while($_ = <IN>){
		if(/$releng:($rev_pattern)/){
		    $branch_number = $1;
		    printf("branch = %s\n", $branch_number) if $debug;
		    last FIND_BRANCH_LOOP;
		} elsif(/^\@\@$/) {
		    last FIND_BRANCH_LOOP;
		}
	    }
	}
    }
    $branch_number || die "Cannot find branch number for $filename\n";

    # "a.b.0.c" will be converted to "a.b.c"
    $branch_number =~ s/\.0\./\./;

    # Next, find exact revision number.
    while($_ = <IN>){
	if(/^($branch_number\.\d+)$/){
	    $revision = $1;
	} elsif(/^\@\@$/){
	    last;
	}
    }
    close(IN);

    if($revision) {
	# return "a.b.c.x"
	print "return $revision\n" if $debug;
	return $revision;
    } else {
	# return "a.b"
	$revision = $branch_number;
	$revision =~ s/\.\d+$//;
	print "return $revision\n" if $debug;
	return $revision;
    }
}

#
# Find original file from translated file
# Use FreeBSD: RCS keyword to find original file
#
sub find_orig_file{
    my ($filename) = @_;

    printf("filename = %s\n", $filename) if $debug;

    open(IN, "$filename") || die "cannot open $filename";
    while($_ = <IN>){
	if(/%FreeBSD: (src.*),v/){
	    return ($1);
	}
    }
}

sub usage {
    die "Usage: newsyncstat.pl\n" .
	"\t--docdir=directory where translated manpages live (required)\n" .
	"\t--cvsroot=CVS root where src/ directory lives (required)\n" .
	"\t--releng=CVS branch tags like RELENG_4, HEAD and etc\n" .
	"\t--htmlout=Output HTML file name (required)\n";
}

MAIN:{
    use Getopt::Long;
    GetOptions ("docdir=s",	# required (e.g., $HOME/CVS_xxx/ja-man/manX/)
		"cvsroot=s",	# required (e.g., /pub/cvsup/FreeBSD.cvs/)
		"htmlout=s",	# required (e.g., $HOME/public_html/X.html)
		"releng=s");	# optional (default HEAD)
    if (!($opt_docdir && $opt_htmlout && $opt_cvsroot)) {
	&usage();
	# NOTREACHED
    }
    if ($opt_releng) {
	$releng = $opt_releng;
    }

    # build @manlist
    opendir(JA_DIR, "$opt_docdir") || die "cannot opendir";
    @manlist = grep{ /\.\d/ && -f "$opt_docdir/$_" } readdir(JA_DIR);
    @manlist = sort(@manlist);

    open(OUT, "|$summary_generator > $opt_htmlout") || die;

    while($_ = shift(@manlist)){
	$transfilename = "$opt_docdir/$_";
	$origfilename = &find_orig_file("$transfilename");

	if($origfilename) {
	    $trans_ver = &rev_of_trans($transfilename);
	    $orig_ver = &rev_of_orig($origfilename);
	    printf(OUT "%s %s %s %s\n",
		   $transfilename, $origfilename, $trans_ver, $orig_ver);
	} else { 
	    $trans_ver = &rev_of_trans($transfilename);
	    printf(OUT "%s %s %s %s\n",
		   $transfilename, $str_NotAvail, $trans_ver, $str_NotAvail);
	}
    }

    close(OUT);
}

----Next_Part(Sun_May__4_21:20:55_2003_680)--
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-Description: summary.pl
Content-Disposition: inline; filename="summary.pl"

#!/usr/bin/perl
#
# Copyright (C) 2000, 2001 Kazuo Horikawa <horikawa@jp.FreeBSD.org>
# All rights reserved 
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# $Header: /home/cvs/man-jp/syncstat/summary.pl,v 1.2 2001/04/12 02:07:23 horikawa Exp $

$cvsweb		= "http://www.FreeBSD.org/cgi/cvsweb.cgi/";
$str_NotAvail	= 'N/A';
$rev_pattern	= "\[\\d\\\.\]\+\\d\+";
$stat_OK	= "<SPAN CLASS=\"ok\">OK</SPAN>";
$stat_NG	= "<SPAN CLASS=\"warn\">NG</SPAN>";
$stat_UNKNOWN	= "<SPAN CLASS=\"warn\">Unknown</SPAN>";

$str_Html_Header = <<'EOT';
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD>
<META http-equiv="Content-Type" content="text/html; charset=ISO-2022-JP">
<STYLE type=text/css>
	BODY { color: black; background: white; }
	a:link    { color: #5555ff; background: white; }
	a:visited { color: #B22222; background: white; }
	a:active  { color: #FF0000; background: white; }
	H1        { text-align: center; color: #00007f; background: white; }
	SPAN.ok   { color: green; }
	SPAN.warn { color: red; }
</STYLE>
<TITLE>Syncstat</TITLE>
</HEAD>
<BODY>
<H1>Status of Synchronization</H1>
EOT

$str_Table_Begin = <<'EOT';
<TABLE BORDER=1 WIDTH="100%">
<TR>
<TD>jman</TD><TD>src</TD><TD>jman rev</TD><TD>man rev</TD><TD>stat</TD>
</TR>
EOT

$str_Table_End = <<'EOT';
</TABLE>

<H1>Legend</H1>
<TABLE BORDER=1>
<TR><TD>Symbol</TD><TD>Description</TD></TR>
<TR><TD>OK</TD><TD>Translation matches with original</TD></TR>
<TR><TD>NG</TD><TD>Translation does not match with original</TD></TR>
<TR><TD>UNKNOWN</TD><TD>Cannot compare Translation with original, because origianl file cannot be determined</TD></TR>
<TR><TD>N/A</TD><TD>Original revision number and file is not found.  Lacks %FreeBSD: % keyword in translation</TD></TR>
</TABLE>

<P>You can browse revision history of translations by following links
in column "jman".  Also, you can browse revision history of original
by following links in column "src".</P>
EOT

$str_Html_Footer = <<"EOT";
<P><A HREF="http://jigsaw.w3.org/css-validator"><IMG style="border:0;width:88px;height:31px" SRC="http://jigsaw.w3.org/css-validator/images/vcss.gif" ALT="Valid CSS!"></A>
</BODY></HTML>
EOT

MAIN:{
    use File::Basename;

    print $str_Html_Header;
    print $str_Table_Begin;

    while($_ = <STDIN>){
	if(/(\S+)\s+(\S+)\s+($rev_pattern)\s+($rev_pattern)/){
	    ($jman, $src, $jman_rev, $man_rev) = ($1, $2, $3, $4);
	    
	    if($3 eq $4) {
		$stat = $stat_OK;
	    } else {
		$stat = $stat_NG;
	    }
	} elsif (/(\S+)\s+(\S+)\s+(\S+)\s+(\S+)/){
	    ($jman, $src, $jman_rev, $man_rev) = ($1, $2, $3, $4);
	    $stat = $stat_UNKNOWN;
	}

	print("<TR>");
	$jman_basename = basename($jman);
	print("<TD><A HREF=\"$cvsweb$jman\">$jman_basename</A></TD>");
	if ($src eq $str_NotAvail) {
	    print("<TD>$src</TD>");
	} else {
	    print("<TD><A HREF=\"$cvsweb$src\">$src</A></TD>");
	}
	print("<TD>$jman_rev</TD><TD>$man_rev</TD><TD>$stat</TD>");
	print("</TR>\n");
    }
    close (IN);

    print $str_Table_End;

    $lastmodified = localtime;
    print "<P>Last Modified: $lastmodified</P>\n";
    print $str_Html_Footer;
}

----Next_Part(Sun_May__4_21:20:55_2003_680)----
