#!/usr/bin/perl # $Id: make-book,v 1.2 2004/09/23 20:52:11 tomj Exp $ # Create a linear HTML book from a source file that contains an # ordered list of filenames/page numbers and page titles. # The two portions must be separated with a TAB. # Files must have the name of the page number, and .tif format; # eg. page 1 is 1.tif, 4-6 is 4-6.tif. Following the # page number/filename by a tab is an optional page # header or title. This title is applied to the browser # window. If one is not specified then the most-recent page # header is used (eg. you only need to specify it when # it changes; you can title all the pages in a chapter by: # # 11 Chapter Foo # 12 # 13 # ... # "meta page numbers" fill in certain useful things: # # !T /tab/ Title of document (becomes window title) # # There is no real list of metas, you have to # look at the code below. # Filename issues. $htmlext= "html"; # HTML file type $imageext= "png"; # !X image file type $index= "index.$htmlext"; # index filename $htmlpath= "Book"; # !P path to the HTML pages, $imagepath= "../png"; # !F path from HTML to images, # Defaults for items that are expected to be in the document. $title= "No !T title given"; # !T $desc= "No !D description given";# !D $css= "No !C stylesheet given"; # !C $home= "No !H home given"; # !H $header= ""; # optional page header text $last_header= "XX"; # so we can detect changes # Each line of the input source is processed, those that are not # metas each generate an HTML page. We need to read one-line-ahead # so that we can make the next/previous hrefs. my ($prev, $this, $next)= ("", ""); # the queue of pages open (I, ">$index") or die ("Can't create $index?!"); foreach (<>) { chomp; s/^\s*$//; next if /^$/; next if /^#/; # Extract the metas here. if (/^!/) { ($page, $txt)= split (/\t/); $htmlpath= $txt if $page eq "!P"; # path to HTML, $imagepath= $txt if $page eq "!F"; # path to images $imageext= $txt if $page eq "!X"; # image file extention $title= $txt if $page eq "!T"; # document title, $css= $txt if $page eq "!C"; # CSS stylesheet file $desc= $txt if $page eq "!D"; # document description, $home= $txt if $page eq "!H"; # document home, next; } # We keep a 3-deep queue of page entries, so that we can # make PREV, NEXT links. $prev= $this; # shift the queue, $this= $next; $next= $_; # add to the end, # This hack gets us ahead one line so that we have a "next". # It complicates outputting the last line when we reach # the end. next if $this eq ""; # await a page, # This kludge causes the index header junk to be output only # once. &start_index()if $prev eq ""; # Not every page reference has a title/header, eg. sequential # pages in a chapter. This remembers the title until it changes. # last_header is used to determine when to make a new table of # contents entry. ($page, $txt)= split (/\t/, $this); # remember $header= $txt if $txt ne ""; # new header # Now generate output. &print_toc ($page, $header) if $header ne $last_header; &print_page ($page, $header, $prev, $next); $last_header= $header; } # Now output the remaining page. ($page, $txt)= split (/\t/, $next); if ($txt ne "") { $last_header= $header; $header= $txt; } &print_toc ($page, $header) if $header ne $last_header; &print_page ($page, $header, $prev, ""); &end_index(); close I; ############################################################# # # Given a page number and header text, print one line # into the Table of Contents. sub print_toc { my $page= shift; my $hdr= shift; print I << "IDX";
  • Page $page, $hdr
  • IDX } ############################################################# # # Given a page number and header, and previous and next page # numbers, output the page with the page-image. sub print_page { my $page= shift; my $hdr= shift; my $prev= shift; my $next= shift; ($prev, $txt)= split (/\t/, $prev); # we only want ($next, $txt)= split (/\t/, $next); # page numbers open (F, ">$htmlpath/$page.$htmlext") or die ("Can't create file $htmlpath/$page.$htmlext\n"); print F << "P1"; $title $title$hdr

    [Back to document index]    P1 print F << "PREV" if $prev ne ""; [Previous page $prev]    PREV print F << "NEXT" if $next ne ""; [Next page $next] NEXT print F << "P2";


    P2 close F; } ############################################################# # # Output the header section of the index page. # sub start_index { print I << "H1"; $title $desc

    This is the LGP-21 Hardware Maintenance and Training Manual supplied with the machine, page-scanned at 150 dpi, 11.5" x 8.5" (U.S. A size). It contains operation, theory of operation (including a complete algebraic definition of all the machine logic), memory alignment procedures and a complete set of logic diagrams, photographs and schematics.

    The original manual, borrowed from the Computer Museum of America, was copied, then scanned on an ordinary flatbed scanner. Each page image was saved to a disk file, named with the original document's page number (eg. page 1-3 became disk file 1-3.tiff). A simple text file contains these page-numbers, ordered, and notable pages have a title or description separated from the page number by a tab character.

    These pages were then created with a Perl script that takes a simple text-file list of page number/filenames and descriptions, and creates all of the HTML. This allows updating the entire dataset easily and portably.

    H2 }