#!/bin/sh

print_help()
{
    printf "%s\n" "
Usage:
auserdd DATA
auserdd --help|--version

List all data words for given DATA id.

See \"man any\", \"man rdd\" for further details.
"
}

local_which()
{
    arg="$1"

    if test -x "${arg}" ; then
        printf "%s\n" "${arg}"
        return 0
    fi

    IFS=:
    for dir in ${PATH} ; do
        if test -x "${dir}/${arg}" ; then
            printf "%s\n" "${dir}/${arg}"
            return 0
        fi
    done
    return 1
}

# find libraries

name_exec="${0}"
base_dir="${name_exec%/*}"
if test "${base_dir}" = "${name_exec}" ; then
    expanded_exec="$(local_which ${name_exec})"
    base_dir="${expanded_exec%/*}"
fi
# step one dir behind
RDD_BASEDIR="${base_dir%/*}"

if test -f "${RDD_BASEDIR}/lib/rdd/rddause.sh" ; then

    . "${RDD_BASEDIR}/lib/rdd/rddcmd.sh"
    . "${RDD_BASEDIR}/lib/rdd/rddause.sh"

else
    printf "%s\n" '
No rdd libraries were found.
Normally they are expected in ${RDD_BASEDIR}/lib/rdd/ subdirectory with the same relative root, as for ${RDD_BASEDIR}/bin/this_executable.
'
    exit 1
fi

case "$1" in
    --help)
            print_help
            exit 0
        ;;
    --version)
            printf "%s\n" "${RDD_VERSION}"
            exit 0
        ;;
esac

rdd_ause "${@}"
