#! /bin/sh

# $Progeny$$

# This program is in the public domain.

# Too bad we don't have something like sysexits.h for POSIX sh...
EX_USAGE=64

@PROGENY_CONFIG_SCRIPT_VARS@
@PROGENY_CONFIG_SCRIPT_SET@

usage ()
{
    cat <<EOF
usage: $0 --VAR ...

Print the value of the variable VAR.  Run $0 -l or $0 --list for a list
of valid variable names.
EOF
}

listvars ()
{
    for i in ${VARS}; do
        echo ${i}
    done
}

have ()
{
    var=$1

    for i in ${VARS}; do
        if [ ${var} = ${i} ]; then
            return 0
        fi
    done

    return 1
}

###############################################################################

if [ $# -eq 0 ]; then
    usage
    exit ${EX_USAGE}
fi

while [ $# -gt 0 ]; do
    case $1 in
    -l|--list-vars)
        listvars
        break
        ;;

    --)
        usage
        exit ${EXIT_USAGE}
        ;;

    --*)
        var=$(echo $1 | sed -e 's/^--//' -e 's/-/_/g')
        if have ${var}; then
            eval val="\$${var}"
            echo ${val}
        else
            usage
            exit ${EX_USAGE}
        fi
        ;;

    *)
        usage
        exit ${EX_USAGE}
    esac

    shift
done

exit 0
