#!/bin/sh

fatal()
{
	echo "$@" >&2
	exit 1
}

if [ "$1" = "--help" ] || [ "$1" = "-h" ] || [ -z "$1" ] ; then
	echo "Usage: $0 [--notest] file1 [file2...]"
	echo "toutf converts file from koi8-r to utf-8 if already not converted"
	echo "with --notest will perform really recoding"
	exit 0
fi

COMMAND="enca -V"
COMMENT="Testing"
if [ "$1" = "--notest" ] ; then
	COMMAND="enconv -d -x UTF-8 -V"
	COMMENT="Converting"
	shift
fi

while [ -n "$1" ] ; do
	# Skip dirs
	test -d "$1" && shift && continue
	echo -n "$COMMENT $1..."
	$COMMAND "$1"
	shift
done
