#!/bin/sh
# $XConsortium: Xsession,v 1.7 92/08/06 11:08:14 gildea Exp $

# environment variables that this shell script sets/changes:
export DISPLAY HELPPATH LD_LIBRARY_PATH
export MANPATH NOSUNVIEW OPENWINHOME PATH XFILESEARCHPATH

# look in /usr/openwin if OPENWINHOME is not set.
OPENWINHOME="/usr/openwin"

# initial arglist is null
PASSTHRU=

NOAUTH=0
SERVERHELP=0
INCLUDEDEMOPATH=0
NOSUNVIEW=0

# Add to the path variable named by $1 the component $2.  $3 must be
# "append" or "prepend" to indicate where the component is added.
addpath () {
    eval value=\"\$$1\"
    case "$value" in
	*:$2:*|*:$2|$2:*|$2)
	    result="$value"
	    ;;
	"")
	    result="$2"
	    ;;
	*)
	    case "$3" in
		p*)
		    result="$2:${value}"
		    ;;
		*)
		    result="${value}:$2"
		    ;;
	    esac
    esac
    eval $1=$result
    unset result value
}

# convenience routine which appends a string to a path.
append () {
    addpath "$1" "$2" append
}

# convenience routine which prepends a string to a path.
prepend () {
    addpath "$1" "$2" prepend
}

# add $OPENWIN/mumble to several related environment variables.
[ $INCLUDEDEMOPATH -eq 1 ] && prepend PATH $OPENWINHOME/demo

append	HELPPATH	$OPENWINHOME/lib/locale
append	HELPPATH	$OPENWINHOME/lib/help
prepend XFILESEARCHPATH	$OPENWINHOME/lib/locale/%L/%T/%N%S
append	XFILESEARCHPATH	$OPENWINHOME/lib/%T/%N%S
prepend PATH		$OPENWINHOME/bin

if [ -d $OPENWINHOME/share/man ]; then
    case "$MANPATH" in
    "") MANPATH="$OPENWINHOME/share/man:/usr/man" ;;
    *)  prepend MANPATH $OPENWINHOME/share/man ;;
    esac
fi

# Add locale-specific support
#
if [ -f $OPENWINHOME/bin/set_locale_env ]; then
    . $OPENWINHOME/bin/set_locale_env
fi

case $# in
1)
	case $1 in
	failsafe)
		exec xterm -geometry 80x24-0-0
		;;
	esac
esac

startup=$HOME/.xinitrc
resources=$HOME/.Xresources

if [ -f $startup ]; then
	exec /bin/sh $startup
else
	if [ -f $resources ]; then
		xrdb -load $resources
	fi
	olwm &
	exec xterm -geometry 80x24+10+10 -ls
fi
