#! /bin/bash
#------------------------------------------------------------------------
# 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. 
#
#---->  Loop over arguments
for next in $@ ; do
    if [ `echo "$next" | grep -c '^/'` = 0 ]; then 
	next=`echo $PWD/$next | sed -e 's,/$,,g'`
    elif [ "$next" != "/" ]; then 
	next=`echo $next | sed -e 's,/$,,g'`
    fi

#---->  Add $next/bin to PATH
    case ":${PATH}:" in
    *:${next}/bin:*)
        ;;
    ::)
        PATH="${next}/bin"
	;;
    *)
        test -d "${next}/bin" && PATH="${next}/bin":${PATH}
	;;
    esac
    export PATH

#---->  Add $next/lib to LD_LIBRARY_PATH
    if [ -d ${next}/lib ]; then
	case ":${LD_LIBRARY_PATH}:" in
	    *:${next}/lib:*) 
                ;;
	    ::)
	        LD_LIBRARY_PATH=${next}/lib
		;;
	    *)
	        LD_LIBRARY_PATH=${next}/lib:${LD_LIBRARY_PATH}
		;;
	esac 
    fi

    if [ -d ${next}/lib64 ]; then
	case ":${LD_LIBRARY_PATH}:" in
	    *:${next}/lib64:*) 
                ;;
	    ::)
	        LD_LIBRARY_PATH=${next}/lib64
		;;
	    *)
	        LD_LIBRARY_PATH=${next}/lib64:${LD_LIBRARY_PATH}
		;;
	esac
    fi
    export LD_LIBRARY_PATH

#---->  Add $next/man to MANPATH
    if [ "`uname -s`" != "Linux" ]; then
	case ":${MANPATH}:" in
	    *:${next}/man:*)
	        ;;
	    ::)
		MANPATH=${next}/man:/usr/share/man
		;;
	    *)
		test -d ${next}/man && \
		MANPATH=${next}/man:${MANPATH}
		;;
	esac
	export MANPATH
    fi
done
