#!/bin/sh
# dictionary update script for cmigemo
#
set -e

# check scripts
SKK2MIGEMO_PL=/usr/share/cmigemo/tools/skk2migemo.pl
[ -x $SKK2MIGEMO_PL ] || exit 1
OPTIMIZE_DICT_PL=/usr/share/cmigemo/tools/optimize-dict.pl
[ -x $OPTIMIZE_DICT_PL ] || exit 1

# check source file
if [ x"$1" = x"" ]; then
   SKKDIC_SRC=/usr/share/skk/SKK-JISYO.L
else
   [ -f $1 ] && SKKDIC_SRC=$1
fi
[ -z $SKKDIC_SRC ] && _exit 1

_make_cp932 () {
  echo -n "create cp932 dictionary ..."
  $SKK2MIGEMO_PL < $SKKDIC_SRC | $OPTIMIZE_DICT_PL | nkf -s \
    > /usr/share/cmigemo/cp932/migemo-dict
  echo "done"
}
_make_eucjp () {
  echo -n "create euc-jp dictionary ..."
  $SKK2MIGEMO_PL < $SKKDIC_SRC | $OPTIMIZE_DICT_PL | nkf -e \
    > /usr/share/cmigemo/euc-jp/migemo-dict
  echo "done"
}
_make_utf8 () {
  echo -n "create utf-8 dictionary ..."
  $SKK2MIGEMO_PL < $SKKDIC_SRC | $OPTIMIZE_DICT_PL | nkf -w \
    > /usr/share/cmigemo/utf-8/migemo-dict
  echo "done"
}

# create dictinaries...
_make_cp932
_make_eucjp
_make_utf8

exit 0
