#!/bin/bash

# file: $ISIP_IFC/login/shell_bashrc.sh
# version: $Id: shell_bashrc.sh 10639 2007-01-26 22:55:17Z tm334 $
#
# this is the standard .bashrc file.
# a user should execute this file at the top of their personal
# bashrc file.
#

# important definitions
#
PROGRAM_NAME="$0";

DEFAULT_ISIP_TERM="vt100";

DEFAULT_ISIP="/data/isip";
DEFAULT_ISIP_WEB="/data/isip/www";
DEFAULT_ISIP_IFC="$DEFAULT_ISIP/tools/ifc";
DEFAULT_ISIP_DATA="$DEFAULT_ISIP/data";
DEFAULT_ISIP_PROTO="$DEFAULT_ISIP/tools/proto";

DEFAULT_ISIP_SERVER="yavin";

DEFAULT_ISIP_UMASK="002";
DEFAULT_ISIP_HISTSIZE="1024";
DEFAULT_ISIP_INDEX_FILE="$HOME/.isip_index";

DEFAULT_ISIP_EDITOR="emacs";
DEFAULT_ISIP_EDITOR_INIT_FILE="$HOME/login/editor_emacs_init.el";
DEFAULT_ISIP_PRINTER="cavs2130";

DEFAULT_ISIP_XINITRC="$HOME/login/x11_xinitrc.sh";
DEFAULT_ISIP_TWMRC="$HOME/login/x11_twmrc.sh";
DEFAULT_ISIP_XTERM="xterm";

DEFAULT_CVSROOT="$DEFAULT_ISIP/tools/cvsroot";
DEFAULT_ISIP_VERSION="ver_0"

#------------------------------------------------------------------------------
# general isip stuff goes here:
#  this section usually sets the path, defines environment variables, etc.
#------------------------------------------------------------------------------

# define the location of the isip environment
#
ISIP=${ISIP:-"$DEFAULT_ISIP"};
if (test ! -d "$ISIP") then
    echo "<$PROGRAM_NAME> the isip environment is not properly set up!";
    #exit -1;
fi

isip="$ISIP";
export ISIP isip;

# define the location of the isip web disk
#
ISIP_WEB=${ISIP_WEB:-"$DEFAULT_ISIP_WEB"};
if (test ! -d "$ISIP_WEB") then
    echo "<$PROGRAM_NAME> the isip environment is not properly set up!";
    #exit -1;
fi

isip_web="$ISIP_WEB";
export ISIP_WEB isip_web;

# define the location of the isip tools
#
ISIP_IFC=${ISIP_IFC:-"$DEFAULT_ISIP_IFC"};
if (test ! -d "$ISIP_IFC") then
    echo "<$PROGRAM_NAME> the isip tools environment is not properly set up!";
    #exit -1;
fi

isip_ifc="$ISIP_IFC";
export ISIP_IFC isip_ifc;

# define the location of isip data
#
ISIP_DATA=${ISIP_DATA:-"$DEFAULT_ISIP_DATA"};
if (test ! -d "$ISIP_DATA") then
    echo "<$PROGRAM_NAME> the isip tools environment is not properly set up!";
    #exit -1;
fi

isip_data="$ISIP_DATA";
export ISIP_DATA isip_data;

# define the location of the ISIP prototype system
#
ISIP_PROTO=${ISIP_PROTO:-"$DEFAULT_ISIP_PROTO"};
if (test ! -d "$ISIP_PROTO") then
    echo "<$PROGRAM_NAME> the isip prototype environment is not properly set up!";
fi
isip_proto="$ISIP_PROTO";
export ISIP_PROTO isip_proto;

# define environmental variables dependent upon $ISIP
#
DEFAULT_ISIP_WORDLIST="$ISIP_IFC/login/spell_ispell_wordlist.sh"
DEFAULT_ISIP_DEVEL=$ISIP

# define the location of the isip development environment. user's can
# override this definition if they set ISIP_DEVEL in their .bashrc
# file before this file is sourced.
#
ISIP_DEVEL=${ISIP_DEVEL:-"$DEFAULT_ISIP_DEVEL"};
if (test ! -d "$ISIP_DEVEL") then
    echo "<$PROGRAM_NAME> cannot find development environment!";
    echo "<$PROGRAM_NAME> using production directory $ISIP!";
    ISIP_DEVEL=$ISIP_IFC;
fi
export ISIP_DEVEL;

# define the type of machine and operating system being used:
# note: uname is not terribly portable. the command below is not backwardly
# compatible with all unix operating systems.
#
ISIP_BINARY=`sh $ISIP_IFC/config.guess`;
export ISIP_BINARY;

# define the home directories for some important tools:
#  note that these environment variables (containing the base location of the
#  tool) are required by other tools in the isip environment).
#
CLASSPATH=".:$ISIP/lib/java/varmint.jar";
export CLASSPATH;

# define paths which make the java plugin work under netscape communicator
#
JAVA_PLUGIN_PATH="$ISIP/common/java/jre1.5.0_07/plugin"
NPX_JRE_PATH="$ISIP/common/java/jre1.5.0_07"
export JAVA_PLUGIN_PATH NPX_JRE_PATH;

# initialize the path for the isip tools starting with
# the current working directory
#
PATH=".";

# add the ISIP OS extensions:
#  since we don't have root permissions, we need a place to
#  add OS-related stuff.
#
PATH="$PATH:$ISIP/common/bin:$ISIP/common/java/jre1.5.0_07/bin";
PATH="$PATH:/usr/bin";
PATH="$PATH:/usr/local/mysql/bin"; # NOT ON YAVIN
PATH="$PATH:$ISIP/common/java/jdk1.5.0_07/bin";
PATH="$PATH:$ISIP/tools/svnroot/hooks";
PATH="$PATH:$ISIP/tools/svnroot";
PATH="/opt/gcc/v41/bin:$PATH";

LD_LIBRARY_PATH="/usr/lib/gcc-lib/i386-redhat-linux/3.2.3";

alias gcc='gcc41';
alias g++='g++41';

# add the system-level directories and site-specific packages
#
PATH="$PATH:/usr/bin:/bin:/sbin:/usr/sbin";
PATH="$PATH:/usr/local/gnu/bin:/usr/local/bin:/usr/X11R6/bin"; # not yavin
PATH="$PATH:/usr/pbs/bin"; # not on yavin
PATH="$PATH:/usr/local/rational/releases/PurifyPlus.2003a.06.15/i386_linux2/bin"; # not on yavin

# add the isip script and architecture dependent binary directories to
# the path. if ISIP_DEVEL is equal to ISIP, only add them once. if
# they are different, then add ISIP_DEVEL before ISIP.
#
if (test "$ISIP_IFC" = "$ISIP_DEVEL") then
    PATH="$PATH:$ISIP_DEVEL/bin/scripts:$ISIP_IFC/bin/scripts";
    PATH="$PATH:$ISIP_IFC/bin/$ISIP_BINARY";
else
    PATH="$PATH:$ISIP_DEVEL/bin/scripts:$ISIP_IFC/bin/scripts";
    PATH="$PATH:$ISIP_DEVEL/bin/$ISIP_BINARY:$ISIP_IFC/bin/$ISIP_BINARY";
fi

# add the isip prototype scripts and architecture dependent binary
# directories to the path.
#
PATH="$PATH:$ISIP_PROTO/bin/scripts";
PATH="$PATH:$ISIP_PROTO/bin/$ISIP_BINARY";

# add speech-related packages
#
PATH="$PATH:$ISIP/common/bin"; # was linked to srilm, was broken
PATH="$PATH:$ISIP/common/nist/bin"; 

# export the path
#
export PATH;

# create a corresponding man path - give local customizations
# priority
#
DEFAULT_MANPATH="$DEFAULT_MANPATH:/usr/man";

# set the actual MANPATH
#
MANPATH=${MANPATH:-$DEFAULT_MANPATH};
export MANPATH;

# set xwindows library path: we finally decide to stick with Sun's openwin
#
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/openwin/lib:/usr/local/lib";
export LD_LIBRARY_PATH;

# define the isip libraries
#
ISIP_LIBS="-L$ISIP_DEVEL/lib/$ISIP_BINARY \
           -l_asr \
	   -l_pr \
	   -l_search \
           -l_sp \
           -l_algo \
           -l_stat \
	   -l_mmedia \
           -l_shell \
	   -l_numeric \
           -l_math_matrix \
           -l_math_vector \
           -l_math_scalar \
           -l_io \
	   -l_system \
           -lm";
export ISIP_LIBS;

# define the location of /tmp
#
ISIP_TMPDIR="/tmp";
export ISIP_TMPDIR;

# define compiler related things:
#  (1) the make file tool and priority
#  (2) the location of include files 
#  (3) the C++ compiler
#
ISIP_MAKE="nice -5 make";
ISIP_INCLUDE="-I$ISIP_DEVEL/include";
ISIP_CPLUS_COMPILER="g++32";
ISIP_CPLUS_OPTIMIZE="-O2";
export ISIP_MAKE ISIP_INCLUDE ISIP_CPLUS_COMPILER ISIP_CPLUS_OPTIMIZE;

# declare the location of a scratch file to be used to index tools
#
ISIP_INDEX_FILE=$DEFAULT_ISIP_INDEX_FILE;
export ISIP_INDEX_FILE;

# define some global error codes to be used for shellscripts
#
ISIP_NOERROR="0";
ISIP_ERROR="1";

#------------------------------------------------------------------------------
# general user-level stuff goes here:
#  this section usually defines things that affect the user's interactive
#  environment.
#------------------------------------------------------------------------------

# set LOGNAME: since this is expensive, we only want to do it once
#
# define a username variable:
#  doing this in a standard way is becoming increasingly difficult
#
ISIP_USERNAME=`/usr/bin/id | cut -f2 -d'(' | cut -f1 -d')'`;
LOGNAME="$ISIP_USERNAME";
export ISIP_USERNAME LOGNAME;

# set default protection
#
umask $DEFAULT_ISIP_UMASK;

# set core file size to something small (realistic)
#
ulimit -c 0;

# set history length
#
HISTSIZE=$DEFAULT_ISIP_HISTSIZE;

# prevent storing adjacent identical lines in the bash history
#
history_control="ignoredups";

# set the preferred printer
#  note that system V seems to use lpdest
#
PRINTER=${PRINTER:-"$DEFAULT_ISIP_PRINTER"};
LPDEST="$PRINTER";
export PRINTER LPDEST;

# set up some useful host names
#
ISIP_SERVER=${ISIP_SERVER:-"$DEFAULT_ISIP_SERVER"};
ISIP_HOST=`uname -n | cut -d. -f1`;
export ISIP_SERVER ISIP_HOST; 

# set the editor
#
unset EDITOR;
EDITOR=${EDITOR:-"$DEFAULT_ISIP_EDITOR"};
ISIP_EDITOR_INIT_FILE=$DEFAULT_ISIP_EDITOR_INIT_FILE;
export EDITOR ISIP_EDITOR_INIT_FILE;

# set x environment variables
#
ISIP_XINITRC="$DEFAULT_ISIP_XINITRC";
ISIP_TWMRC="$DEFAULT_ISIP_TWMRC";
export ISIP_XINITRC ISIP_TWMRC;

XINITRC="$ISIP_XINITRC";	
TWMRC="$ISIP_TWMRC";
XAPPLRESDIR="$DEFAULT_XAPPLRESDIR";
export XINITRC TWMRC XAPPLRESDIR;

# set their default xterm
#
ISIP_XTERM="$DEFAULT_ISIP_XTERM";
export ISIP_XTERM;

# setup version control
#
CVSROOT=${CVSROOT:-"$DEFAULT_CVSROOT"};
ISIP_VERSION=${ISIP_VERSION:-"$DEFAULT_ISIP_VERSION"};
CVSREAD=1
CVSEDITOR="emacs -l $ISIP_EDITOR_INIT_FILE"
export CVSROOT ISIP_VERSION CVSREAD CVSEDITOR;

# define a group dictionary
#
WORDLIST="$DEFAULT_ISIP_WORDLIST";
export WORDLIST;

REMOTE_USERNAME_00=${REMOTE_USERNAME_00:-"$ISIP_USERNAME"};
REMOTE_USERNAME_01=${REMOTE_USERNAME_01:-"$ISIP_USERNAME"};
REMOTE_USERNAME_02=${REMOTE_USERNAME_02:-"$ISIP_USERNAME"};
export REMOTE_USERNAME_00 REMOTE_USERNAME_01 REMOTE_USERNAME_02;

#------------------------------------------------------------------------------
#  interactive stuff goes here:
#  the commands below are to be executed for interactive shells only.
#  to determine if the shell is interactive, test for PS1.
#------------------------------------------------------------------------------
if (test -n "$PS1") then

    # update prompt
    #
    PS1=$ISIP_HOST"_[$SHLVL]: ";
    PS2=$ISIP_HOST"_[$SHLVL]? ";
    export PS1 PS2;

    # set some useful stuff for non-X terminal logins - a non-X
    # term has no DISPLAY set automatically.
    #

    if (test -z "$DISPLAY") then

	# set terminal type to the lowest common denominator - a vt100
	# (crude, but reliable)
	#
	TERM=${TERM:-"$DEFAULT_ISIP_TERM"};
	export TERM;

	# set USER, which for some reason does not always get set
	#
	USER="$ISIP_USERNAME";
	export USER;
    fi

    # setup dmalloc
    #
    #function isip_dmalloc { eval dmalloc -b -f $ISIP_IFC/login/debugger_gdb_dmallocrc.text $*;}

    #--------------------------------------------------------------------------
    # define some extremely useful commands:
    #
    # the commands defined here should satisfy two requirements -
    #  (1) no standard unix alias exist for these commands
    #  (2) the command name length is limited to two characters
    #
    # all other commands in the isip environment are prefaced with "isip_".
    # since some of the commands defined below are frequently used, they
    # are allowed to exist without a standard prefix. the downside of this
    # is that they might cause a conflict with commands from another
    # environment (for example, several years ago, the show file command
    # "sf" was eliminated because it caused conflicts with some third
    # party environments.
    #--------------------------------------------------------------------------

    # define directory commands:
    #  due to the nature of shell programming, these must be defined using
    #  functions, so that they can be part of the user level environment
    #  these must also be in the bashrc so that they are available for
    #  any shell.
    #
    p  () { echo $PWD; }
    sd () { pushd $1 > /dev/null; echo $PWD; }
    td () { pushd    > /dev/null; echo $PWD; }
    pd () { popd  $1 > /dev/null; echo $PWD; }

    # define useful short unix commands:
    #  these are designed to include the most common and useful featrues
    #  of standard unix commands
    #
    #d  () { ls -cblFa $*; }
    #f  () { finger -l $*; }
    #m  () { more $*; }

    # make sure the tty settings are reasonable
    #  in Solaris 2.4, and various versions of X, this is required
    #  to make backspace and delete work properly. the options selected
    #  here were the result of much experimentation. we used to use stty sane,
    #  but that forces a 7-bit stream, which breaks some modem/tty connections.
    #
    stty erase \^? intr \^c echoe;

    # end of interactive shell
fi


#
# end of file
