#!/bin/sh

# choices.sh - prints out the path to the user's Choices directory for
#              an application.
# This program contributed by Chris Arndt.

CHOICESPATH=${CHOICESPATH:-$HOME/Choices:usr/local/share/Choices:/usr/share/Choices}

if [ "x$1" = "x-r" ]; then
    READ="True"
    shift
fi

if [ "x$1" != "x" ]; then
    APP="$1"
fi
    


if [ -n "$READ" ]; then
    for dir in $(echo $CHOICESPATH | tr ':' ' ') "$APP_DIR"
    do
        if [ -d "$dir/$APP" ]; then
            echo "$dir/$APP"
            exit 0
	fi
    done
    exit 1
else
    if [ -z "${CHOICESPATH%%:*}" ]; then
        # first part of CHOICEPATH is empty, saving disabled
        exit 1
    elif [ -n "$APP" ]; then
        echo "${CHOICESPATH%%:*}/$APP"
    else
        echo "${CHOICESPATH%%:*}"
    fi
fi

exit 0
