#!/bin/bash
# 
# Copyright (C) 2001-2005 Michael Fuchs
#

prog=`type -p -- $0`

if [ $? -ne 0 ] ; then
    echo "Can't find installation directory!"
    exit 1
fi

prog=`readlink -f $prog`
bindir=`dirname "$prog"`

dbdhome=`cd "$bindir/.." && pwd`

javadoc=`type -p -- javadoc`
java=`type -p -- java`

# set -x

function fatal {
    echo "[Error] $1"
    exit 1
}

function usage {

    msg=$1
    cat <<EOF
dbdoclet
Copyright (C) 2001-2009 Michael Fuchs

The DocBook Doclet (dbdoclet) creates DocBook code from Java source
documentation. It is helpful, if you want to print reference handbooks of
your API. The program is used in conjunction with the javadoc tool.

The dbdoclet script is just a simple wrapper for the javadoc tool and the 
dbdoclet doclet. The following command line is used:

  $javadoc \\
      -J-Xms64m -J-Xmx256m \\
      -classpath $dbdhome/jars/dbdoclet.jar \\
      -doclet org.dbdoclet.doclet.docbook.DocBookDoclet \\
      -docletpath $dbdhome/jars/dbdoclet.jar \$*

To view the options of the javadoc command use javadoc -help.

Syntax: dbdoclet <JAVADOC OPTIONS> <OPTIONS> <PACKAGES>
  
  -p <PROPERTIES FILE>    - Properties file for dbdoclet.

EOF

    [ "$msg" != "" ] && fatal "$msg"
    
    exit 0
}

[ ! -d $dbdhome ] && fatal "Can't find directory $dbhome!"
[ "x${javadoc}" = "x" ] && fatal "Can't find program javadoc!"

locale=""
cmdline=""

counter=0

while [ $# -gt 0 ]
do
  case $1 in

      -locale)  
          locale="-locale $2"
          shift
	  ;;
      
      *) 
          ARGS[$counter]=$1
          counter=$(($counter+1))
	  ;;
  esac
  shift
done

$javadoc \
    $locale \
    -J-Xms256m -J-Xmx1024m \
    -classpath $dbdhome/jars \
    -doclet org.dbdoclet.doclet.docbook.DocBookDoclet \
    -docletpath $dbdhome/jars/dbdoclet.jar "${ARGS[@]}"

exit $?
