#******************************************************************************
#                       PACOR II SOFTWARE
#               Property of the U.S. Government
#                       NASA/GSFC/Code 560
#******************************************************************************
#
# UNIT NAME: .cshrc
#
# PURPOSE: To initialize the C-shell environment in order to compile and
#          execute ISTP DPS software in the Common Desktop Environment.
#
# INVOCATION METHOD: source .cshrc
#
# CHANGE HISTORY:
# Author        Change ID  Build/Release   Date      Description of Change
# ------        ---------  ------------- ---------   ---------------------
# R. Wiechert   ISTP        R1.0          06/09/97   Original
# R. Wiechert   ISTP        R1.0C         01/02/98   added xhost +
# R. Wiechert   ISTP        R1.0D         03/05/98   added .mycshrc
# R. Wiechert   ISTP        R1.1A         04/02/98   guess DISPLAY variable
#
# NOTES: The .login file should make sure that all $PATH variables
#        are set correctly.  This involves sourcing .dps_user_env
#        and .dps_compile_info to initialize the PICS environment.
#        A working environment is recorded in the comments below:
#
#setenv PATH /opt/local/lzp/bin:/opt/SUNWspro/bin
#setenv PATH "$PATH":/usr/ccs/bin:/usr/bin:/usr/sbin:/opt/local/bin
#setenv PATH "$PATH":/usr/dt/bin:/usr/openwin/bin
#setenv PATH "$PATH":/opt/lv401:/opt/local/parasoft/bin.solaris
#setenv PATH "$PATH":/oracle/app/oracle/product/7.3.2/bin:.
#setenv PATH "$PATH":/usr/ucb:$HOME/bin
#setenv LD_LIBRARY_PATH /opt/SUNWspro/lib
#setenv LD_LIBRARY_PATH "$LD_LIBRARY_PATH":/usr/dt/lib:/usr/openwin/lib
#setenv LD_LIBRARY_PATH "$LD_LIBRARY_PATH":/opt/local/parasoft/lib.solaris
#setenv LD_LIBRARY_PATH "$LD_LIBRARY_PATH":/oracle/app/oracle/product/7.3.2/lib
#setenv MANPATH /opt/local/parasoft/man:/opt/SUNWspro/man:/opt/local/man
#setenv MANPATH "$MANPATH":/usr/dt/man:/usr/man:/usr/openwin/share/man
#setenv ORACLE_SID WIND
#setenv PACOR2HOME /export/home/dev/dps1/wind
#setenv PICSHOME $PACOR2HOME/pics
#if ( -f $PICSHOME/.dps_user_env ) then
#source $PICSHOME/.dps_user_env
#else
#echo "WARNING: file not found: .dps_user_env"
#endif
#if ( -f $PICSHOME/.dps_compile_info ) then
#source $PICSHOME/.dps_compile_info
#else
#echo "WARNING: file not found: .dps_compile_info"
#endif
#cd
#
#******************************************************************************


if ( ! ${?DT} ) then

    # commands and environment variables not appropriate for desktop
    stty erase "^H" kill "^U" intr "^C" eof "^D" susp "^Z"

    # attempt to guess DISPLAY variable
    if ( ! ${?DISPLAY} ) setenv DISPLAY
    set GUESSHOST=`expr "$DISPLAY" : '\(.*\):.*'`
    if ( "$GUESSHOST" == "" ) then
        set GUESSDISPLAY=`who -m| awk '{ print $6 }'`
        set GUESSHOST=`expr "$GUESSDISPLAY" : '..*\(:\).*'`
        if ( "$GUESSHOST" == ":" ) then
            # extract hostname from (hostname:*), may be null
            set GUESSHOST=`expr "$GUESSDISPLAY" : '.\(.*\):.*'`
        else
            # extract hostname from (hostname), null on error
            set GUESSHOST=`expr "$GUESSDISPLAY" : '.\(.*\).'`
        endif
    endif
    if ( "$GUESSHOST" == "" ) then
        # unable to determine hostname, use netstat to get IPaddress
        set GUESSHOST=`netstat -n -I hme0| tail -1| awk '{ print $4 }'`
    else
        # convert hostname to dotted decimal IPaddress
        set GUESSDISPLAY=`expr "$GUESSHOST" : '\([0-9].*\..*\..*\..*\)'`
        if ( "$GUESSDISPLAY" == "" ) then
            # lookup IPaddress in /etc/hosts file, return null for unknown IPaddress
            set GUESSDISPLAY=`grep "$GUESSHOST" /etc/hosts| tail -1| awk '{ print $1 }'`
        endif
        # converted IPaddress or null
        set GUESSHOST="$GUESSDISPLAY"
    endif
    # alter DISPLAY variable only if we guessed a valid IPaddress
    set GUESSDISPLAY=`expr "$GUESSHOST" : '\([0-9].*\..*\..*\..*\)'`
    if ( "$GUESSDISPLAY" != "" ) then
        set GUESSDISPLAY="$GUESSDISPLAY":0.0
        set GUESSHOST=`expr "$DISPLAY" : '\([0-9].*\..*\..*\..*\)'`
        if ( "$GUESSHOST" == "" ) then
            echo "Assuming DISPLAY should be set to $GUESSDISPLAY"
            echo "Try telnet instead of rlogin if this is wrong"
        endif
        setenv DISPLAY "$GUESSDISPLAY"
    endif

endif
 

if ( $?prompt ) then

    set history=50             # number of commands to save
    set savehist=$history      # number saved to ~/.history
    unset autologout           # automatic logout option
    unset ignoreof             # ctrl-D logout option
    set mail=300               # seconds between mail calls
    set filec                  # auto filename completion
    set fignore=.o             # ignore filename.extensions
    set notify                 # asynchronous job notification
 
    alias setprompt 'set prompt="`/usr/bin/hostname`:`/usr/ucb/whoami`[`pwd`]\!=> "'
    alias cd 'cd \!*;setprompt'
    setprompt
 
    setenv EDITOR /bin/vi
    setenv EXINIT 'set sh=/bin/csh'
 
    setenv PAGER  more # pg = page program, more = simple more
    setenv MORE   ""   # -c = clear screen first
 
endif


umask 022 # -rw-r--r-- mask
limit descriptors unlimited
source ~/.alias
if ( -f ~/.mycshrc ) then
   source ~/.mycshrc
else
   echo "Please edit .mycshrc to personalize your environment."
   echo "Please do NOT modify the .cshrc and .alias files."
endif
exit
