# prompt - Get user input.
#
# Version 1.3
#
# Pre:
#    admin_dir - directory containing administration scripts
#    uprompt - prompt value
#    udefault - default value
# Post:
#    userin - user's response:
#     'Y', 'yes', and 'YES' are changed to 'y'
#     'N', 'no', and 'NO' are changed to 'n'
#
# If the user types 'exit', this routine forces exit of the script.
#
# This routine is sourced from csh.
#
# It uses the following utility scripts:
#   abort - abort and exit the top csh script
#
# Copyright (c) 1995 by
#
#    Confluent, Inc.
#    400 Spear St., Suite 207
#    San Francisco, CA 94105
#
# Voice: 415-764-1000
# Fax: 415-764-1008
# Internet: info@confluent.com
#
# Created: 950116 - jag
# Modified: 950314 - jag : Set onintr to abort only if enable_intr set
# Modified: 970110 - jag : Quote glob arguments

# If enable_intr is set, set onintr to abort; otherwise, ignore interrupts.
if ($enable_intr) then
  onintr cleanup_mark
else
  onintr -
endif

# Get the user input.
echo -n "["$udefault"]" $uprompt" "
set userin = $<

# Change a simple <return> to the default.
if ("$userin" == "") set userin = "$udefault"

# Perform filename expansion and echo the resulting user input.
set userin = `glob "$userin"`
echo $uprompt" $userin"

# Abort if 'exit' was specified.
if ("$userin" == "exit") goto cleanup_mark

# Change some synonyms to 'y' and 'n'.
switch ("$userin")
  case "Y":
  case "yes":
  case "YES":
    set userin = "y"
    breaksw

  case "N":
  case "no":
  case "NO":
    set userin = "n"
    breaksw
endsw

# Return.
exit

#----------------------------------------------------------------------
# Cleanup
#----------------------------------------------------------------------
cleanup_mark:

source $admin_dir/abort
