#!/bin/bash
#@DOC@ run fmtb_parse & wg to see comparison graphically
#
# Copyright (C) 2006  Nathan (Acorn) Pooley
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License (gpl.txt) for more details. 
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
# 
# You can contact the author, Nathan (Acorn) Pooley, by writing
# to Nathan (Acorn) Pooley, 949 Buckeye Drive, Sunnyvale, CA  94086, USA
# or through the form at http://www.rawbw.com/~acorn/wand/feedback.html
# 

_usage() {
	if [[ -n $1 ]] ; then
		echo "$*"
	fi	
	echo "Usage try3cmp <file> <spell> [opts]"
	echo "   Run fmtb_parse on <file> with <spell> and then run wg."
	exit 1
}

file=""
spell=""
OPT_args=""

for i in "$@"
do
	if [[ x${i%\?}y = x-y ]] ; then
		_usage
	fi
	case "$i" in
		-*)	OPT_args="$OPT_args$i "	;;
		*)	if [[ -z $file ]] ; then
				file="$i"
			elif [[ -z $spell ]] ; then
				spell="$i"
			else
				_usage "Extra arg: '$i'"
			fi
			;;
	esac
done
#echo "OPT_args='$OPT_args'"

if [[ -n $file && -n $spell ]] ; then
	if [[ -f $spell && ! -f $file ]] ; then
		i="$file"
		file="$spell"
		spell="$i"
	fi
fi

if [[ -z $file ]] ; then
	_usage "Please provide filename"
fi
if [[ ! -f $file ]] ; then
	_usage "filename '$file' not found"
fi
###if [[ -z $spell ]] ; then
###	_usage "Please provide spell"
###fi
if [[ -z $OPT_args ]] ; then
	OPT_args=-m
fi

echo "Running: fmtb_parse -s $OPT_args $spell -r$file.wgtok < $file"
fmtb_parse -s $OPT_args $spell -r$file.wgtok < $file
echo "Created $file.wgtok"
echo "Now running: ./wg -b $file $file.wgtok &"
./wg -b $file $file.wgtok &
