#!/bin/sh

# get the fully-resolved path to this script, after following symlinks
script=$0
while [ -h "$script" ]; do
  script=`ls -l $script | sed 's/.*-> *//'`;
done

# get the directory containing the script
mydir="`dirname $script`"

# set JAVA_HOME specially for OS X
if [ `uname` == 'Darwin' ]; then
  JAVA_HOME=/usr/local/soylatte;
fi

# count the number of arguments to the first argument that
# does not start with a - (dash)
# those arguments should be passed to the JVM
jvmargcount=0
for arg in "$@"
do
  if [[ $arg == -* ]]; then
      let "jvmargcount+=1"
  else
      break
  fi
done

# accumulate the arguments for the JVM in jvmargs
# shift, so that only the remaining arguments are in "$@"
i=0
jvmargs=`while [ "$i" -lt "$jvmargcount" ]
do
  echo -n "$1 "
  shift
  let "i+=1"
done`
i=0
while [ "$i" -lt "$jvmargcount" ]
do
  shift
  let "i+=1"
done

$JAVA_HOME/bin/java -agentlib:yjpagent -Xbootclasspath/p:$mydir/../dist/lib/classes.jar $jvmargs edu.rice.cs.mint.runtime.Mint "$@"
