#! /bin/sh

# Make sure we have an absolute path to the backend and stylesheet, as
# jw doesn't like relative paths...

STUFFPATH=`dirname $0`
if [ -n "${STUFFPATH##/*}" ]
then
    STUFFPATH=$PWD/$STUFFPATH
fi

DVI_PAGES=$1
FILENAME=$2

export DVI_PAGES

if [ "$1" == "" ]  || [ "$2" == "" ] ; then
  echo "Usage: $0 <page-nums> <parent-file>"
  echo "example: $0 42-50 rhl-cg-en.sgml"
  exit 1
fi

#
#Grab name of the SGML file without extension
#

FILENAME="`echo $FILENAME | sed 's,\.sgml$,,;s,\.sgm$,,'`"

# Generate index
jw -f docbook \
    -b $STUFFPATH/index \
    -d $STUFFPATH/stylesheets/redhat.dsl#html \
    -o $FILENAME-tmp \
    ${FILENAME}.sgml

# Generate PDF with generated index
jw -f docbook \
    -b $STUFFPATH/indexedpg-pdf \
    -d $STUFFPATH/stylesheets/redhat.dsl#print \
    ${FILENAME}.sgml

# Remove temp directory
echo -n Removing temp directory $PWD/$FILENAME-tmp...
rm -rf $PWD/$FILENAME-tmp
echo Done!

