#!/bin/sh

# Copyright 1988-1991 Network Computing Devices, Inc.  All rights reserved.
# An unpublished work.

#ident "@(#)lw_maint	14.1	91/02/26"

MYNAME=$0
DIR=`dirname $0`

EXIT_OK=0
EXIT_USAGE=1
EXIT_ERROR=2

PS2NCD=$DIR/ps2ncd

if [ $# -ne 1 ]
then
    echo Usage: $MYNAME lw-name >&2
    exit $EXIT_USAGE
fi
ncd="$1"

# First get the interresting data from the printer.

set - `(echo /str 40 string def; \
        echo statusdict begin 25 sccbatch str cvs print pop end; \
        echo \( \) print; \
        echo statusdict begin 25 sccbatch pop str cvs print end; \
	echo \( \) print; \
	echo statusdict begin str printername print end; \
       ) | $PS2NCD "$ncd" 2>&1`

		shift	# date
		shift	# time
		shift	# ps2ncd
		shift	# ncd terminal name
parity="$1";	shift	# parity
baud="$1";	shift	# baud
printer="$*"

echo "Printer "$printer" has interface speed"
echo -n "currently set to "$baud" baud with "
case "$parity" in
    0) echo -n ignore ;;
    1) echo -n odd ;;
    2) echo -n even ;;
    3) echo -n no ;;
    *) echo -n unknown ;;
esac
echo " parity."

echo -n "What baud rate do you want? "
read baud

case "$baud" in
    9600| 19200| 38400)
	;;
    *)
	echo $baud is not a valid interface speed. >&2
	exit $EXIT_ERROR
	;;
esac

echo -n "What kind of parity setting do you want? "
read parity

case "$parity" in
    i| ignore)
	parity=0
	;;
    o| odd)
	parity=1
	;;
    e| even)
	parity=2
	;;
    n| no| none)
	parity=3
	;;
    *)
	echo $parity is not a valid parity setting. >&2
	exit $EXIT_ERROR
	;;
esac

echo -n "Enter printer password (try 0 if you haven't set one)? "
read password

(echo serverdict begin $password exitserver; \
 echo statusdict begin 25 $baud $parity setsccbatch end; \
) | $PS2NCD "$ncd"`
