OSDN Git Service

translation_list バージョン2 導入開始。 test_tl_ver2
authormatsuand <30614168+matsuand@users.noreply.github.com>
Sun, 29 May 2022 12:01:14 +0000 (21:01 +0900)
committermatsuand <30614168+matsuand@users.noreply.github.com>
Sun, 29 May 2022 12:01:14 +0000 (21:01 +0900)
bin/JMcommon.pm [new file with mode: 0644]
bin/JMtl.pm
bin/JMtl2.pm [new file with mode: 0644]
bin/mkdist.perl

diff --git a/bin/JMcommon.pm b/bin/JMcommon.pm
new file mode 100644 (file)
index 0000000..479256e
--- /dev/null
@@ -0,0 +1,53 @@
+#!/usr/bin/perl
+package JMcommon;
+
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT_OK = qw(getCommentInfo);
+
+#
+# コメント行内のキーワードとその値を %thash に取り込む。
+#
+sub getCommentInfo($) {
+    my %thash;
+    my $tl = $_;
+    my $ver = 1;
+
+    open TL, $tl || die "cannot open $tl";
+    while (<TL>){
+      chomp;
+      my $line = $_;
+
+      # 行頭がコメント記号(#)で始まる場合
+      if ($line =~ /^\#/) {
+
+        # キーワードコメント行(#. KEYWORD VALUE)の場合
+        if ($line =~ /^\#\.[ \t]*([a-zA-Z_]+)[ \t]+(.*)$/) {
+          $thash{$1} = $2;
+        }
+      }
+    }
+    close TL;
+
+    # コメント行内のキーワード指定に TL_VERSION がない場合、
+    # TL_VERSION を 1 として %thash に登録する。
+    if ($thash{'TL_VERSION'} eq '') {
+      $thash{'TL_VERSION'} = 1;
+    }
+
+    # translation_list バージョン1の各キーに合わせるために、
+    # 必要なキーと値を生成する。
+
+    # パッケージ名: pkg <= PACKAGE_NAME
+    $thash{'pkg'} = $thash{'PACKAGE_NAME'};
+
+    # パッケージバージョン: over,dver,rver <= PACKAGE_VER
+    $thash{'over'} = $thash{'PACKAGE_VER'};
+    $thash{'dver'} = $thash{'PACKAGE_VER'};
+    $thash{'rver'} = $thash{'PACKAGE_VER'};
+
+    # パッケージリリース日付: odat <= PACKAGE_DATE
+    $thash{'odat'} = $thash{'PACKAGE_DATE'};
+
+    %thash;
+}
index 896d4b7..565a172 100755 (executable)
@@ -46,6 +46,10 @@ sub line2hash($) {
     my %thash;
     
     chomp $entry;
+
+    # コメント行であった場合は空ハッシュを返して終了
+    if ($entry =~ /^\#/) { return %thash; }
+
     my @member = split /:/, $entry;
     
     my $mark = $member[0];
diff --git a/bin/JMtl2.pm b/bin/JMtl2.pm
new file mode 100644 (file)
index 0000000..511d103
--- /dev/null
@@ -0,0 +1,81 @@
+#!/usr/bin/perl
+package JMtl2;
+
+require Exporter;
+@ISA = qw(Exporter);
+@EXPORT_OK = qw(line2hash_ver2);
+
+#
+# entry → hash.
+#
+sub line2hash_ver2($) {
+    my ($entry) = @_;
+    my %thash;
+    
+    chomp $entry;
+
+    # コメント行であった場合は空ハッシュを返して終了
+    if ($entry =~ /^\#/) { return %thash; }
+
+    my @member = split /\|/, $entry;
+    
+    my $status_str = &trim($member[0]);
+    
+    my ($stat);
+    my $kind = 'roff';
+
+    SW1: {
+      #if ($mark eq '×') {$stat = '1st_non'; last SW1;}
+      #if ($mark eq '▲') {$stat = '1st_rsv'; last SW1;}
+      #if ($mark eq '△') {$stat = '1st_dft'; last SW1;}
+      #if ($mark eq '●') {$stat = '1st_prf'; last SW1;}
+      #if ($mark eq '☆') {$stat = 'upd_non'; last SW1;}
+      #if ($mark eq '■') {$stat = 'upd_rsv'; last SW1;}
+      #if ($mark eq '□') {$stat = 'upd_dft'; last SW1;}
+      #if ($mark eq '◆') {$stat = 'upd_prf'; last SW1;}
+      #if ($mark eq '○') {$stat = 'up2date'; last SW1;}
+      #if ($mark eq '◎') {$stat = 'up2datR'; last SW1;}
+      #if ($mark eq 'C') {$stat = 'cnt_upd'; last SW1;}
+      #if ($mark eq 'c') {$stat = 'cnt_old'; last SW1;}
+      if ($status_str eq '未対応') {$stat = '1st_non'; last SW1;}
+      if ($status_str eq '翻訳中') {$stat = '1st_rsv'; last SW1;}
+      if ($status_str eq '翻訳完') {$stat = '1st_dft'; last SW1;}
+      if ($status_str eq '校正中') {$stat = '1st_prf'; last SW1;}
+      if ($status_str eq '校正完') {$stat = 'up2date'; last SW1;}
+      if ($status_str eq '寄贈')   {$stat = 'cnt_upd'; last SW1;}
+  
+      $kind = 'link';
+      #if ($mark eq '@') {$stat = 'up2date'; last SW1;}
+      #if ($mark eq '※') {$stat = '1st_non'; last SW1;}
+      if ($status_str eq 'リンク') {$stat = '1st_non'; last SW1;}
+
+      $kind = 'roff';
+    }
+
+    $thash{'mark'} = "$status_str";
+    $thash{'kind'} = $kind;
+    $thash{'stat'} = $stat;
+
+    $thash{'fname'} = &trim($member[2]); # TLバージョン2 では拡張子込みのファイル名
+    $thash{'sec'}   = &trim($member[1]); # TLバージョン2 では "man" + <num>
+
+    $thash{'tdat'}  = &trim($member[5]);
+    $thash{'tname'} = &trim($member[6]);
+    $thash{'tmail'} = &trim($member[7]);
+    $thash{'lname'} = &trim($member[4]); # TLバージョン2 では拡張子込みのファイル名
+    $thash{'lsec'}  = &trim($member[3]); # TLバージョン2 では "man" + <num>
+
+    $thash{'comment'} = $member[8];
+    for (my $i = 9; $i <= $#member; $i++){
+      $thash{'comment'} .= ":$member[$i]";
+    }
+
+    %thash;
+}
+
+
+sub trim {
+  my $str = $_[0];
+  $str =~ s/^[ \t]*(.*?)[ \t]*$/$1/;
+  return $str;
+}
index 0049be3..797d4db 100755 (executable)
@@ -9,7 +9,9 @@ BEGIN{
     $epath = `dirname $0`; chomp $epath;
     unshift (@INC, $epath);
 }
+use JMcommon ('getCommentInfo');
 use JMtl ('line2hash', 'hash2line');
+use JMtl2 ('line2hash_ver2');
 use strict 'vars';
 
 my ($idx_header, $idx_footer);
@@ -40,12 +42,12 @@ if (-d "$DISTROOT/manual") {
 }
 system("mkdir -p $DISTROOT/manual");
 
-my (%roff_hash, %link_hash);
+my (%roff_hash, %roff_status, %link_hash);
 #
 # $CVSROOT/manual/$pkg/translation_list の scan.
 #
 print "scanning translation_list's...\n";
-open RL,"find $CVSROOT/manual -name translation_list|";
+open RL,"find $CVSROOT/manual -name translation_list | sort |";
 while(<RL>){
     print;
     chomp;
@@ -60,33 +62,97 @@ while(<RL>){
     system "mkdir -p $DISTROOT/manual/$pkg/";
     system "cp $tl $DISTROOT/manual/$pkg";
 
+    my %ti_common = getCommentInfo($tl);
+    my $tl_ver = $ti_common{'TL_VERSION'};
+
     open TL, $tl || die "cannot open $tl";
     while (<TL>){
        chomp;
-       my %ti = line2hash($_);
+       my %ti_ver;
+       if ($tl_ver == 2) {
+         %ti_ver = line2hash_ver2($_);
+       } else {
+         %ti_ver = line2hash($_);
+       }
+       # ハッシュが空の場合(=コメント行であった場合)は next
+       if (!%ti_ver) { next; }
+
+       # ハッシュを統合する
+       # ( ti_common: 共通ハッシュ, ti_ver: バージョン別ハッシュ )
+       my %ti = (%ti_common, %ti_ver);
+
        my $name = $ti{fname};
        my $sec = $ti{sec};
-       my $page = "$pkg,$name,$sec";
+       my $page = "$tl_ver,$pkg,$name,$sec";
+       $roff_status{"$page"} = $ti{stat};
 
-       if ($ti{kind} eq "link" && $ti{stat} eq "up2date"){
-           my $dst = ".so man$ti{lsec}/$ti{lname}.$ti{lsec}";
-           $link_hash{"$page"} = $dst;
-           print "collect link: $page => $dst\n";
+       if ($ti{kind} eq roff && $ti{stat} =~ /^cnt/) {
+           my $src;
+           if ($tl_ver == 2) {
+               $src = "$pkg/contrib/$sec/$name";
+           } else {
+               $src = "$pkg/contrib/man$sec/$name.$sec";
+           }
+           if (-f "$CVSROOT/manual/$src") {
+               $roff_hash{"$page"} = $src;
+               print "collect roff: $page <= $src\n";
+           }
            next;
        }
 
-       if ($ti{kind} eq roff && $ti{stat} =~ /^up/) {
-           my $src = "$pkg/release/man$sec/$name.$sec";
-           $roff_hash{"$page"} = $src;
-           print "collect roff: $page <= $src\n";
+       if ($ti{kind} eq roff && -d "$CVSROOT/manual/$pkg/release") {
+           my $src;
+           if ($tl_ver == 2) {
+               $src = "$pkg/release/$sec/$name";
+           } else {
+               $src = "$pkg/release/man$sec/$name.$sec";
+           }
+           if (-f "$CVSROOT/manual/$src" && $ti{stat} ne "1st_non") {
+               $roff_hash{"$page"} = $src;
+               print "collect roff: $page <= $src\n";
+           }
            next;
        }
+    }
 
-       if ($ti{kind} eq roff && $ti{stat} =~ /^cnt/) {
-           my $src = "$pkg/contrib/man$sec/$name.$sec";
-           $roff_hash{"$page"} = $src;
-           print "collect roff: $page <= $src\n";
-           next;
+    # もう一度、先頭から走査して、リンクファイルについて
+    # そのリンク先が翻訳済みとして記述されていたかどうかを
+    # 確認し、リンクのための出力処理を行う。
+    # (リンク行のステータスを利用しない=記述内容を信用しない)
+    seek(TL, 0, 0);
+    while (<TL>){
+       chomp;
+       my %ti_ver;
+       if ($tl_ver == 2) {
+         %ti_ver = line2hash_ver2($_);
+       } else {
+         %ti_ver = line2hash($_);
+       }
+       # ハッシュが空の場合(=コメント行であった場合)は next
+       if (!%ti_ver) { next; }
+
+       # ハッシュを統合する
+       # ( ti_common: 共通ハッシュ, ti_ver: バージョン別ハッシュ )
+       my %ti = (%ti_common, %ti_ver);
+
+       my $name = $ti{fname};
+       my $sec  = $ti{sec};
+       my $page = "$tl_ver,$pkg,$name,$sec";
+       my $lname = $ti{lname};
+       my $lsec  = $ti{lsec};
+       my $lpage = "$tl_ver,$pkg,$lname,$lsec";
+       if ($lsec ne "" && $lname ne "") {
+           my $dst_status = $roff_status{"$lpage"};
+           if ($dst_status !~ /^1st/) {
+               my $dst;
+               if ($tl_ver == 2) {
+                   $dst = ".so man$lsec/$lname";
+               } else {
+                   $dst = ".so man$lsec/$lname.$lsec";
+               }
+               $link_hash{"$page"} = $dst;
+               print "collect link: $page => $dst\n";
+           }
        }
     }
     close TL;
@@ -97,10 +163,17 @@ close RL;
 # copy 開始
 #
 foreach my $fkey (sort keys %roff_hash){
-    my ($pkg,$name,$sec)=split /,/, $fkey;
+    my ($tl_ver,$pkg,$name,$sec)=split /,/, $fkey;
 
-    my $dstdir = "$DISTROOT/manual/$pkg/man$sec";
-    my $dstfile = "$dstdir/$name.$sec";
+    my $dstdir;
+    my $dstfile;
+    if ($tl_ver == 2) {
+        $dstdir = "$DISTROOT/manual/$pkg/$sec";
+        $dstfile = "$dstdir/$name";
+    } else {
+        $dstdir = "$DISTROOT/manual/$pkg/man$sec";
+        $dstfile = "$dstdir/$name.$sec";
+    }
     my $srcfile = "$CVSROOT/manual/$roff_hash{$fkey}";
 
     print "copy $srcfile => $dstfile\n";
@@ -112,10 +185,17 @@ foreach my $fkey (sort keys %roff_hash){
 # make symlinks
 #
 foreach my $fkey (sort keys %link_hash){
-    my ($pkg, $name, $sec) = split /,/, $fkey;
+    my ($tl_ver,$pkg, $name, $sec) = split /,/, $fkey;
 
-    my $dstdir = "$DISTROOT/manual/$pkg/man$sec";
-    my $dstfile = "$dstdir/$name.$sec";
+    my $dstdir;
+    my $dstfile;
+    if ($tl_ver == 2) {
+        $dstdir = "$DISTROOT/manual/$pkg/$sec";
+        $dstfile = "$dstdir/$name";
+    } else {
+        $dstdir = "$DISTROOT/manual/$pkg/man$sec";
+        $dstfile = "$dstdir/$name.$sec";
+    }
 
     print "cat \"$link_hash{$fkey}\" > $dstfile\n";
     system "mkdir -p $dstdir";
@@ -142,13 +222,28 @@ while(<RL>){
     unless(/.*pod\/([^\/]*)\/translation_list/){next;}
     my $pkg=$1;
 
-    system "mkdir -p $DISTROOT/manual/$pkg/";
-    system "cp $tl $DISTROOT/manual/$pkg";
+    system "mkdir -p $DISTROOT/pod/$pkg/";
+    system "cp $tl $DISTROOT/pod/$pkg";
+
+    my %ti_common = getCommentInfo($tl);
+    my $tl_ver = $ti_common{'TL_VERSION'};
 
     open TL, $tl || die "cannot open $tl";
     while (<TL>){
        chomp;
-       my %ti = line2hash($_);
+       my %ti_ver;
+       if ($tl_ver == 2) {
+         %ti_ver = line2hash_ver2($_);
+       } else {
+         %ti_ver = line2hash($_);
+       }
+       # ハッシュが空の場合(=コメント行であった場合)は next
+       if (!%ti_ver) { next; }
+
+       # ハッシュを統合する
+       # ( ti_common: 共通ハッシュ, ti_ver: バージョン別ハッシュ )
+       my %ti = (%ti_common, %ti_ver);
+
        my $name = $ti{fname};
        my $page = "$pkg,$name";
 
@@ -177,4 +272,3 @@ foreach my $fkey (sort keys %pod_hash){
     system "mkdir -p $dstdir";
     system "$POD2MAN --utf8 $srcfile > $dstfile";
 }
-