#! /bin/bash

. /etc/utt/compdic.conf


while [ $# -gt 2 ]
do
  case $1
  in
    -d)
      dictionary_home=$2
      shift 2
    ;;

    *)
      echo "The arguments to use are"
      echo "-d <dictionary-home-dir>"
      shift 1
    ;;
  esac
done


if [ $# -lt 2 ]
then
    echo "Usage:"
    echo "        compdic-update [-d <dictionary-home-dir>] <dictionary-name> <difference> <difference> ..."
    echo "where"
    echo "    <dictionary-home-dir> - dictionary home directory"
    echo "    <dictionary-name>     - dictionary name"
    echo "    <difference>          - diff format file containing paths to be added/removed from dictionary"
    exit 0
fi	

fst=$dictionary_home/$1.fst
cats=$dictionary_home/$1.cats
bin=$dictionary_home/$1.bin
shift 1
diffs=$*

echo running "compdic-update-fst $fst $diffs"
compdic-update-fst $fst $diffs

echo running "compdic-fst-to-bin $fst $bin"
compdic-fst-to-bin $fst $bin

echo running "compdic-update-cats $cats $diffs"
compdic-update-cats $cats $diffs
