#!/bin/sh

# ask a question with a yes/no answer;
# Usage: ask [-y|-n] "question"
# Set default: -y = yes; -n = no; otherwise no default;
# Returns: 0 (true) = yes; 1 (false) = no;
# Note: changing the default does not effect the return value;
#
# [Thanks to Daniel E. Singer <des@cs.duke.edu> for providing
#  the "ask()" function]

ASK_DFLT=
# process options/args
for ASK_OPT do
 case "${ASK_OPT}" in
  -[yY]*) ASK_DFLT='y' ;;
  -[nN]*) ASK_DFLT='n' ;;
  --) shift; break ;;
  -*) ;;
  *) break
 esac
 shift
done
ASK_PROMPT="${*}"

# get the response
while : ; do
 ./extras/arch_hooks/echon "${ASK_PROMPT} (y/n)?${ASK_DFLT:+ [$ASK_DFLT]} " >&2
 read ASK_ANSWER ASK_JUNK

 : ${ASK_ANSWER:=$ASK_DFLT}

 case "${ASK_ANSWER}" in
  [yY]*)
   exit 0
   ;;
  [nN]*)
   exit 1
   ;;
  *)
  echo "" >&2
 esac
done
