#!/bin/sh
#
# $Id: viztool,v 1.2 2001/11/08 19:38:54 mdb Exp $
#
# Sets up the classpath and invokes viztool with arguments supplied to
# this script.

BINDIR=`dirname $0`
RUNJAVA=$BINDIR/runjava
VIZAPP=com.samskivert.viztool.Driver

usage ()
{
    echo "Usage: $0 [OPTIONS] package_prefix"
cat << EOH

options:
      [--exclude=pkg:pkg:...]
         Note that sub-packages must explicitly be enumerated in this
         list. Excluding foo.bar will not automatically exclude
         foo.bar.baz.
      [--print]
      [--cpath="jar_file|directory [jar_file|directory ...]"]
         A list of jar files and directories to include in the classpath
         (separated by spaces). This will be globbed for you, so you can
         pass in --cpath="lib/*.jar".
EOH
    exit -1
}

if [ $# = 0 ]; then
    usage
fi

while test $# -gt 0
do
    case "$1" in
    -h|-\?)
        usage
        ;;
    --print)
        OPTIONS="$OPTIONS -print"
        ;;
    --exclude=*)
        EXCL=`echo $1 | sed 's:--exclude=::g'`
        JOPTIONS="$JOPTIONS -Dexclude=$EXCL"
        ;;
    --cpath=*)
        ELEMS=`echo $1 | sed 's:--cpath=::g'`
        if [ -z "$CLASSPATH" ] ; then
            export CLASSPATH=`echo $ELEMS | sed 's/ /:/g'`
        else
            export CLASSPATH=$CLASSPATH:`echo $ELEMS | sed 's/ /:/g'`
        fi
        ;;
    -*)
        echo "Unknown option: $1"
        exit -1
        ;;
    *)
        PACKAGE=$1
        ;;
    esac
    shift
done

if [ -z "$PACKAGE" ]; then
    usage
fi

# invoke the program
$RUNJAVA -- $JOPTIONS $VIZAPP $OPTIONS $PACKAGE
