#!/bin/sh
#
# if this site supports v9 the interactive monitor is the old "protop xx"
# it must be installed seperately but this script will act as a "shim"
# and pass along the path to the db from dblist.cfg
#
# you must edit the path to old protop.env at the bottom
#

. #ENVPT3#/bin/protopenv

TMPDIR=${TMPDIR-/tmp}
LOGDIR=${LOGDIR-/tmp}

MNAME="protop"

cd ${PROTOP}

if [ ! -d ${TMPDIR} ]
then
        mkdir ${TMPDIR}
fi

if [ ! -d ${LOGDIR} ]
then
        mkdir ${LOGDIR}
fi

errmsg()
{
	echo ""
	echo "${1}"
	echo ""
}

# save ${1} and shift the command args so that we can easily pass along $2 etc
#
# P1 is a "friendly name" in etc/dblist.cfg
#

P1=${1}

if [ -z "${P1}" ]
then
	errmsg "Please specify a friendly name in etc/dblist.cfg."
	exit
fi

shift
XDB=

if [ -f ${PROTOP}/etc/dblist.cfg ]	# search using "pipe" as the delimiter
then
	XDB=`grep "^${P1}|" ${PROTOP}/etc/dblist.cfg | awk -F"|" '{print $2}' 2>/dev/null`
else
	echo "No ${PROTOP}/etc/dblist.cfg!  You must use bin/dbmaint.sh to create friendly names first!"
	exit
fi

# if XDB has a value then we found a friendly name and the path is in XDB
#

if [ ! -z "${XDB}" ]					# friendly name!
then
	PARAM='-param '"${P1}"				# pass the friendly name into protop.p
else
	errmsg "Please specify a friendly name in etc/dblist.cfg."
	exit
fi

# this must be modified to point to where old style protop is intalled

. /home/ptxx/bin/protop.env

if [ -f ${XDB}.db ]
then
	${DLC}/bin/_progres -p ${MNAME}.p ${XDB} -pf etc/protop.pf -T ${TMPDIR}
else
	errmsg "${XDB}.db does not exist."
fi
