#! /bin/sh

#================================================================
# u8toej
# Conveter from UTF-8 to EUC-JP
#================================================================


# set variables
LANG=C ; export LANG
LC_ALL=C ; export LC_ALL
tmpfile="/tmp/u8toej.$$"


# check arguments
if [ $# -lt 1 ]
then
  printf 'u8toej: usage: ejto8 file...\n' 1>&2
  exit 1
fi


# function to remove the temporary directory
tmpclean(){
  rm -rf "$tmpdir"
}


# set the exit trap
trap tmpclean 1 2 3 13 15


# convert the file
while [ -n "$1" ]
do
  iconv -f UTF-8 -t EUC-JP -c "$1" > "$tmpfile"
  if [ -n "$tmpfile" ]
  then
    mv -f "$tmpfile" "$1"
  fi
  shift
done


# exit normally
exit 0



# END OF FILE
