#! /bin/sh

# Linux case
if [ -z "$PANDA_ROOT" ]; then
  # Convert semicolons back to colons
  PYTHONPATH=`echo $PYTHONPATH | sed 'y/;/:/'`
  export PYTHONPATH
  # Run unbuffered output, with any options passed in
  exec python -u $*
  exit 1
fi

# Under Windows/Cygwin, we have to do this whole thing a little differently.
# We have to de-cygwinify the semicolon separated PYTHONPATH
# The new path
NEWPYTHONPATH=
# Temporarily change the semicolons into spaces
for path in `echo $PYTHONPATH | sed 'y/;/ /'`; do
    # For each entry run it through the cygwin filter
    NEWPYTHONPATH=$NEWPYTHONPATH\;`cygpath -w $path`
done
# Set the new PYTHONPATH
PYTHONPATH=$NEWPYTHONPATH
export PYTHONPATH


# Lets also de-cygwinify the Project variables (so you can use file name 
# completion)  This is hardcoded for the most popular trees
if [ "$DTOOL" ]; then
    DTOOL=`cygpath -w $DTOOL`
    export DTOOL
fi
if [ "$PANDA" ]; then
    PANDA=`cygpath -w $PANDA`
    export PANDA
fi
if [ "$DIRECT" ]; then
    DIRECT=`cygpath -w $DIRECT`
    export DIRECT
fi
if [ "$TOONTOWN" ]; then
    TOONTOWN=`cygpath -w $TOONTOWN`
    export TOONTOWN
fi

# Export the proper home environment variable
HOME=`cygpath -w $HOME`
export HOME


# We can't run with -u under windows for some reason.  But we do need to
# make a distinction between python_d and python.  We'll accept the user
# parameter -d to indicate we should run python_d.

if [ x"$1" = x"-d" ]; then
  shift 1
  exec python_d ${1+"$@"}
else
  exec python ${1+"$@"}
fi

