#!/bin/bash
#@DOC@ run fmtb_parse on some number of files with same options
#
# 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() {
	echo "rrr [OPTIONS] <file> <file> ..."
	echo "  run fmtb_parse with [OPTIONS] on each <file>."
	exit 0
}

opts=""
flist[0]=""
unset flist
fcnt=0

for i in "$@"
do
	if [[ x${i%\?}y = x-y ]] ; then
		_usage
	fi
	case "$i" in
		-*)		opts="$opts$i "	;;
		*)		if [[ -f $i ]] ; then
					flist[$fcnt]="$i"
					(( fcnt = fcnt + 1 ))
				else 
					opts="$opts$i "
				fi
				;;
	esac
done

if (( fcnt > 0 )) ; then
	for i in "${flist[@]}"
	do

		#echo "fmtb_parse $opts $i"
		fmtb_parse $opts $i
	done
else
	while read line
	do
		fmtb_parse $opts $line
	done
fi
