#!/bin/sh
#
# Author: Marco Ladermann
# Date: Sat May 10 13:59:35 CEST 2003 @541 /Internet Time/
# Purpose: Starts the transformation process of a UI file to Java
# Changed:
#
# This software is free software. It is released under the terms of the
# GNU Lesser General Public Licence (LGPL)
# see http://www.gnu.org/copyleft/lesser.html
#
# These stylesheets are distributed in the hope that they will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#

usage() {
    juic=$(basename $0)
    cat <<EOT
Usage: $juic [options] uifile...
Where options can be:
    -outdir     "dir"                       : output directory, defaults to current directory
    -package    "the.package.for.the.class" : Generates a package declaration
    -main       (true | false)              : Generate a main method, defaults to "false"
    -abstract   (true | false)              : Slots are declared abstract, defaults to "true"
    -images     dir                         : Path to images, defaults to "images"
    -os         (unix | msdos | mac)        : Selects newline characters
EOT
    exit 1
}

# Assume the directory structure
# ${UIXSL}/
#          bin/
#          xsl/
#              common/
#              java

UIXSLDIR=/usr/share/juic
UIXSL=${UIXSLDIR}/juic.xsl

ABSTRACT="true"
MAIN="false"
OUTDIR="."
IMAGES="images"
OS="unix"
PACKAGE=""

while [ -n "$1" ]
do
    case "$1" in
        -abstract) ABSTRACT=$2; shift; shift;;
        -main) MAIN=$2; shift; shift;;
        -outdir) OUTDIR=$2; shift; shift;;
        -images) IMAGES=$2; shift; shift;;
        -os) OS=$2; shift; shift;;
        -package) PACKAGE=$2; shift; shift;;
        -*) echo Unknown parameter $1; shift;;
        *) break;;
    esac
done

if [ -z "$1" ]
then
    usage
fi
if [ $ABSTRACT = 'true' -a $MAIN = 'true' ]
then
    echo "Option \"-main\" will be ignored, because class will be abstract"
    MAIN="false"
fi    

while [ -n "$1" ]
do
    xsltproc --nonet --novalid \
        --stringparam package "$PACKAGE" \
        --stringparam outdir "$OUTDIR/" \
        --stringparam images "$IMAGES/" \
        --stringparam os $OS \
        --stringparam genabstract $ABSTRACT \
        --stringparam genmain $MAIN \
        $UIXSL "$1"
    shift
done

