#!/bin/sh

usage () {
  cat << EOF
usage: topdf <pddpsource>.xml
EOF
  exit $1
}

infile="$1"

[ $# -eq 0 ] && usage 1

SOURCE_NAME="${infile##*/}"
SOURCE_STUB="${SOURCE_NAME%.xml}"

[ "${SOURCE_STUB}" = "${SOURCE_NAME}" ] && usage 1

xmllint >/dev/null --xinclude --postvalid "${infile}"
xsltproc --nonet --xinclude \
 -o "$SOURCE_STUB.fo" \
 /usr/share/xml/docbook/stylesheet/nwalsh/fo/docbook.xsl \
 "${infile}"

# FIXME need to run this twice, it should be check-wrapped too
pdfxmltex "$SOURCE_STUB.fo"
