#! /bin/csh -f
#------------------------------------------------------------------------
# Establish search path for the loader, linker, and man pages. If they
#   already exist in the environment variable or the directory doesn't
#   exist, then quietly ignore the request.
#
# shift
foreach next ($argv)
    if ( ! `echo "$next" | grep -c '^/'` ) then 
	set next=`echo $PWD/$next | sed -e's,/$,,g'`
    else if ("$next" != "/") then
	set next=`echo $next | sed -e's,/$,,g'`
    endif

#---------------------------------------------------------------------
# Establish PATH
#---------------------------------------------------------------------
    switch(":${PATH}:")
    case *":${next}/bin:"*:
	breaksw
    case "::":
	setenv PATH "${next}/bin"
	breaksw
    default:
	test -d "${next}/bin" && setenv PATH "${next}/bin":${PATH}
	breaksw
    endsw
#---------------------------------------------------------------------
# Establish LD_LIBRARY_PATH
#---------------------------------------------------------------------
    if (! $?LD_LIBRARY_PATH) setenv LD_LIBRARY_PATH
    if ( -d "$next/lib" ) then
	switch(":${LD_LIBRARY_PATH}:")
	case *":${next}/lib:"*:
	    breaksw
	case "::":
	    setenv LD_LIBRARY_PATH "${next}/lib"
	    breaksw
	default:
	    setenv LD_LIBRARY_PATH "${next}/lib":${LD_LIBRARY_PATH}
	    breaksw
	endsw
    endif
#
    if ( -d "$next/lib64" ) then
	switch(":${LD_LIBRARY_PATH}:")
	case *":${next}/lib64:"*:
	    breaksw
	case "::":
	    setenv LD_LIBRARY_PATH "${next}/lib64"
	    breaksw
	default:
	    setenv LD_LIBRARY_PATH "${next}/lib64":${LD_LIBRARY_PATH}
	    breaksw
	endsw
    endif
#---------------------------------------------------------------------
# Establish MANPATH
#---------------------------------------------------------------------
    if ("`uname -s`" != "Linux") then
	if (! $?MANPATH) setenv MANPATH
	switch(":${MANPATH}:")
	case *":${next}/man:"*:
	    breaksw
	case "::":
	    setenv MANPATH "${next}/man"
	    breaksw
	default:
	    test -d "${next}/man" && setenv MANPATH "${next}/man":${MANPATH}
	    breaksw
	endsw
    endif
end
unset next
rehash
exit 0
