#!/bin/sh
# Moritz Willers
# Thu Jan 26 12:18:28 GMT+0100 1995
# Version 0.3
#
echo ""
echo "Let's see whether you've got ispell"
ispell -vv > /dev/null
if [ $status ]; then
    echo "You must first install ispell before you can run this skript"
    exit 0
fi
echo "Ok"

echo ""
echo "Looking for your hash files"
LIBDIR=`ispell -vv | grep LIBDIR | awk '{print $3}' | sed 'y/"/ /'`
files=`ls ${LIBDIR}`
echo "There are:"
for file in $files
do
    if [ `expr ${file} : .*\.hash` -gt 0 ]; then
		echo "      $file"
    fi
done

echo ""
echo "Generating makefile ... "

cat > makefile << EOF
#
# Makefile for nextispell.
#
# Created by Moritz Willers.
#
# `date`
#
# Version 0.4
#

# -------- Languages to be made, derived from the hash files of ispell -------
#          delete entries, according to your needs

EOF
echo -n "DAEMONS = " >> makefile

for file in $files
do
    if [ `expr ${file} : .*\.hash` -gt 0 ]; then
		language=`expr ${file} : '\(.*\)\.hash'`
		echo -n "nextispell_${language}.daemon nextispell_${language}-tex.daemon " >>makefile
    fi
done
cat Makefile >> makefile

echo ""
echo "Now have a look at the head of the makefile and"
echo "decide which languages you want to have made"
echo "look out for DAEMONS"
echo ""
open makefile

echo -n "Meanwhile I'm creating another auxiliary file "
# generating a colon seperated list of the form:
# name.daemon:Language
cat /dev/null > tmp.table
for file in $files
do
	echo -n "."
    if [ `expr ${file} : .*\.hash` -gt 0 ]; then
		language=`expr ${file} : '\(.*\)\.hash'`
		language1=`echo $language | sed 's/\+/\\\\+/'`
		Name=`awk -F: '/^'${language1}':/{print $2}' language.table`
		langopt=`awk -F: '/^'${language1}':/{print $3}' language.table`
		if [ `expr length "$Name"` -eq 0 ]; then
			Name=$language
		fi
		echo nextispell_${language}.daemon:${Name}:${langopt} >> tmp.table
		echo nextispell_${language}-tex.daemon:${Name}-tex:'"-d'${language}' -Ttex"' >> tmp.table
    fi
done
echo ""
echo ""
echo ""
echo "If you have modified the makefile __correctly__ you can now type make"
echo ""
