#!/usr/sbin/perl -ns
# This script massages a list of HTML files into online help files for
# the CXFS/FailSafe GUI.
BEGIN {
# get hack name
@dirs = split(/\//,$0);
$O = "$dirs[$#dirs]";
# init
if ($FailSafe) {
$Product = "FailSafe";
} elsif ($CXFS) {
$Product = "CXFS";
} else {
die "usage: ${O} -CXFS file ...\n ${O} -FailSafe file ...\n";
}
$fn = "";
$count = 0;
$Header = <<EOH;
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>$Product Cluster Manager GUI: \
EOH
chop $Header; # hack to remove newline from end of header
$Body = <<EOB;
</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff" TEXT="#000000">
EOB
$Footer = "\n\n</BODY>\n\n</HTML>\n";
}
if (m/^<TITLE>/) {
chop;
@dirs = split(/\//,$ARGV[0]);
if ($dirs[$#dirs] =~ m/[0-9]{3}-[0-9]+-[0-9]+/) {
$PartNo = $&;
}
print STDERR "${O}: reading $ARGV\n";
if (m/^<TITLE>(.*)\s+\(.*\),\s+([-0-9]+)/) {
$Title = $1;
$PartNo = $2;
} elsif (m/^<TITLE>([^<]+)\s+(\*+.*\*+)/) {
$Title = $1;
} elsif (m/^<TITLE>([^<]+)/) {
$Title = $1;
}
}
if (m/<A NAME="(fs_[a-z]+)">/) {
($_, $token, $post) = ($`, $1, $');
if ($fn) {
# now it appears that the SGI_HELPID will always appear on a newline
# so this hackery is no longer necessary:
# if (m/<p>Figure [0-9]/) { # should never happen
# $_ = $`;
# }
# &fixup();
# print HTML $_;
print HTML $Footer;
close(HTML);
$fn = "";
}
$fn = "$token\.html";
open(HTML, ">$fn") ||
die "${O}: unable to create \"$fn\".\n";
$count++;
print STDERR "${O}: created \"$fn\".\n";
print HTML $Header;
$_ .= $post; # put header back together
unless (m/(<!-- SGI_HELPID:$token--><\/A>)(<b>)?([^<>]*)\s*(<\/b>)?\s*(<\/h[1-4]>)/) {
$_ .= <ARGV>;
unless (m/(<!-- SGI_HELPID:$token--><\/A>)(<b>)?([^<>]*)\s*(<\/b>)?\s*(<\/h[1-4]>)/) {
die "$ARGV($.): missing title for section \"$fn\".\n";
}
}
($pre, $title, $post) = ($`, $3, $5 . $');
$title =~ s/ with the GUI//i; # remove extraneous text
print HTML $title;
print HTML $Body;
$_ = $pre . $title . $post; # and put it back together
&fixup();
print HTML $_;
next;
}
if (m/(<h[1-4] class="SGITPL-head">|<\/BODY>|<p>Figure [0-9])/) {
if ($fn) {
$_ = $`; # everything up to match (if anything)
&fixup();
print HTML $_;
print HTML $Footer;
close(HTML);
$fn = "";
}
next;
}
if (eof) {
if ($fn) {
die "$ARGV($.): end of section \"$fn\" not found.\n";
}
close(ARGV);
next;
}
if ($fn) {
&fixup();
print HTML $_;
next;
}
END {
print "${O}: $count files created.\n";
}
sub fixup {
unless ($Title) {
die "$ARGV($.): missing <TITLE> tag at head of document.\n";
}
s/<A HREF="$PartNo\_([0-9]+).html\#.*" TARGET=_top>([^<>]*)<\/A>/$2 in Chapter $1/g;
s/Chapter\s+[0-9]+/$& of the <CITE>$Title<\/CITE>/g;
s/<img\s[^>]+>//gi;
s/ -> / -> /g;
s/&(?![a-z0-9#]+;)/&/gi;
}