#!/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 - Divvun gramcheck version 0.3.10"
        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/bin/divvun-validate-suggest" ] && [ -e "$d"/errors.dtd ]; then
    dir="$d"
else
    dir=/usr/share/divvun-gramcheck
fi

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