#! /bin/sh
# This searches a search database.  Argument is the database directory

# Cygwin support.  $cygwin _must_ be set to either true or false.
case "`uname`" in
  CYGWIN*) cygwin=true ;;
  *) cygwin=false ;;
esac

# For Cygwin, ensure paths are in UNIX format before anything is touched
if $cygwin; then
  [ -n "$JAVAHELP_HOME" ] &&
    JAVAHELP_HOME=`cygpath --unix "$JAVAHELP_HOME"`
fi

if [ "$JAVAHELP_HOME" = "" ] ; then
  # try to find jhindexer
  if [ -d /opt/javahelp ] ; then 
    JAVAHELP_HOME=/opt/javahelp
  fi

  if [ -d ${HOME}/opt/jhindexer ] ; then 
    JAVAHELP_HOME=${HOME}/opt/javahelp
  fi

  ## resolve links - $0 may be a link to javahelp's home
  PRG=$0
  progname=`basename $0`
  
  while [ -h "$PRG" ] ; do
    ls=`ls -ld "$PRG"`
    link=`expr "$ls" : '.*-> \(.*\)$'`
    if expr "$link" : '.*/.*' > /dev/null; then
	PRG="$link"
    else
	PRG="`dirname $PRG`/$link"
    fi
  done
  
  JAVAHELP_HOME=`dirname "$PRG"`/../..

fi

# For Cygwin, switch paths to Windows format before running java
if $cygwin; then
  JAVAHELP_HOME=`cygpath --path --windows "$JAVAHELP_HOME"`
fi

java -jar $JAVAHELP_HOME/javahelp/bin/jhsearch.jar "$@"
