1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178
|
#!/usr/bin/perl -w
# Copyright (c) 1998 by Marco Budde (Budde@tu-harburg.de)
# Copyright (c) 2001 by Colin Watson (cjwatson@debian.org)
# Copyright (c) 2001, 2002 by GOTO Masanori (gotom@debian.org)
# GNU General Public License
################################################################
# HOWTO-INDEX -> dhelp / dwww / doc-base #
# #
# usage: html2docbase <dhelp section> <dwww section> #
# <dhelp file> <dwww file> <files> #
################################################################
my $dhelp_section = shift;
my $dwww_section = shift;
my $dhelp_file = shift;
my $dwww_file = shift;
my $root = '/usr/share/doc/HOWTO/ja-html';
##############################
# get abstract of document #
##############################
sub get_abstracts ($)
{
my $filename = shift;
my %docs;
my $index;
open IN, "< $filename" or die "can't open $filename!\n";
{
local $/ = undef;
$index = scalar <IN>;
}
close IN;
# Transform silly DocBook-generated HTML into something more easily
# parseable.
$index =~ s/\n>/>/g;
$index =~ s/\n/ /g;
# JF-INDEX format
while ($index =~ m!<dt><a\s*href="(.*?)"> # link
<strong>(.*?)</strong></a> .*? # title
<dd>(.*?) # abstract
<small> .*? !gx)
{
my ($link, $title, $abstract) = ($1, $2, $3);
# JF un-neccesary link
$JFdocsDIR = 'http://www.linux.or.jp/JF/JFdocs/';
$contribDIR = 'http://www.linux.or.jp/JF/';
$link =~ s/$JFdocsDIR//;
$link =~ s/$contribDIR//;
# Clean up whitespace.
$abstract =~ s/^\s+//;
$abstract =~ s/\s+$//;
$abstract =~ s/\s\s+/ /g;
# Dispose of some HTMLisms.
$title =~ s/&#(\d+);/chr $1/eg;
$abstract =~ s/&#(\d+);/chr $1/eg;
$abstract =~ s!<em>!!;
$abstract =~ s!</em>!!;
$abstract =~ s!<i .*?>!!;
$abstract =~ s!</i>!!;
$abstract =~ s!<a .*?>!!;
$abstract =~ s!</a>!!;
$title =~ s/&/&/g;
$title =~ s/</</g;
$title =~ s/>/>/g;
$title =~ s/"/"/g;
$abstract =~ s/&/&/g;
$abstract =~ s/</</g;
$abstract =~ s/>/>/g;
$abstract =~ s/"/"/g;
$docs{$link} = {title => $title, abstract => $abstract};
}
return %docs;
}
##################
# write .dhelp #
##################
sub write_dhelp (*$$$)
{
my ($dhelp, $filename, $linkname, $abstract) = @_;
print $dhelp <<EOF;
<item>
<directory>$dhelp_section
<linkname>$linkname
<filename>$filename
<description>
$abstract
</description>
</item>
EOF
}
##################################
# dwww support (via menu file) #
##################################
sub write_dwww (*$$$$)
{
my ($dwww, $filename, $docid, $linkname, $abstract) = @_;
print $dwww <<EOF;
?package(doc-linux-ja-html):needs="dwww" section="$dwww_section" \\
title="$docid" \\
longtitle="$linkname" \\
description="$abstract" \\
command="$root/$filename"
EOF
}
####################
# write doc-base #
####################
# Commented out until bug #114692 is fixed.
#sub write_doc_base ($$$$)
#{
# my ($filename, $docid, $linkname, $abstract) = @_;
# open DOCBASE, "> $outdir/$docid"
# or die "can't write to $outdir/$docid: $!";
# print DOCBASE <<EOF;
#Document: $docid
#Title: $linkname
#Abstract: $abstract
#Section: $section
#
#Format: HTML
#Index: $root/$filename
#Files: $root/$filename
#
#EOF
# close DOCBASE;
#}
################
# main #
################
open DHELP, "> $dhelp_file";
open DWWW, "> $dwww_file";
for my $filename (@ARGV)
{
my %abstracts = get_abstracts $filename;
for my $docfile (sort keys %abstracts)
{
my $docid = $docfile;
$docid =~ s!mini/!!;
$docid =~ s!(?:-HOWTO)?(?:/index)?\.html!!;
$docid = "ldp-ja-$docid";
if (defined $ENV{DEB_BUILD_OPTIONS} and
$ENV{DEB_BUILD_OPTIONS} =~ /debug/)
{
print "$docid: $abstracts{$docfile}{title}\n";
print "$abstracts{$docfile}{abstract}\n\n";
}
write_dhelp DHELP, $docfile, $abstracts{$docfile}{title},
$abstracts{$docfile}{abstract};
write_dwww DWWW, $docfile, $docid, $abstracts{$docfile}{title},
$abstracts{$docfile}{abstract};
# write_doc_base $docfile, $docid, $abstracts{$docfile}{title},
# $abstracts{$docfile}{abstract};
}
}
close DHELP;
close DWWW;
|