#!/bin/ksh
#
# ident "@(#)bbprefs.sh 1.2     01/05/01 SMI"
#
# Copyright (c) 2000 by Sun Microsystems, Inc.
# All rights reserved.
#                       

# print the preferences from a dat file 
# $1 dat file
# $2 pref type (user_pref, lock_pref...)

. $BBROOT/etc/opt/SUNWbb/blackbox.rc

export PATH=/bin/. 

VARS=$BBPATH/config/vars.def

if [ $# != 2 ]; then
    echo "usage: $0 <dat file> <pref type>"
    exit 1
fi

IDSTR=`id $BBUSER`

if [ $? != 0 ]; then
    echo "unkown user: $BBUSER"
    exit 2
fi

UID=`echo $IDSTR | awk '{ print $1 }' | cut -f2 -d'=' | cut -f1 -d'('`

# need to set this, since it is used when sourcing $VARS
UPATH=/home/$BBUSER 

if [ -r $VARS ]; then
	. $VARS
fi

retv=0
(
    while [ $retv != 1 ]; do
	read desc value
	retv=$?
	if [ ${#desc} != 0 -a ${#value} != 0 ]; then
	    comment=`echo $desc | cut -d'#' -f1`
	    if [ ${#comment} != 0 ]; then
		doeval=0
		[[ x$value = x*\$* ]] && doeval=1
		print -n "$2($desc , "
		if [ $doeval = 1 ]; then
		    str="print -n $value"
		    [[ x$value = x\"* ]] && print -n " \""
		    nvalue=`eval $str`
		    print -n $nvalue
		    [[ x$value = x\"* ]] && print -n "\""
		    print " );"
		else
		    print " $value );"
		fi
	    fi
	fi
    done
) < $BBPATH/config/$1

