#!/bin/csh -f
#
#	CVS ID: PVL_to_DB,v 1.3 2008/09/30 04:59:50 castalia Exp
#
# PVL_to_DB
#
# A wrapper for the PIRL Java Database PVL to database mapper.
#
# see http://pirlwww.lpl.arizona.edu/software/PIRL_Java_Packages/PIRL/PVL/PVL_to_DB.html
#
#	Environment variables used and their default values:
#
#	PIRL_JAVA_HOME - /opt/java
#		This may be a directory pathname where the PIRL subdirectory and
#		all its class files is located; or it may be the pathname to the
#		PIRL.jar file containing all dependencies. On Darwin systems the
#		~/Library/Java/Extensions and /Library/Java/Extensions directory
#		will be checked for the PIRL.jar file.
#
#	The following are used only if PIRL_JAVA_HOME is not a jar file.
#
#	MySQL_JDBC - $PIRL_JAVA_HOME/mysql-connector/mysql-connector.jar
#		The pathname to the MySQL JDBC driver jar file or the root
#		directory where its class files are located.
#		(http://dev.mysql.com/downloads/connector/j/)
#
#	PostgreSQL_JDBC - $PIRL_JAVA_HOME/PostgreSQL/postgresql.jar
#		The pathname to the PostgreSQL JDBC driver jar file or the root
#		directory where its class files are located.
#		(http://jdbc.postgresql.org/)
#
#	JCM - $PIRL_JAVA_HOME/jcm/jcm_data.jar
#		The pathname to the Java Components for Mathematics jar file or
#		the root directory where its class files are located.
#		(http://math.hws.edu/javamath)
#
#	CVS ID: PVL_to_DB,v 1.3 2008/09/30 04:59:50 castalia Exp

set OS = `uname -s`

#	Location of the PIRL Java Packages.
if (! $?PIRL_JAVA_HOME) then
	if ($OS == "Darwin") then
		if (-e ~/Libarary/Java/Extensions/PIRL.jar) then
			set PIRL_JAVA_HOME = ~/Libarary/Java/Extensions/PIRL.jar
		else
		if (-e /Libarary/Java/Extensions/PIRL.jar) then
			set PIRL_JAVA_HOME = /Libarary/Java/Extensions/PIRL.jar
		endif
		endif
	endif
	if (! $?PIRL_JAVA_HOME) \
		set PIRL_JAVA_HOME = /opt/java
endif
if (! -e ${PIRL_JAVA_HOME}) then
	echo "No such file or directory: ${PIRL_JAVA_HOME}"
	exit -1
endif
set classpath = $PIRL_JAVA_HOME


if ($PIRL_JAVA_HOME !~ "*.jar") then

	#	Database drivers:

	#	Location of the MySQL JDBC driver.
	if (! $?MySQL_JDBC) \
		set MySQL_JDBC = $PIRL_JAVA_HOME/mysql-connector/mysql-connector.jar
	if (! -e ${MySQL_JDBC}) then
		echo "No such file or directory: ${MySQL_JDBC}"
		echo "MySQL database support is not available."
		unset MySQL_JDBC
		unsetenv MySQL_JDBC
	else
		set classpath = ${classpath}:${MySQL_JDBC}
	endif

	#	Location of the PostgreSQL JDBC driver.
	if (! $?PostgreSQL_JDBC) \
		set PostgreSQL_JDBC = $PIRL_JAVA_HOME/PostgreSQL/postgresql.jar
	if (! -e ${PostgreSQL_JDBC}) then
		echo "No such file or directory: ${PostgreSQL_JDBC}"
		echo "PostgreSQL database support is not available."
		unset PostgreSQL_JDBC
		unsetenv PostgreSQL_JDBC
	else
		set classpath = ${classpath}:${PostgreSQL_JDBC}
	endif

	if (! $?MySQL_JDBC && ! $?PostgreSQL_JDBC) then
		echo "Conductor can not function without database support."
		exit 1
	endif


	#	External Java packages:

	#	Location of the Java Components for Mathematics.
	if (! $?JCM) \
		set JCM = $PIRL_JAVA_HOME/jcm/jcm_data.jar
	if (! -e ${JCM}) then
		echo "No such file or directory: ${JCM}"
		echo "The Java Components for Mathematics are required by Conductor."
		echo "See http://math.hws.edu/javamath"
		exit -1
	endif
	set classpath = ${classpath}:${JCM}

endif


exec java -cp $classpath PIRL.PVL.PVL_to_DB $argv:q
