#! /bin/sh
#
# @(#)setDESCRIPTION	1.4	LPS_UNX_COM	02/19/95
#
# Copyright 1994   Digital Equipment Corporation, Maynard, MA
#
# setDESCRIPTION
#
# A script that produces a value for attribute DESCRIPTION.
#
# Parameters:
#    $1 - LPS class identifier, one of {PC, MC, PS, ENV}
#    $2 - Operating system type identifier (eg: SV2, BSD, etc)
#    $3 - Print client type identifier (eg: AIX, BSD, SV3, etc)
#    $4 - PrintServer printer model (eg: LPS17, LPS20)
#    $5 - Default value for the attribute
#    $6 - Path of the output file to receive the final attribute value
#
# Global variables:
#    ECHON
#    FUNCS
#    PAGER
#    TMPDIR
#    TR    (for the checknumrange() function)
#
# Exit values:
#    0 - Success, output file contains newly set attribute value.
#    1 - Error or interruption occurred, error messages go to stderr,
#	 contents of the output file are undefined.
###

CLASS=$1
OSTYPE=$2
PCTYPE=$3
PSMODEL=$4
DEFVAL=$5
OUTFILE=$6

. $FUNCS   # Import the standard LPS shell functions

QUESTION="How do you want to describe this object"

showhelp true "
${QUESTION}?

All LPS objects (PrintServer printers, Management Clients and Print Clients)
can have a description line defined for them.  The description can be any
string of text that you want.  Some examples might be:

    Printer next to Conference Room 101B

    Duplex-capable print queue

    Marketing printer #23

    Event logger for printer Saskwatch

Note that a few types of characters can not be used, including colon (\":\"),
backslash (\"\\\") and most control characters.  If you enter one of these
characters, it will be removed.

To end the text string, press the RETURN key.  You then will be shown
the string and asked to confirm its use.  If you don't like the string,
you can re-enter it when prompted.

If a description string already exists and you find it acceptable, then
simply press the RETURN key to retain that description.
"

if [ "$DEFVAL" ]		# To catch first time definitions
then
    confirm=true
else
    # For printers, set a default value describing the model

    if [ "$CLASS" = "PS" ]
    then
	DEFVAL=`getPSdesc "$PSMODEL"`
	confirm=true
    else
	confirm=false
    fi
fi

RESPONSE="$DEFVAL"

while true
do
    # To be ABSOLUTELY SURE we have filtered out all undesirable
    # characters, do the filtering process twice in succession.
    # Note, though, that even this approach can result in some
    # backslash chars getting thru...

    RESPONSE=`echo "$RESPONSE" | $TR -d '\:'`
    RESPONSE=`echo "$RESPONSE" | $TR -d '\:'`

    if $confirm
    then
	if [ "$RESPONSE" ]
	then
	    echo
	    echo "The description now reads:"
	    echo "$RESPONSE"
	else
	    echo
	    echo "The description is blank."
	fi

	if yesno y "Is this description acceptable"
	then
	    echo "$RESPONSE" > $OUTFILE
	    exit 0
	fi
    fi

    echo
    echo "Enter the description string, press RETURN when completed:"
    read RESPONSE

    confirm=true
done
