#!/bin/ksh

case $0 in
-*)	alias z='echo "cannot suspend login shell (yet)."';;
*)	alias z='kill -STOP $$';;
esac

MACHINE=$(hostname)
if [ `id -u` = "0" ] ; then
	PS1="${MACHINE}# "
else
	PS1="${MACHINE%${MACHINE#???}}% "
fi
PS2="${MACHINE%${MACHINE#???}}\\        " 

export EDITOR='vi'
export PVM_ROOT=/local/pvm3

set -o vi
set -o complete

# this must be done after the path is set
typeset -x PAGER=`whence less`

# aliases
alias p=$PAGER
alias vt100='export TERM=vt100'
alias sw="fg %-"

### These are some old functions that might still be useful ###
#
# Some functions to implement the csh pushd/popd mechanism
typeset -i dirtop=${dirtop:--1}
function pushd {
	case $# in # (((
	0)	if [ dirtop -lt 0 ]; then
			print - "pushd: No other directory"; return 1
		fi
		typeset dir=${dirstack[dirtop]}
		#if [ -d $dir -a -x $dir ] && cd $dir; then
		if cd $dir; then
			dirstack[dirtop]=$OLDPWD
		else
			print - "pushd: Bad directory $dir"; return 1
		fi ;;
	1)	case $1 in	# ((
		+[0-9]*) typeset -i indoff=${1#+}-1
			if [ indoff -gt dirtop ]; then
				print - "pushd: Directory stack not that deep"
				return 1
			fi
			indoff=dirtop-indoff
			typeset dir=${dirstack[indoff]}
			#if [ -d $dir -a -x $dir ] && cd $dir; then
			if cd $dir; then
				while [ indoff -lt dirtop ]; do
					dirstack[indoff]=${dirstack[indoff+1]}
					indoff=indoff+1
				done
				dirstack[dirtop]=$OLDPWD
			else
				print - "pushd: Bad directory $dir"; return 1
			fi ;;
		*)	#if [ -d $1 -a -x $1 ] && cd $1; then
			if cd $1; then
				dirstack[dirtop=dirtop+1]=$OLDPWD
			else
				print - "pushd: Bad directory $1"; return 1
			fi ;;
		esac ;;
	*)	print - "pushd: Too many arguments"; return 1 ;;
	esac
	dirs
}


function popd {
	case $# in	# (((
	0)	if [ dirtop -lt 0 ]; then
			print - "popd: Directory stack empty"; return 1
		else
			typeset dir=${dirstack[dirtop]}
			#if [ -d $dir -a -x $dir ] && cd $dir; then
			if cd $dir; then
				dirtop=dirtop-1
			else
				print - "popd: Bad directory $dir"; return 1
			fi
		fi ;;
	1)	case $1 in	# ((
		+[1-9]*) typeset -i pos=${1#+}-1
			if [ pos -gt dirtop ]; then
				print - "popd: Directory stack not that deep"
				return 1
			else
				pos=dirtop-pos
				while [ pos -lt dirtop ]; do
					dirstack[pos]=${dirstack[pos+1]}
					pos=pos+1
				done
				unset dirstack[dirtop]
				dirtop=dirtop-1
			fi ;;
		*)	print - "popd: Bad argument"; return 1 ;;
		esac ;;
	*)	print - "popd: Too many arguments"; return 1 ;;
	esac
	dirs
}


function dirs {
	typeset -i ind=dirtop
	if [ "$1" = "-l" ]; then
		print -n $PWD
		while [ ind -ge 0 ]; do
			print -n " ${dirstack[ind]}"; ind=ind-1
		done
	else
		pentry "$PWD"
		while [ ind -ge 0 ]; do
			print -n " "; pentry "${dirstack[ind]}"; ind=ind-1
		done
	fi
	print -
}

function pentry {
	typeset x=${1#$HOME}
	if [ $HOME != "/" -a "$x" != $1 ]; then
		print -n "~$x"
	else
		print -n "$1"
	fi
}

#
# Set up command to print out include files
#
#idirs='. $in $in/sys $in/net $in/local $in/netinet'
#echo $idirs


function i {
	if [ $# -lt 1 ]; then echo "Usage: i [-n] file [file ...]"; return; fi
	typeset f flist="" notfound="" how=${PAGER:-/usr/ucb/more}
	if [ -z "$idirs" ] ; then
		idirs="`find /usr/include -type d`"
	fi
	eval typeset expidirs=\"$idirs\"
	integer found
	if [ $1 = "-n" ]; then how="print -"; shift 1; fi
	for i in $*; do
		f=${i%.h}.h; found=0
		for j in $expidirs; do
			if [ -r $j/$f ]; then flist="$flist $j/$f"; found=1; fi
		done
		if [ found -eq 0 ]; then notfound="$notfound, $f"; fi
	done
	if [ "$flist" ]; then $how $flist; fi
	if [ "$notfound" ]; then print - "cannot find: ${notfound#, }"; fi
}
#
# Now reference the .kshrc in the user's home directory if there
# is one.
#
if [ -r $HOME/.kshrc ]; then
    . $HOME/.kshrc
fi