#!/bin/sh
# @(#) $Header: getspoolname,v 1.20 93/02/22 15:06:52 ss2 Exp $
#  modified: change the help about destination name.

OPTION=$1
DEFAULT=$2
TYPE=$3


while [ 0 ] 
do
  if [ -n "$DEFAULT" ]
  then
    echo ""
    $ECHO "Enter the lp destination name (default=$DEFAULT): $NL"
  else
    echo ""
    $ECHO "Enter the lp destination name: $NL"
  fi

  read SPOOLNM
  if [ "$SPOOLNM" = "q" ]
  then
    exit 1
  fi

  if [ "$SPOOLNM" = "" ]
  then
    if [ -n "$DEFAULT" ]
    then
      SPOOLNM=$DEFAULT
      break
    else
      continue
    fi
  fi

  if [ "$SPOOLNM" = "?" ]
  then
    case $OPTION in
      option6solaris)
        echo ""
        echo "Enter the name to be used as the destination (option -d) in a  "
	echo "\"lp\" command. "
	echo ""
        echo "The name is limited to 14 characters and must consist entirely"
        echo "of the characters A-Z, a-z, 0-9, and _ (underscore)."
        echo ""
        $QUITHELP
        continue
	;;
      option8solars)
        echo ""
        echo "Enter the name used as the destination in an \"lp\" command."
	echo "This destination is removed from the spooler."
	echo ""
	$QUITHELP
	;;
    esac
    continue
  fi
  case $OPTION in
    option6solaris)
      echo "$SPOOLNM" | grep '^[a-zA-Z0-9_]*$' > /dev/null
      VALID=$?
      if [ "$VALID" -eq 0 ]
      then
        # Name can be only 14 chars or less
        LENGTH=`expr "$SPOOLNM" : '.*'`
        if [ "$LENGTH" -gt 14 ]
        then
          VALID=1
        fi
      fi
      if [ "$VALID" -ne 0 ]
      then
        echo ""
        echo "$SPOOLNM is an invalid name.  The name is limited to 14"
        echo "characters and must consist entirely of the characters A-Z,"
        echo "a-z, 0-9, and _ (underscore)."
	echo ""
	continue
      fi
      ;;
  esac
  break
done

echo "$SPOOLNM" > $TMP/SPOOLNM
exit 0
