#!/bin/sh



# Joseph Rosevear 210402 I wrote this script.



# Functions

bound() {

   # Define level.
   level=`echo $1 | cut -d: -f1`
   
   # Define sam_add.
   new_sam_add=`echo $1 | cut -d: -f2-`
   
   if [ "$sam_add" = "" ]; then
   
      sam_add=$new_sam_add
      
   else
   
      sam_add=$sam_add:$new_sam_add
   fi
   
   # Define PATH
   PATH=$pold:$place:$level:$sam_add
   
   # Increment sam_env_num
   sam_env_num+=1
   
   # Variable PS1 needs to be exported, even though it is already
   # exported.  I don't know why.  I think it is special.
   
   
   # Use sh to keep shell open if $sam_batch is not "batch".
   if [ "$2" != "batch" ]; then

      sh
   fi 

   return
}

# Declarations.
declare -i sam_env_num

# Exports.
export sam_temp_dir
export sam
export sam_symbol
export pold
export olevel
export sam_env_num
export level
export sam_add

# Define place and use it to source bprofile.
place=`dirname $0`

. $place/bprofile

# Make dir /tmp/sam.
mkdir /tmp/sam

# Make some initializations.
sam_temp_dir=/tmp/sam
sam=$place
sam_symbol=":)"

# Make some initializations if pold doesn't exist.
if [ "$pold" = "" ]; then

   pold=$PATH
   olevel=$SHLVL
   level=""
   sam_add=""
   sam_env_num=0
fi

while [ "$#" -gt 0 ]; do

#  if [ "$2" = "" ]; then
   
#     last_field=true
      
#  else
   
#     unset last_field
#  fi

   $1
   shift
done

# Say Thank You if all done.
if [ "$SHLVL" = "$olevel" ]; then

   echo "*** Thank you for using SAM Lite ;) ***"
fi

exit
