#! /usr/local/bin/perl
# Script to read a tag-enhanced book of plots
# Copyright 1996, 1998 by Alexander Forst
# alex@complang.tuwien.ac.at
#
# This is my first Perl script. You are allowed to point out
# errors, make every change you like as long as you notify me
# and don't laugh. :-)
#
# usage: plt2html.pl ...
# outputs a number of files: pl0.html, pl1.html,...
#
# these constants are useful for parsing in different modes
# the variable $parseMode must be set to one of these values
#open(IN,"plots1.tag") || die("not found");
#open(IN,"tag.txt") || die("not found");
$parsePreamble = "<(author|date|length|genre|type|setting|monster|plot)>";
$parseAuthor = "?(author|email)>";
$parseEnd = "";
$parseVillain = "<(stats|list|/villain)>";
$parsePlot = "<(stats|list|villain|/plot)>";
$htmlFooter = <
[The Net Book of Plots Home Page]
EOT
&initParse;
$parseMode = "";
$otherText = ""; # Placeholder for text before and after plots.
# This text is stored in the file contents.html
$count = 0;
&newPlot;
while( &nextToken ) {
if( $token eq "" ) {
$otherText .= $text; # save text before and between plots
if( $plotTitle )
{
&outPlot;
$count++;
}
&newPlot;
&readTitle;
}
&readAuthor if( $token eq "" );
&readDate if( $token eq "" );
&readLength if( $token eq "" );
&readGenre if( $token eq "" );
&readType if( $token eq "" );
&readSetting if( $token eq "" );
&readMonster if( $token eq "" );
&readPlot if( $token eq "" );
}
$text = $otherText . $text;
&parseText;
$otherText = $text; # save text after all plots
&outPlot;
open( INDEX, ">contents.html" ) || die( "Cannot open contents.html" );
print INDEX "\n";
print INDEX "\n\nPlot Book: Contents\n";
print INDEX "\n";
print INDEX "\n\n";
print INDEX <Note:
This page contains editor's notes and any additional text of the
Net Books of Plots.
Contents
EOT
print INDEX $otherText;
print INDEX $htmlFooter;
print INDEX "\n";
close( INDEX );
open( INDEX, ">length.html" ) || die( "Cannot open length.html" );
print INDEX "\n";
print INDEX "\n\nPlots by length\n";
print INDEX "\n";
print INDEX "\n
Plots by length
\n";
foreach $key (sort(keys(%lengths))) {
print INDEX "
\n\n";
}
print INDEX $htmlFooter;
print INDEX "\n";
close( INDEX );
open( INDEX, ">genre.html" ) || die( "Cannot open genre.html" );
print INDEX "\n";
print INDEX "\n\nPlots by genre\n";
print INDEX "\n";
print INDEX "\n
Plots by genre
\n";
foreach $key (sort(keys(%genres))) {
print INDEX "
\n\n";
}
print INDEX $htmlFooter;
print INDEX "\n";
close( INDEX );
open( INDEX, ">type.html" ) || die( "Cannot open type.html" );
print INDEX "\n";
print INDEX "\n\nPlots by type\n";
print INDEX "\n";
print INDEX "\n
Plots by type
\n";
foreach $key (sort(keys(%types))) {
print INDEX "
\n\n";
}
print INDEX $htmlFooter;
print INDEX "\n";
close( INDEX );
open( INDEX, ">setting.html" ) || die( "Cannot open setting.html" );
print INDEX "\n";
print INDEX "\n\nPlots by setting\n";
print INDEX "\n";
print INDEX "\n
Plots by setting
\n";
foreach $key (sort(keys(%settings))) {
print INDEX "
\n\n";
}
print INDEX $htmlFooter;
print INDEX "\n";
close( INDEX );
open( INDEX, ">monster.html" ) || die( "Cannot open monster.html" );
print INDEX "\n";
print INDEX "\n\nPlots with special monster\n";
print INDEX "\n";
print INDEX "\n
Plots with special monsters
\n";
foreach $key (sort(keys(%monsters))) {
print INDEX "
\n/g; # paragraphs
$text =~ s/([_*+])(\w+)\1/$2<\/em>/g; # emphasis
}
# read the next token --> $token
# the text before the token is stored
# in $text
sub nextToken {
$text =""; # clear the text
do {
if( $parse ) { # we have a parse line
if( $parse =~ m/$parseMode/i ) { # we found a token
$text .= $`; # save the text before the token
$token = $&; # this is the token
$token =~ tr/A-Z/a-z/; # change to lowercase
$parse = $'; # parse the rest of the line
return 1; # success!
} else {
$text .= $parse; # save all text
$parse = ""; # nothing left to parse
}
}
} while( $parse = <> ); # read next line
return 0; # it was the last line
}
sub initParse {
$parse = "";
%titles = ();
%authors = ();
%lengths = ();
%genres = ();
%types = ();
%settings = ();
%monsters = ();
}