OSDN Git Service

cvs-status-modified が translation_list 以外のファイルが更新された場合でも
[linuxjm/jm.git] / bin / mkpodweb.perl
1 #!/usr/bin/perl -w
2 #
3 # build html hierarchy of pod files using pod2html
4 #
5 # $Id: mkpodweb.perl,v 1.2 2000/08/02 10:00:22 nakano Exp $
6 #
7 BEGIN{
8     $epath = `dirname $0`; chomp $epath;
9     unshift (@INC, $epath);
10 }
11 use JMtl ('line2hash', 'hash2line');
12 use strict 'vars';
13
14 my ($idx_header, $idx_footer);
15
16 #
17 # $PODROOT は CVS リポジトリの JM/pod,
18 # $WWWROOT は web の html コンテンツのトップ,
19 # $POD2HTML は pod2html コマンドを想定.
20 #
21 if (@ARGV < 3) {die "$0 srcroot destroot pod2html\n"};
22
23 my $PODROOT = $ARGV[0];
24 unless (-d $PODROOT) {die "$PODROOT does not exist\n"};
25
26 my $WWWROOT = $ARGV[1];
27
28 my $POD2HTML = $ARGV[2];
29 unless (-x $POD2HTML) {die "$POD2HTML does not executable\n"};
30
31 #
32 # for debugging purpose:
33 #
34 #my $PODROOT = "/home/nakano/text/JM/imp/pod";
35 #my $WWWROOT = "/home/nakano/public_html/JMwww/html";
36 #my $MAN2HTML = "/home/nakano/bin/man2html";
37 #my $YAMAN2HTML = "/home/nakano/text/JM/head/admin/tools/yaman2html.perl";
38
39 #
40 # man2html 出力に対して置換する各リンク (決め打ち(^^;)
41 #
42 my $PODWROOT='../../pod';
43 my $MAIN='<A HREF="../../index.html">JM Home Page</A>';
44 my $CSS='<LINK REL="stylesheet" TYPE="text/css" HREF="../../jmpod.css">';
45
46 my (%pod_hash, %page_name);
47 #
48 # $PODROOT/$pkg/translation_list の scan.
49 #
50 print "scanning translation_list's...\n";
51 open RL,"find $PODROOT -name translation_list|";
52 while(<RL>){
53     print;
54     chomp;
55     my $tl = $_;
56     unless(/.*pod\/([^\/]*)\/translation_list/){next;}
57     my $pkg=$1;
58
59     open TL, $tl || die "cannot open $tl";
60     while (<TL>){
61         print;
62         chomp;
63         my %ti = line2hash($_);
64         my $name = $ti{fname};
65         my $page = "$pkg,$name";
66
67         if ($ti{kind} eq "roff" && $ti{stat} =~ /^up/) {
68             my $src = "$pkg/release/$name.pod";
69             $pod_hash{"$page"} = $src;
70             print "collect pod: $page <= $src\n";
71             next;
72         }
73
74         if ($ti{kind} eq "roff" && $ti{stat} =~ /^cnt/) {
75             my $src = "$pkg/contrib/$name.pod";
76             $pod_hash{"$page"} = $src;
77             print "collect pod: $page <= $src\n";
78             next;
79         }
80     }
81     close TL;
82 }
83 close RL;
84
85 foreach my $key (sort keys %page_name){
86     my $num = $#{$page_name{$key}} + 1;
87     print "$key: $num\n";
88 }
89 #
90 # 変換開始。
91 #
92
93 #
94 # roff -> html
95 #
96 foreach my $fkey (sort keys %pod_hash){
97     my ($pkg, $name) = split /,/, $fkey;
98
99     my $hdir = "$WWWROOT/$pkg";
100     my $hfile = "$hdir/$name.pod.html";
101
102     system("mkdir -p $hdir");
103
104     print "converting $pkg/$name.pod...";
105     my $podpage = "$PODROOT/$pod_hash{$fkey}";
106
107     # pod page への link.
108     my $PODP = "<A HREF=\"$PODWROOT/$pod_hash{$fkey}\">pod page</A>";
109     my $NAVI = "$MAIN\n$PODP";
110
111     open P2H, "$POD2HTML $podpage |";
112     open WL,"| nkf -j > $hfile";
113
114     while(<P2H>){
115         s/\<\/HEAD\>/$CSS\n<HEAD>\n/;
116         s/<BODY>/<BODY>$NAVI\n<HR>\n/;
117
118         # Fix double quotes
119         s/\`\`/\&#147;/g;
120         s/\'\'/\&#148;/g;
121
122         # Fix single quotes
123         s/\'/\&#146;/g;
124
125         # Fix em-dashes... It may not be parsed well by JP browsers.
126         # s/---/\&#151;/g;
127
128         # Add </P> to the end of paragraphs
129         if (/^\<P\>/ .. /^$/)
130         {
131             print WL "</P>\n" if (/^$/);
132         }
133         print WL;
134     }
135     close P2H;
136     close WL;
137     system ("rm -f pod2html-*cache");
138     print "done.\n";
139 }
140