#! /usr/bin/perl
#
# ../../scripts/story.pl raw/story.txt raw/title.html raw/overview.html
#
open(STORY_FP, $ARGV[0]) || die "Can't open STORY_FP: $!\n";
#
# Get the maximum number of pages.
#
$iMaxPages = 0;
$iLine = 0;
while () {
if ($iLine == 66) {
$iMaxPages++;
$iLine = 0;
}
$iLine++;
}
$iPage = 0;
open(PAGE_FP, ">page_" . $iPage . ".tmp") || die "Can't open PAGE_FP: $!\n";
$iLine = 0;
seek(STORY_FP, 0, 0);
print PAGE_FP "\n";
wringer: while () {
chop $_;
if ($iLine == 66) {
$iNext = $iPage + 1;
$iPrev = $iPage;
print PAGE_FP "
\n";
close PAGE_FP;
$iPage++;
open(PAGE_FP, ">page_" . $iPage . ".tmp") || die "Can't open PAGE_FP: $!\n";
$iLine = 0;
print PAGE_FP "\n";
} elsif ($_ eq "") {
print PAGE_FP "
\n";
$iLine++;
next wringer;
}
print PAGE_FP $_ . "\n";
$iLine++;
}
print PAGE_FP "
\n";
close PAGE_FP;
close STORY_FP;
#
# Now loop over each temp page and create the html version!
#
open(INDEX_FP, ">index.html") || die "Can't open INDEX_FP: $!\n";
print INDEX_FP << "INTRO";
www.kanigix.org
INTRO
print INDEX_FP "\n";
open(TIT_FP, $ARGV[1]) || die "Can't open TIT_FP: $!\n";
while () {
print INDEX_FP;
}
close TIT_FP;
print INDEX_FP "\n
\n\n";
open(OUTLINE_FP, $ARGV[2]) || die "Can't open OUTLINE_FP: $!\n";
while () {
print INDEX_FP;
}
close OUTLINE_FP;
print INDEX_FP "\n\n";
for ($i = 0; $i <= $iMaxPages; $i++) {
print INDEX_FP " [" . $i . " ]";
open(PAGE_FP, ">page_" . $i . ".html") || die "Can't open PAGE_FP: $!\n";
print PAGE_FP << "INTRO";
www.kanigix.org
INTRO
print PAGE_FP "\n";
open(TIT_FP, $ARGV[1]) || die "Can't open TIT_FP: $!\n";
while () {
print PAGE_FP;
}
close TIT_FP;
print PAGE_FP "\n
\n\n";
$iNext = $i + 1;
$iPrev = $i;
if ($i == 0) {
print PAGE_FP "\n\n<< < ";
} else {
print PAGE_FP "\n\n
<< < ";
}
if ($i == $iMaxPages) {
print PAGE_FP $i . " > >> (Home)
\n\n";
} else {
print PAGE_FP $i . " > >> (Home)
\n\n";
}
open(TMP_FP, "page_" . $i . ".tmp") || die "Can't open TMP_FP: $!\n";
while () {
print PAGE_FP;
}
close TMP_FP;
unlink "page_" . $i . ".tmp";
if ($i == 0) {
print PAGE_FP "\n\n<< < ";
} else {
print PAGE_FP "\n\n
<< < ";
}
if ($i == $iMaxPages) {
print PAGE_FP $i . " > >> (Home)
\n\n";
} else {
print PAGE_FP $i . " > >> (Home) \n\n";
}
print PAGE_FP << "FINAL";