#ident	"@(#)nlp.admin:menu/packagemgmt/lpmgmt/printers/enable_p	1.5"
## IDOC:   SCREEN 2.32: ENABLE PRINTER
#menu# Enable printer for printing

##+++ (help _H83)
#help#        You use the "enable" command to allow one or  more  printers
#help#        to  start printing requests queued for them.  You need to do
#help#        this after you have added a new printer  and  are  ready  to
#help#        bring  it  on  line,  after  you  have  finished servicing a
#help#        printer that you had earlier disabled, and if  you  need  to
#help#        manually re-enable a printer that was automatically disabled
#help#        because of a problem.
#help#
#help#        If new print requests had also been refused for  a  printer,
#help#        which  is  the  case with new printers, you may also want to
#help#        use the "accept" command in the  "printers"  menu  to  allow
#help#        requests to be accepted for the printer you enable.
##--- (help _H83)

##+++ (general)
echo "
Whenever you want to quit, type \"q\".
If you are not sure how to answer any prompt, type \"?\" for help,
or see the System Administrator's Guide.

If a default appears in the question, press the return key to use it.
"
##--- (general)

trap 'exit 0' 1 2 15
flags="-qq -k$$"

##+++ (functions)
chk_printer_list () {
# listof: printer-name
    while true; do
	RESP=`checkre ${flags} -fe \
		-H "$3" \
		"$1${SyStSt:+!printer-list!}" \
		$4 \
		'.*' ''`
	RESP=`echo ${RESP} | tr ',' ' '`
	if [ -z "${RESP}" ]; then : ${RESP:="$2"}; fi
	if [ -z "${RESP}" ]; then :; else if ( set -- ${RESP}
		while [ $# -gt 0 ]; do
			echo "$1" \
			| ( flags="-m1"; chk_name >/dev/null 2>&1 ) || exit 1
			shift
		done; exit 0
	); then return 0; fi
	fi
	echo '	You did not give a valid printer name.
	Separate multiple items with a comma or blank.'
    done
}
chk_name () {
	RESP=`checkre ${flags} -fe $4 \
		${2:+"-D$2"} -H "$3" \
		"$1${SyStSt:+!name!}" \
		'^[a-zA-Z0-9_]\{1,14\}$' \
			'A name can contain only 1 to 14 letters, digits, and underscores.' \
	`
}
##--- (functions)

##+++ (line 1)
echo \
"Enter the names of the printers that can start printing requests.
Separate multiple names with a space or comma."
##--- (line 2)

DEF=`cat ${TMPDIR:-/tmp}/PRT.\`basename \\\`tty\\\`\` 2>/dev/null`
while true
do
##+++ (2.32.3)
chk_printer_list \
	"${DEF:+(default: ${DEF})}" \
	"${DEF}" \
	"\
        You are expected to enter the name of the printer  you  want
        to enable.  If you don't know the name, enter \"q\" and select
        the \"status\" command from the \"printers\" menu, to get a list
        of  known  printers.   You  can  give  several  names if you
        separate them with spaces or commas.  \
"
OPT=${RESP}
##--- (2.32.3)

	enable ${OPT}
done
