# This file will always be taken in.  .login is now
# vestigial, and doesn't matter if first or second.

# Reset the CSHENV_DIR
# (TODO: Downgrade this from environment variable to shell variable)
unsetenv CSHENV_DIR
if( ! $?CSHENV_DIR ) then
	if( $?CSHENV_DEBUG ) then
		echo "CSHENV_DIR is not set.  Guessing it based upon "'${1}'": ${1}"
	endif
	# Done twice to strip out the hooks dir and the hook itself.
	setenv CSHENV_DIR ${1}_
	setenv CSHENV_DIR `dirname ${CSHENV_DIR}`
	setenv CSHENV_DIR `dirname ${CSHENV_DIR}`
	if( $?CSHENV_DEBUG ) then
		echo "CSHENV_DIR is auto set to ${CSHENV_DIR}"
	endif

	if( "." == $#CSHENV_DIR ) then
		if( $?CSHENV_DEBUG ) then
			echo "CSHENV_DIR is still not set.  Using guessed default."
		endif

		set cshenv_fallback_dir
		setenv CSHENV_DIR ~/cshenv
	endif
endif

if( $?CSHENV_DEBUG ) then
    echo "Set (in tcshrc hook) CSHENV_DIR to: " ${CSHENV_DIR}
endif

alias _debug "eval 'if ( $?CSHENV_DEBUG ) echo \!*'"
_debug "Debug setup..."
_debug "Debug setup... (Paren test)"

setenv LC_NUMERIC en_US.UTF-8
setenv LC_MEASUREMENT en_US.UTF-8
setenv LC_MONETARY en_US.UTF-8
setenv LC_TIME en_US.UTF-8


# These are the bits that are in tcshrc

set CSHENV_TCSHRC_SOURCED

_debug "Starting tcshrc..."

if( -c `tty` ) then
	_debug "Going to source core tcshrc..."

    # Capture the original path, so that we don't
    # keep infinitely expanding it.
    if( $?CSHENV_ORIGINAL_PATH ) then
        setenv PATH "${CSHENV_ORIGINAL_PATH}"
    else
        setenv CSHENV_ORIGINAL_PATH "${PATH}"
    endif

    source ${CSHENV_DIR}/tcshrc
endif

# Not using tcshrc bits for non-login shells.  Will decide what to do later.

_debug "Ending tcshrc..."

###########################
# vim: ft=tcsh
###########################
