#!/bin/bash

XSLT_DIR=@xgridfit_dir@/utils/

usage() {
    echo
    echo "usage: ttx2xgf infile[.ttx] [outfile]"
    echo
}

if [ $# -lt 1 ]
    then
    usage
    exit 1
fi

FNAME=$1

if ! echo $FNAME | grep -q "\.ttx$"
then
        FNAME=${FNAME}.ttx
fi

if [ ! -f "$FNAME" ]; then
        echo "File $FNAME not found" 1>&2
        exit 1
fi

OUTNAME=$2

if [ -z "$OUTNAME" ]; then
        OUTNAME=`basename $FNAME .ttx`.xgf
fi

xsltproc ${XSLT_DIR}convert-ttx.xsl $FNAME | \
sed -f ${XSLT_DIR}convert-asm.sed \
> $OUTNAME
