#! /bin/sh
#
# @(#)showobjvars	1.11	LPS_UNX_COM	2/19/95
#
# Copyright 1994   Digital Equipment Corporation, Maynard, MA
#
# showobjvars
#
# This script presents a formatted attribute-oriented display on stdout
# of the specified set of object variables for the named object.
#
# NOTE:  Due to the special handling done for PS objects, there
#        is a VERY TIGHT BINDING between this script and the
#        format of variable display as done by lpsodblist!
#
# Parameters:
#    $1 - Class identifier, one of {PC, PS, MC, ENV}
#    $2 - Object name, should be null for the ENV class
#    $3 - Path of the attribute list file
#
# Note that support for the ENV class has not yet been implemented.
#
# Global variables:
#    FUNCS
#    LPSODB
#    LPSODBLIST
#    All object variables of the specified class
#
# Exit values:
#    0 - Failure, some sort of problem occurred; this should be
#	 relatively rare, and if it occurs, then something very
#	 bad has happened to our environment.
#   >0 - Success, the exit value represents the number of variable value
#        lines written to stdout (does not include descriptive header lines).
###

CLASS=$1
OBJNAME=$2
ATTRLIST=$3

# Import the standard shell function library, and export all
# object variables of the specified class for use by the
# LPSODBLIST utility.

if . $FUNCS
then
    expobjvars $CLASS
else
    exit 0
fi

# Count the number of attributes in $ATTRFILE

varcnt=`wc -l < $ATTRLIST`

# Resolve the object "description" string for use in the display header

OBJDESC="`getobjdesc $CLASS`"

# Display the header, then dump out the object variable descriptions
# and current values for all variables listed in the $ATTRLIST file.

echo
echo "    Current configuration for $OBJDESC $OBJNAME:"
echo

$LPSODBLIST -f $LPSODB -A $ATTRLIST -P "${CLASS}_"

# If this is a PS object, then display all $CONFIG file variables

if [ $CLASS = PS ]
then
    export TMPDIR	# For any subscripts invoked

    # Create a function used to display a single variable and its value
    #
    # Params:  $1=quoted description string, $2=quoted variable value

    varline ()
    {
	desc="$1"
	val="$2"

###	if [ -z "$val" ] ; then val="(not set)" ; fi

	varcnt=`expr $varcnt + 1`

	if [ $varcnt -lt 10 ]
	then
	    echo "   ${varcnt}) $desc  $val" ;
	else
	    echo "  ${varcnt}) $desc  $val" ;
	fi
    }

    # Display all PS-specific configuration variable descriptions and values

    varline "Password:                " "$PS_PASSWORD"
    varline "Enable accounting:       " "$PS_ACCOUNTING"
    varline "Enable event logging:    " "$PS_LOGGING"
    varline "Front panel language:    " "`getlangname $PS_LANGUAGE`"
    varline "Gateway address:         " "$PS_GATEWAY"
    varline "Deny internet addresses: " "$PS_DENYIP"
    varline "Allow internet addresses:" "$PS_ALLOWIP"
    varline "Deny DECnet addresses:   " "$PS_DENYDN"
    varline "Allow DECnet addresses:  " "$PS_ALLOWDN"
    varline "Enable SNMP:             " "$PS_ENABLESNMP"
    varline "Location:                " "$PS_SYSLOCATION"
    varline "Contact:                 " "$PS_SYSCONTACT"
    varline "Enable SNMP traps:       " "$PS_ENABLETRAPS"
    varline "SNMP communities:" " "
    echo
    dispcfgtab "$PS_COMMUNITIES" communities false
    echo
    varline "SNMP trap destinations:" " "
    echo
    dispcfgtab "$PS_TRAPS" traps false
fi

exit $varcnt
