#ident	"@(#)nlp.admin:menu/packagemgmt/lpmgmt/printers/accept_p	1.5"
## IDOC:   SCREEN 2.23: ACCEPT PRINT REQUESTS
#menu# Allow printer to accept print requests

##+++ (help _H44)
#help#        You use the "accept" menu to let print requests be  accepted
#help#        for  a printer or class of printers.  You must do this after
#help#        adding a new printer because the LP Print Service holds  off
#help#        accepting any requests for the printer until you've finished
#help#        defining it.  You tell the print service you're  done  using
#help#        the  "accept"  command.  You may also need to stop accepting
#help#        requests at a later time, perhaps because you wish  to  take
#help#        the  printer  out  of service for repair or because too many
#help#        requests are backed up in queue for the printer.   When  the
#help#        printer is  ready  for service again you'll use the "accept"
#help#        command.
##--- (help _H44)

##+++ (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 or printer classes
that can start accepting print requests.
Separate multiple names with a space or comma."
##--- (line 3)

DEF=`cat ${TMPDIR:-/tmp}/PRT.\`basename \\\`tty\\\`\` 2>/dev/null`
while true
do
##+++ (2.23.4)
chk_printer_list \
	"${DEF:+(default: ${DEF})}" \
	"${DEF}" \
	"\
        You are expected to enter the name of the printer or printer
        class  that  is now ready to accept print requests.  You can
        give more than one name by separating them with a  space  or
        comma.

        Note that accepting print requests  for  a  printer  is  not
        enough  to  cause  them  to print.  The printer must also be
        enabled, using the \"enable\" command in the \"printers\"  menu.
        The  LP Print Service does not start printing requests until
        it is told by you that the printer is  ready:   powered  on,
        with paper loaded, with the proper form loaded, etc.  \
"
OPT=${RESP}
##--- (2.23.4)

	/usr/lib/accept ${OPT}
done
