#!/bin/sh
# -----------------------------------------------------------------------
# Main script for firing up SME client
# Usage: startup_client [options]
#
# options:
#
#	-d 	debug
#	-p	port
#	
# -----------------------------------------------------------------------

# This is written by configure: do not modify
MODEL=null
SCENARIO=null
MORE_ARGS="yes"
DEBUG="0"
JAVA_RUN_ARGS=""
PORT="17736"
HOST="localhost"
SHELL=""
USE_SNI=""

if [ $# -gt 0 ] ; then

  if [ $1 = -help ] ; then
	echo "Usage: startup_client [options]"
	echo "  options:"
	echo 
	echo "    -help              print usage help"
	echo "    -p <port>          Set port   "
	echo "    -h <host>          Set host   "
	echo "    -d <debugMode>  debug mode: ( 1:run debugger, 2:attach debugger manually )"
	echo "    -java <args>    additional args to java command"
	echo	
	exit 0
  fi

  while [ $MORE_ARGS = "yes" ] ; do
    MORE_ARGS="no"

    if [ $1 = "-d" ] ; then
      MORE_ARGS="yes"
      shift
      DEBUG="$1"
      shift
      echo "In debug mode:"
    fi

    if [ $1 = "-p" ] ; then
      MORE_ARGS="yes"
      shift
      PORT="$1"
      shift
      echo "Using port: $PORT"
    fi

    if [ $1 = "-h" ] ; then
      MORE_ARGS="yes"
      shift
      HOST="$1"
      shift
      echo "Using host: $HOST"
    fi

    if [ $1 = "-sni" ] ; then
      MORE_ARGS="yes"
      shift
      HOST="$1"
      USE_SNI="-sni"
      PORT="10000"
      shift
      echo "Using SNI host: $HOST (port 10000)"
    fi

    if [ $1 = "-python" ] ; then
      MORE_ARGS="yes"
      shift
      SHELL="-python"
    fi


    if [ $1 = "-java" ] ; then
      MORE_ARGS="yes"
      shift
      JAVA_RUN_ARGS="$JAVA_RUN_ARGS $1"
      shift
    fi

    if [ $1 = "-m" ] ; then
      MORE_ARGS="yes"
      shift
      MODEL="$1"
      shift
      echo "Using Model: $Model"
    fi

    if [ $1 = "-scen" ] ; then
      MORE_ARGS="yes"
      shift
      SCENARIO="$1"
      shift
      echo "Using Scenario: $SCENARIO"
    fi

    if [ $1 = "-v" ] ; then
      MORE_ARGS="yes"
      shift
      JAVA_RUN_ARGS="$JAVA_RUN_ARGS -verbose"
    fi

  done

fi		

APP_ARGS="$SHELL -p $PORT -h $HOST -m $MODEL -scen $SCENARIO $USE_SNI"
export APP_ARGS
export JAVA_RUN_ARGS

sme_execute_class miiee.client.SMEClient $DEBUG

exit 0		
