#!/usr/local/bin/perl
##
###########################################################################
##
##  Program:  slide-generator.pl
##
##  Purpose:  Generate a series of HTML slides based on a single formatted
##            HTML file.
##
##  Version:  1.0   13 Jan 1997
##
##  Author:   Peter Murray, Digital Media Services
##            Case Western Reserve University
##            http://www.cwru.edu/home/pem.html
##
##  Legalities:
##            Copyright 1997 by Case Western Reserve University.
##            All rights reserved.
##
##  Revision History:
##    13 Jan 1997  pem  Initial Release
##
## DOCUMENTATION, in PERL POD format, is at the end of the program.
## Running the program `perldoc <programname>` should output the manual.
##
$slide=1; $fileOpen = 0;
$forwardGif = "next.gif";
$backGif = "previous.gif";
$indexGif = "index.gif";
$logoHTML = "<FONT SIZE=-1>ALA/LITA Vendor/User Interest Group 1997<BR><B>World Wide Web Technologies in CWRU Libraries</B></FONT><HR>";
$bodyAttrib = "BGCOLOR=\"white\" VLINK=\"blue\"";

while (<>) {
  if (/<h1>(.+)<\/h1>/i) {
    @slides[$slide] = "H1|$slide|$1|";
    $indexSlide = $slide;
    $withinH2 = 0;
    $slide++;
    next;
  }
  if (/<h2>(.+)<\/h2>/i) {
    $withinH2 = 1;
    @slides[$slide] = "H2|$slide|$1";
    if ($fileOpen == 1) {
      $nextSlide = $slide;
      $prevSlide = $slide-2;
#      print OUTFILE "<A HREF=\"slide".$nextSlide.".html\"><img ALIGN=right BORDER=none ALT=\"forward\" SRC=\"$forwardGif\"></A>\n";
#      print OUTFILE "<A HREF=\"slide".$indexSlide.".html\"><img ALIGN=right BORDER=none ALT=\"index\" SRC=\"$indexGif\"></A>\n";
#      print OUTFILE "<A HREF=\"slide".$prevSlide.".html\"><img ALIGN=right BORDER=none ALT=\"back\" SRC=\"$backGif\"></A>\n";
#      print OUTFILE "<HR><FONT SIZE=-1>IUG '97</FONT></BODY>\n</HTML>\n";
      print OUTFILE "</BODY>\n</HTML>\n";
      close OUTFILE;
    }
    $nextSlide = $slide+1;
    $prevSlide = $slide-1;
    open(OUTFILE,">slide${slide}.html") || die "Cannot open slide${slide}.html: $!\n";
    print OUTFILE "<HTML>\n<HEAD>\n<TITLE>$1</TITLE>\n</HEAD>\n<BODY $bodyAttrib>\n";
    print OUTFILE "<A HREF=\"slide".$nextSlide.".html\"><img ALIGN=right BORDER=none ALT=\"forward\" SRC=\"$forwardGif\"></A>\n";
    print OUTFILE "<A HREF=\"slide".$indexSlide.".html\"><img ALIGN=right BORDER=none ALT=\"index\" SRC=\"$indexGif\"></A>\n";
    print OUTFILE "<A HREF=\"slide".$prevSlide.".html\"><img ALIGN=right BORDER=none ALT=\"back\" SRC=\"$backGif\"></A>\n";
    print OUTFILE "$logoHTML\n";
    print OUTFILE "<H1>$1</H1>\n";
    $slide++;  $fileOpen = 1;
    next;
  }
  if ($withinH2 == 1) {
    print OUTFILE $_;
  } else {
    @slides[$slide-1] .= $_;
  }
}

close OUTFILE; $fileOpen = 0;

foreach $line (@slides) {
  my($header, $slide, $title, $htmlFrag) = split(/\|/, $line);
  if ($header eq "H1") {
    if ($fileOpen == 1) {
      print OUTFILE "</UL>\n</TITLE>\n</HTML>\n";
      close OUTFILE;
    }
    $nextSlide = $slide+1;
    $prevSlide = $slide-1;
    open (OUTFILE, ">slide${slide}.html") || die "Cannot open slide${slide}.html: $!\n";
    print OUTFILE "<HTML>\n<HEAD>\n<TITLE>$title</TITLE>\n</HEAD>\n<BODY $bodyAttrib>\n";
    print OUTFILE "<A HREF=\"slide".$nextSlide.".html\"><img ALIGN=right BORDER=none ALT=\"forward\" SRC=\"$forwardGif\"></A>\n";
    print OUTFILE "<A HREF=\"index.html\"><img ALIGN=right BORDER=none ALT=\"index\" SRC=\"$indexGif\"></A>\n";
    print OUTFILE "<A HREF=\"slide".$prevSlide.".html\"><img ALIGN=right BORDER=none ALT=\"back\" SRC=\"$backGif\"></A>\n"
      if ($slide < 1);
    print OUTFILE "$logoHTML\n";
    print OUTFILE "<H1>$title <I>index</I></H1>\n";
    print OUTFILE $htmlFrag;
    print OUTFILE "<UL>\n";
    $fileOpen = 1;
  } elsif ($header eq "H2") {
    print OUTFILE "<LI><A HREF=\"slide${slide}.html\">$title</A>\n";
  }
}

close OUTFILE;

open (OUTFILE, ">index.html") || die "Cannot open index.html: $!\n";
print OUTFILE "<HTML>\n<HEAD>\n<TITLE>IUG '97</TITLE>\n</HEAD>\n<BODY $bodyAttrib>\n";
print OUTFILE "<A HREF=\"slide1.html\"><img ALIGN=right BORDER=none ALT=\"forward\" SRC=\"$forwardGif\"></A>\n";
print OUTFILE "$logoHTML\n";
print OUTFILE "<H1>$1</H1>\n";
print OUTFILE "<UL>\n";
$firstOne = 1;
foreach $line (@slides) {
  my($header, $slide, $title) = split(/\|/, $line);
  if ($header eq "H1") {
    if ($firstOne != 1) {
      print OUTFILE "</UL>\n";
    }
    print OUTFILE "<LI><A HREF=\"slide${slide}.html\">$title</A>\n";
    print OUTFILE "<UL>\n";
  } elsif ($header eq "H2") {
    print OUTFILE "<LI><A HREF=\"slide${slide}.html\">$title</A>\n";
  }
  $firstOne = 0;
}
  
  
=head1 NAME

slide-generator.pl - Generate a series of HTML slides

=head1 SYNOPSIS

  slide-generator.pl  [ slide-file ]
 
=head1 DESCRIPTION

The slide generator script takes a specially-formatted HTML file an creates a series
of linked HTML "slides" complete with forward/backward navigation and slide index
pages. 

=head1 PARAMETERS

=over 4

=item [ slide-file ]

An HTML file formatted as specified below.  Alternatively, the HTML file can come from STDIN.

=back

=head1 SETUP

=over 4

=item 1.

Write your slides in one HTML document. 

=item 2.

Use an <H1>...</H1> tag for a main presentation point (such as "HTML, 
image, PDF browsers") as listed in the schedule. This will create a 
group of slides with their own index page. If you want to put a 
paragraph of text or other HTML code on the Main Presentation Point 
slide index page, include it before the first <H2>. 

=item 3.

Use an <H2>...</H2> tag to create a single slide within a presentation 
point. The title between the <H2>...</H2> becomes the title of the 
slide. 

=item 4.

Use any other legal HTML under the <H2> will be added as-is to the slide 
(including inline images and links to other places as you desire). 

=back

=head1 COPYRIGHT

Copyright 1997 by Case Western Reserve University.

=head1 AUTHOR

 Peter Murray
 Library Systems Manager
 Digital Media Services
 Case Western Reserve University
 pem@po.cwru.edu
 http://www.cwru.edu/home/pem.html

Updates available from http://www.cwru.edu/lit/homes/pem/projects/slide-generator.html

=cut


    
