#! /bin/sh
#
# @(#)yesno	1.4	LPS_UNX_COM	02/19/95
#
# Copyright 1993   Digital Equipment Corporation, Maynard, MA
#
# yesno
#
# A shell script to handle the mundane task of displaying a question
# and accepting either a response of either "y" or "n".  There are two
# parameters to this function:
#
#   $1 - The default (null) response, one of:
#		"y"  Default to "yes"
#		"n"  Default to "no"
#		"x"  No default, force the user to enter either "y" or "n"
#   $2 - The string comprising the response prompt (question) displayed
#        to the user.  This string should contain only the simple phrase
#	 of the question, with no trailing punctuation.  Also, the proper
#	 response list, including the default (if any) is automatically
#	 generated.
#
# Global variables:
#    ECHON
#
# The exit value is 0 for "yes", or 1 for "no".  Reasonable permutations
# of "yes" and "no" are also allowed.

: ${ECHON:="/bin/echo -n"}

defresp="$1"
quest="$2"

case "$defresp" in
    [Yy]* )  suffix="([y]|n)?" ;;
    [Nn]* )  suffix="(y|[n])?" ;;
        * )  suffix="(y|n)?" ;;
esac

question="$quest $suffix"

while true
do
    echo
    $ECHON "$question "
    read response
    case ${response:-"$defresp"} in
	[yY] | [yY][eE][sS] )  exit 0 ;;
	    [nN] | [nN][oO] )  exit 1 ;;
			  * )  echo "Please respond with either 'y' or 'n'" ;;
    esac
done
