#!/bin/bash
## This is the batchfile-variant of generating XMI from some headers using manually callings (not ANT).
## The advantages in respect to the ANT variant is: it is straight, you can see what is execute.
## The ANT-variant is indirect. You don't see what should happen in a simple way.

## set the position of file system where the other necessary download tools for XSL-translation are located:
export XML_TOOLS=/usr/share/XML_Tools


## set the environment variable to find batch-, zbnf- and xsl-scripts
export ZBNFJAX_HOME=$PWD/../../zbnfjax

## set the classpath to all necessary jars:
## The zbnf.jar is necessary for org.vishia.zbnf.Zbnf2Xml.
CLASSPATH=$ZBNFJAX_HOME/zbnf.jar

## The xslt.jar is necessary for org.vishia.xml.Xslt. Xslt is an enhanced XSLt-translator using saxon internally.
CLASSPATH=$CLASSPATH:$ZBNFJAX_HOME/Xslt.jar

## The saxon9.jar is downlaodable from http://www.saxonica.com or http://sourceforge.net/projects/saxon
CLASSPATH=$CLASSPATH:$XML_TOOLS/saxon9.jar:$XML_TOOLS/saxon9-jdom.jar

## The jdom is necessary because the input process use jdom, download it from http://www.jdom.org
export CLASSPATH=$CLASSPATH:$XML_TOOLS/jdom.jar

mkdir -p tmp

## All headers should be parsed with one java call per header like:
echo parsing Mystruct.h
java org.vishia.zbnf.Zbnf2Xml -i:Mystruct.h -s:$ZBNFJAX_HOME/zbnf/Cheader.zbnf -y:tmp/Mystruct.h.xml -a:@filename="Mystruct" --report:tmp/Mystruct.zbnf.rpt

## All parsed headers can transform via XSLT-2 using saxon in 2 steps.
echo building XMI
java org.vishia.xml.Xslt -itmp/Mystruct.h.xml -t$ZBNFJAX_HOME/xsl/CheaderTypes.xsl -w+ -ytmp/test.types.xml
java org.vishia.xml.Xslt -itmp/Mystruct.h.xml -itmp/test.types.xml -t$ZBNFJAX_HOME/xsl/gen/Cheader2Xmi.xsl -w+ -ytest.xmi
