#!/bin/sh

# enter - set up project-specific environment

# @(#) enter.sh 1.5 11/4/89 15:56:03

# initialize

IFS=" 	
"

: ${HOME?} ${SHELL=/bin/sh} make sure these are set

# sanity checks...

test $# = 1 || { 
    echo "Usage: ${0} project" 1>&2; exit 1
}

test -r ${HOME}/.${1} || { 
    echo "${0}: can't read environment file: '${HOME}/.${1}'" 1>&2; exit 1
}

test -x ${SHELL} || { 
    echo "${0}: can't execute command shell: '${SHELL}'" 1>&2; exit 1
}

# set up default Bourne-shell prompt

export PS1; PS1="$1%${PS1- }"

# load environment 

. ${HOME}/.${1}

# define UPPER and lower-case environment variables with the project name

_PNAME_=`echo ${1} | case \`echo -n\` in		# assume $1 lower case
			"") tr a-z A-Z;;		# this is for V7, BSD
			 *) tr '[a-z]' '[A-Z]';;	# and this is for SYSV
		     esac`
eval ${1}=\${${_PNAME_}=\${${1}}}

eval test "X\${${1}}" != X || { 
    echo "${0}: ${HOME}/.${1} should set '${1}' or '${_PNAME_}'" 1>&2; exit 1
}

export ${1} MANPATH PATH ${_PNAME_}

# become a new shell

echo "Entering project '${1}' - leave with 'exit' or 'control-d'" 1>&2

exec ${SHELL} 

echo "project ${1} NOT entered" 1>&2; exit 1;

#++
# NAME
#	enter 1
# SUMMARY
#	set up a project-specific environment
# PROJECT
#	sdetools
# SYNOPSIS
#	enter project
#	exit
# DESCRIPTION
#	The \fIenter\fR command sets up an environment that makes
#	it easy to access \fIproject\fR-specific programs and files.
#
#	\fIenter\fP consults a file with environment information
#	($HOME/.\fIproject\fR, Bourne-shell syntax) and invokes 
#	a new command shell of the same type as the login shell.
#	Typically, project environment files are maintained and 
#	given out by the project administrator.
#
#	In order to leave the project environment use the \fIexit\fP 
#	command or type a control-d;
#	the details may depend on the type of login shell involved.
#
#	As a minimum, the environment file should set an environment
#	variable with the same name as the \fIproject\fP. The variable 
#	name can be either be identical to \fIproject\fP or in upper case.
#	For consistency, \fIenter\fP will set both variables to the same value.
# EXAMPLE
# .fi
# .ad
#	In this example, 
#	all files pertaining to a project \fIfoobar\fR are located under the
#	directory \fI/usr/foo/bar/foobar\fR. For example, there
#	are subdirectories
#	\fI/usr/foo/bar/foobar/man\fR with manual pages, 
#	\fI/usr/foo/bar/foobar/bin\fR with executable 
#	programs, other directories for object libraries and include files, 
#	and so on.
#
#	In order to enter a project \fIfoobar\fR, the command
# .PP
# .ti +5
# .ft C
#	enter foobar
# .ft 
# .PP
#	consults a file \fI.foobar\fR (in the user\'s home directory) 
#	with contents:
# .PP
# .ft C
# .nf
# .in +5
#	export FOOBAR;	FOOBAR=/usr/foo/bar/foobar
#	export PATH;	PATH=$PATH:$FOOBAR/bin
#	export MANPATH;	MANPATH=$MANPATH:$FOOBAR/man
# .ft 
# .fi
# .PP
#	The second line automatically makes all project-specific 
#	executable programs accessible. The third line makes it possible 
#	to use the standard UNIX \fIman\fR command for retrieval of 
#	project-specific manual pages. The \fIenter\fR command
#	makes sure that both the \fIfoobar\fR and \fIFOOBAR\fR
#	environment variables are set to the same value.
# COMMANDS
#	sh(1), echo(1), test(1), tr(1), login shell
# FILES
#	$HOME/.\fIproject\fR
# ENVIRONMENT VARIABLES
#	SHELL, login shell
#	HOME, login directory
#	PATH, search path for commands
#	MANPATH, search path for the \fIman\fR command.
# BUGS
#	Name clashes may occur if people have entered several projects
#	at the same time. This can be avoided by using unique project names,
#	which is a good idea anyway.
# AUTHOR(S)
#	W.Z. Venema
#	Eindhoven University of Technology
#	Department of Mathematics and Computer Science
#	Den Dolech 2, P.O. Box 513, 5600 MB Eindhoven, The Netherlands
# CREATION DATE
#	Tue Apr 19 15:35:41 MET DST 1988
# STATUS
#	enter.sh 1.5 11/4/89 15:56:03 (draft)
#--
