#! /bin/sh
#
# @(#)getPSrefs	1.3	LPS_UNX_COM	2/19/95
#
# Copyright 1993   Digital Equipment Corporation, Maynard, MA
#
# getPSrefs
#
# Shell script used to generate a list of names of all Print Client or
# Management Client objects that currently reference the specified PS object.
#
# The generated list is a generated on stdout, one name per line.  If
# there are no dependent objects, then nothing is output to stdout.
#
# There is essentially no error control in this script.  Errors are dumped
# to stderr.  If this script fails, then probably many other scripts will
# have failed before this one gets executed.
#
# Parameters:
#    $1 - PS object name
#    $2 - Class identifier, one of {PC, MC}
#
# The ENV class is not supported by this script.
#
# Global variables:
#    LPSODB
#    LPSODBLIST
#
# Exit values:
#    0 - Success, the list was generated on stdout (even if null)
#    1 - Failure of some kind, either in the command line or the LPSODB,
#	 where error messages are displayed on stderr; in this case,
#	 some output may have already been written to stdout.
###

PSNAME=$1
CLASS=$2

if [ -z "$PSNAME" ]
then
    echo "${0}: No PrintServer printer name specified!" 1>&2
    exit 1
fi

case $CLASS in
    PC ) OPT="-p" ; break ;;
    MC ) OPT="-m" ; break ;;
     * ) echo "${0}: Invalid class identifier: \"$CLASS\"" 1>&2
	 exit 1 ;;
esac

if CLIENTLIST="`$LPSODBLIST -f $LPSODB -c $CLASS`"
then
    for CLIENT in $CLIENTLIST
    do
	if psname="`$LPSODBLIST -f $LPSODB $OPT $CLIENT -v psname`"
	then
	    if [ "$psname" = $PSNAME ]
	    then
		echo $CLIENT
	    fi
	else
	    exit 1
	fi
    done
else
    exit 1
fi

exit 0
