#!/bin/sh
##
##  This file is part of pyFormex 1.0.7  (Mon Jun 17 12:20:39 CEST 2019)
##  pyFormex is a tool for generating, manipulating and transforming 3D
##  geometrical models by sequences of mathematical operations.
##  Home page: http://pyformex.org
##  Project page:  http://savannah.nongnu.org/projects/pyformex/
##  Copyright 2004-2019 (C) Benedict Verhegghe (benedict.verhegghe@ugent.be)
##  Distributed under the GNU General Public License version 3 or later.
##
##  This program is free software: you can redistribute it and/or modify
##  it under the terms of the GNU General Public License as published by
##  the Free Software Foundation, either version 3 of the License, or
##  (at your option) any later version.
##
##  This program is distributed in the hope that it will be useful,
##  but WITHOUT ANY WARRANTY; without even the implied warranty of
##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
##  GNU General Public License for more details.
##
##  You should have received a copy of the GNU General Public License
##  along with this program.  If not, see http://www.gnu.org/licenses/.
##

#
# pyFormex startup script
#
# This scripts allows (and strips) the options:   [ -D ]   [ -2 | -3 ]
# -D: switch on debugging info for this script
# -2 | -3: force Python2 or Python3 command interpreter
# All remaining command line argument are passed to pyFormex.
#

if [ "$1" = "-D" ]; then
    ECHO="echo"
    shift
else
    ECHO=":"  # do nothing
fi

script=$(readlink -f $0)
scriptdir=$(dirname $script)
$ECHO "pyFormex start script: $script"

if [ "$1" = "-2" ]; then
    PYVER=2
    shift
elif [ "$1" = "-3" ]; then
    PYVER=3
    shift
else
    PYVER=${PYFORMEX_PYTHON}
fi

python="python$PYVER"
$ECHO "Python interpreter: $python"

if [ -f "$scriptdir/startup.py" ]; then
    # If we are executing the pyformex script from a pyFormex source tree,
    # make sure we always use the pyformex from that tree.
    #MYPYTHONPATH="$(dirname $scriptdir)"
    #[ -n "$PYTHONPATH" ] && MYPYTHONPATH="$MYPYTHONPATH:$PYTHONPATH"
    #$ECHO "MYPYTHONPATH=$MYPYTHONPATH"
    set exec $python $scriptdir/startup.py "$script" "$@"
else
    # We are executing the script from an installed bin directory
    set exec $python -s -m pyformex.startup "$script" "$@"
fi
if [ "$ECHO" = "echo" ]; then
    printf 'Executing command:\n'
    printf '"%b" ' "$@"
    printf '\n'
fi
"$@"

# End
