#!/bin/csh -f
# Global xsession file
# Accepts one optional argument "nocalls" (i.e., use no user files)
# $Author: jtkohl $
# $Source: /afs/athena.mit.edu/user/j/jtkohl/lib/scripts/RCS/xsession,v $
# $Header: /afs/athena.mit.edu/user/j/jtkohl/lib/scripts/RCS/xsession,v 1.7 90/10/18 13:34:51 jtkohl Exp $

# Note: This shell script deliberately uses the -f flag.

# the following fixes $home on symlinked directories
set foo=`(cd; pwd)`; set home=$foo; unset foo

set initdir=/usr/athena/lib/init

# Deterizations:  use no customization files
# ONLY if the single argument "nocalls" was provided to xsession (e.g., if
# the user selected the SYSTEM option from the initial xlogin menu).

switch ($#argv)
    case 0:
        breaksw
    case 1:
        if (($1 == nocalls) || ($1 == -nocalls)) then
            echo -n "xsession: Running standard Athena xsession "
            echo "with NO user configuration files..."
            setenv NOCALLS
	    $initdir/xsession nocalls
	    exit 0
        else
            set bad_args
        endif
        breaksw
    default:
        set bad_args
endsw

unset initdir

if ($?bad_args) then
        echo "xsession: Arguments ($argv) not recognized."
        echo "Running standard xsession with user configuration files..."
        unsetenv NOCALLS
        unset bad_args
endif

set xsession

# The ~/.cshrc file sets environment variables, attaches lockers, and sets
# the command search path.

echo "Setting up environment..."
source ~/.cshrc

if ($hosttype =~ i386_netbsd && -x /afs/sipb/project/tcsh/tcsh) then
	set shell=/afs/sipb/project/tcsh/tcsh
	setenv SHELL $shell
endif
# *******************   DEVICE SETUP   *******************


echo -n "/tmp/includes..."
source ~/lib/scripts/tmpincludes
echo -n "xmodmap..."
if (-x /lib/cpp) then
	set CPP=/lib/cpp
else if (-x /usr/lib/cpp) then
	set CPP=/usr/lib/cpp
else
	set CPP=cpp
endif
$CPP -P -D$hosttype=1 < ~/lib/X11/Xmodmap | xmodmap -
unset CPP

xrdb -merge ~/.Xresources

# Start window manager.  To change your default window manager, set the 
# WINDOW_MANAGER environment variable in your ~/.environment file.

if (! $?window_manager) setenv window_manager twm
if ($?verbose_login) echo "Starting $window_manager window manager..."
set wm__=$window_manager
unsetenv window_manager
($wm__ &)
unset wm__

# *******************   ACTIVITY STARTUP   *******************

# Run standard system/user startup activities

echo -n "zwgc..."
/usr/athena/bin/zwgc				# Start Zephyr client
	# If zephyr started okay, send message of the day as windowgram
	if ($status == 0) get_message -new -zephyr
(/usr/athena/olc who &) >& /dev/null		# Ping the OLC server

# Run the window-session customizing commands in your ~/.startup.X file.

if (-r ~/.logintime) then
	cat .logintime
endif
echo Last login at `date` on `hostname`. >${HOME}/.logintime
attach `cat ~/.attach_list`
set notify
source ~/lib/scripts/Xrc.xsession

echo "Session initialization completed."


# Gate the session.

# This command, NOT run in the background, "gates" your session.  When
# this process terminates, the session ends and you are logged out.
# To terminate this process, type the "logout" command in an xterm window
# or invoke the "end_session" program.

exec session_gate -logout			# Wait for logout

