#!/bin/sh

usage () {
    cat <<EOF
Usage:
  divvun-validate-suggest FILE - error if FILE is not valid error messages xml for divvun-suggest
EOF
}

case "$1" in
    -V|--version)
        echo "$0 - libdivvun version 0.3.12-alpha"
        exit
        ;;
    -h|--help)
        usage
        exit
        ;;
    "") usage
        exit 1
        ;;
esac

file="$1"

if [ ! -e "${file}" ]; then
    echo "ERROR: '${file}' file not found"
    exit 1
fi


# If it looks like we're not installed, use the errors.dtd of the same
# dir as this script; otherwise assume we're installed:
d=$(dirname "$0")
if [ "$0" != "/usr/local/bin/divvun-validate-suggest" ] && [ -e "$d"/errors.dtd ]; then
    dtd="$d"/errors.dtd
elif [ -e /usr/local/share/libdivvun/errors.dtd ] ; then
    dtd=/usr/local/share/libdivvun/errors.dtd
else
    echo "cannot find errors.dtd in $d or /usr/local/share/libdivvun"
    exit 1
fi

/usr/bin/xmllint --dtdvalid "${dtd}" --noout "${file}"
