#! /bin/sh
prefix=/usr
exec_prefix=/usr

# Set defaults
OPT_f=""
OPT_m=""
OPT_q="-q b"
OPT_v=""
OPT_V=""
time_date_arg="now"

# Note that we use `"$@"' to let each command-line parameter expand to a 
# separate word. The quotes around `$@' are essential!
# We need TEMP as the `eval set --' would nuke the return value of getopt.
TEMP=`/usr/bin/getopt 'f:mq:vV' "$@"`

if [ $? != 0 ] ; then
    echo "batch: error parsing command-line arguments" >&2
    exit 1
fi

# Note the quotes around `$TEMP': they are essential!
eval set -- "$TEMP"

while true ; do
    case "$1" in
        -f) OPT_f="-f $2" ; shift 2 ;;
        -m) OPT_m="-m"; shift ;;
        -q) OPT_q="-q $2"; shift 2 ;;
        -v) OPT_v="-v"; shift ;;
        -V) OPT_V="-V"; shift ;;
        --) shift ; break ;;
        *) echo "batch: internal parsing error" >&2 ; exit 1 ;;
    esac
done

if [ ! -z "$*" ] ; then
    time_date_arg="$*"
fi

exec /usr/bin/at $OPT_f $OPT_m $OPT_q $OPT_v $OPT_V $time_date_arg