#!/bin/sh
# modified by Nikolaus Schaller <hns@computer.org>, 2003

if [ -z "$1" ]; then
        echo usage: `basename $0` application[.app] [arguments...]
        exit 1
fi

app="$1";

# Remove leading slashes at the end of the application name (which may not contain %) and potential .app
# app=`echo $app | sed 's%/*$%%' | sed 's%.*\.app$%%'`

appname=`basename "$app" .app`    # remove .app if it exists
full_appname=`dirname "$app"`

if [ -f "$full_appname/$appname.app" ]; then
        for path in /home/myPDA/System/Applications /home/myPDA/Library/Applications /home/myPDA/Users/theuser/Applications
                do
                if [ -f "$path/$appname.app" ]
                        then
                        full_appname="$path"
                        break
                fi
        done
fi
if [ -f "$full_appname/$appname.app" ]; then    # still not found
        echo "Can't find the required application: $app!"
        exit 1
fi

# appname=`echo $app | sed 's/\.[a-z]*$//'`     # remove final suffix (e.g. .app)

# determine architecture subdirectory

case `uname -s`-`uname -p`-`uname -m` in
        Darwin-powerpc-Power\ Macintosh )       executable=Contents/MacOS;;
        Linux-*-arm* )                          executable=Contents/Linux-ARM
                                                export LD_LIBRARY_PATH="/home/QtPalmtop/lib:/home/myPDA/lib:$LD_LIBRARY_PATH";;       # just to be sure
        Linux-*-i386 )                          executable=Contents/i386;;
        *)                                      executable=Contents/Unknown;;
esac

app_path="$full_appname/$appname.app/$executable/$appname"

echo "Xapp path:" "$app_path"

shift   # remove $1

gdb --core=core --args "$app_path" "$*"        # and replace shell by application with all arguments