#!/bin/bash # $Id: tocgen.sh,v 1.2 2004/01/30 06:17:34 mitch Exp $ # # This script adds a Table of Contents to an HTML document. # # Copyright (c) 2002-2003, FullSpan Software (www.fullspan.com) # Usage subject to terns in license.html USAGE=\ " Usage: tocgen.sh INFILE OUTFILE STYLESHEET Adds a Table of Contents to an HTML document. " if [ $# -ne 3 ]; then echo -e "$USAGE" exit 1 fi INFILE="$1" OUTFILE="$2" STYLESHEET="$3" BKFILE="$INFILE".bak TMPFILE1="$INFILE".tmp1 TMPFILE2="$INFILE".tmp2 if [ ! -e "$INFILE" ]; then echo "Input file does not exist: $INFILE" exit 1 fi if [ ! -e "$STYLESHEET" ]; then echo "Stylesheet file does not exist: $STYLESHEET" exit 1 fi # Make a backup copy if the outfile is the same as the infile if [ "$INFILE" == "$OUTFILE" ]; then cp "$INFILE" "$BKFILE" fi tidy -quiet --indent auto --indent-spaces 3 --tab-size 3 --wrap 0 \ --break-before-br yes --enclose-text yes \ --enclose-text yes --tidy-mark no \ --output-xhtml yes --add-xml-space yes --doctype loose \ -o "$TMPFILE1" "$INFILE" # Bail out if there are errors (Tidy exit code 2), but keep going if # there are warnings (Tidy exit code 1) or if Tidy exits with # no errors or warnings (exit code 0) if [ $? -ge 2 ]; then echo "Error(s) occurred during HTML Tidy" exit 1 fi java bsh.Interpreter tocgen.bsh "$TMPFILE1" "$TMPFILE2" "$STYLESHEET" tidy -quiet --indent auto --indent-spaces 3 --tab-size 3 --wrap 0 \ --break-before-br yes --enclose-text yes \ --enclose-text yes --tidy-mark no \ --output-xhtml yes --add-xml-space yes --doctype loose \ -o "$OUTFILE" "$TMPFILE2" rm "$TMPFILE1" rm "$TMPFILE2"