#!/bin/sh
# 	Usage: envjs <platorm> file.js [file2.js ...]
###########################################################################
ENVJS_PLATFORM='node'

# 	first arguments ($1) 
#		may be a platform or is a file and the default platorm is used
if [ -n "$1" ]; then 
    if [ -n "$1" ]; then ENVJS_PLATFORM="$1"; shift; fi
fi

#   Run envjs with the given platform
###########################################################################
case "$ENVJS_PLATFORM" in

    "node")
        node envjs/node.js $@
        ;;
    "rhino")
        java -Xmx512M -jar rhino/js.jar -opt -1 envjs/rhino.js $@
        ;;
    "rhino-debug")
        java -cp rhino/js.jar org.mozilla.javascript.tools.debugger.Main envjs/rhino.js $@
        ;;
    "spyd")
        python envjs/spydermonkey.py envjs/spydermonkey.js $@
        ;;
    "rubyracer")
        ruby -rrubygems envjs/rubyracer.rb envjs/rubyracer.js $@
        ;;
    "johnson")
        ruby -rrubygems envjs/johnson.rb envjs/johnson.js $@
        ;;
	*)
		#	platform default means $1 was actually a file
        node envjs/node.js $ENVJS_PLATFORM $@
        ;;
esac

