#!/bin/sh
# makeIWL: make a raw word list from the data files from the ispell program
# usage:   ./makeIWL DataFile AffixFile > WordListFile
# note:    in order to use this program you should have both the ispell 
#          program as the program buildhash available on your system
# 980304 erik.tjong@ling.uu.se

# we need exactly two arguments
if [ "$#" != "2" ]
then
   # we do not have two arguments
   echo "usage: makeIWL DataFile AffixFile > WordListFile" >&2
   exit 1
fi

# give the arguments a name
DATAFILE="$1"
AFFIXFILE="$2"

# test if they exist
if [ ! -f "$DATAFILE" ]
then
   echo "cannot open file $DATAFILE" >&2
   exit 1
fi
if [ ! -f "$AFFIXFILE" ]
then
   echo "cannot open file $AFFIXFILE" >&2
   exit 1
fi

# temporary file name
TMPFILE="makeIWL.$$.hash"

# we will extract the word list from a ispell hash dictionary
# so create this dictionary
buildhash -s $DATAFILE $AFFIXFILE $TMPFILE

# test if buildhash was successful
if [ ! -f "$TMPFILE" ]
then
   # failed to create hash file; buildhash will have complained
   # we just clean up: remove temporary file
   /bin/rm -f $TMPFILE 2>/dev/null
   # stop
   exit 1
else
   # hash file created successfully
   # show the word list
   ispell -d ./$TMPFILE -e < $DATAFILE |\
      tr -s ' \n' '\n\n'
fi
# get rid of the temporary file
/bin/rm -f $TMPFILE 2>/dev/null
# done
exit 1
