# Backend to convert a DocBook file into a man page
# Send any comments to Jochem Huhmann <joh@revier.com>
# This program is under GPL license. See LICENSE file for details.

# Convert to *roff
HELPER=$SGML_BASE_DIR/docbook/utils-0.6.14/helpers/docbook2man-spec.pl
TMPDIR=`mktemp -d /tmp/man.XXXXXX` || \
 { echo >&2 "man backend: could not create secure temporary directory"; exit 1;}
trap 'rm -rf "${TMPDIR}"' EXIT
nsgmls $SGML_FILE > "${TMPDIR}/nsgmls.tmp"
sgmlspl $HELPER <"${TMPDIR}/nsgmls.tmp" 2>"${TMPDIR}/errs"
if [ $? -ne 0 ]
then
  cat "${TMPDIR}/errs"
  exit 1
fi

if grep unresolved "${TMPDIR}/errs" >/dev/null 2>&1
then
  echo "Resolving references.."
  sgmlspl $HELPER <"${TMPDIR}/nsgmls.tmp"
  if [ $? -ne 0 ]
  then exit 1
  fi
fi

exit 0
