#! /bin/csh -f

# don't let CTRL-C stop this script from continuing
onintr -

if (! $?QUARTUS_ROOTDIR) then
	setenv SCRIPT_PATH `dirname $0`

	if ("${SCRIPT_PATH}" == "") then
        # in case the dirname doesn't work, use "which" (slower)
		setenv SCRIPT_PATH `which $0 |& tail -1`
	endif

	if ("${SCRIPT_PATH}" == "." || "${SCRIPT_PATH}" == "") then
		setenv QUARTUS_ROOTDIR `dirname $cwd`
	else 
		setenv QUARTUS_ROOTDIR `dirname ${SCRIPT_PATH}`
	endif

	if ("${QUARTUS_ROOTDIR}" == "..") then
		setenv QUARTUS_ROOTDIR `dirname $cwd`
	endif
endif

if ( "${QUARTUS_ROOTDIR}" !~ /* ) then
	setenv QUARTUS_ROOTDIR `(cd ${QUARTUS_ROOTDIR} ; pwd)`
endif

#
# This is a special hh wrapper script that is setup to invoke hh from
# the MW 4.0.2 directory from the GUI, in the case that the original Quartus
# wrapper detected the Solaris 8 loader patch was missing.
#
setenv CMD_NAME hh
unsetenv QUARTUS_QENV
unsetenv MWHOME
setenv QUARTUS_MWHOME ${QUARTUS_ROOTDIR}/hh

source ${QUARTUS_ROOTDIR}/adm/qenv.csh

if ($QENV_STATUS != 0) exit $QENV_STATUS

# Need this so shell won't try to match a * or ? inside a quoted arg
set noglob=1

set cmd_line=
@ count=1;
while ($count <= $#argv)
	set cmd_line=($cmd_line \"$argv[$count]\")
	@ count++
end

# Need quotes around command with noglob set
eval exec "$CMD_NAME $cmd_line"
