KPATH=/bbs/lib/key.d; export KPATH
case $# in
0)
     echo "Usage : $0 sourcefile"
     exit;;
esac
if test -f "$1"
then
   FILE=$1; export FILE
else
   echo "No file: $1"
   exit
fi
grep $1 KEY > /dev/null
case $? in
0) echo "$1 has already been processed"
   exit;;
esac
echo "Processing $1, building key.raw
Finding hyphanated words..."
hyphen $1 | tolower > hyph
sed '
/'$1'/d
/^$/d
s/-//' hyph > hy.inc
sed '
/'$1'/d
/^$/d
:a
/[\/-]/{
s//\
/
b a
}
s/-$//' hyph > hy.ign
sort -u hy.inc -o hy.inc
sort -u hy.ign -o hy.ign
tr ' ' '\012' < $1  hy.inc | tolower | sort -u > key.raw1
cat hy.ign key.raw1 | sort | uniq -u |
sed -n '
/[	 :;,._'\'')("!*?]\[{}+=\\#@$%&*<>^]/s///g
/['\''\`][dst]$/s/['\''\`]//
s/ness$//
/[^e][cdfrtslnp]ies$/s/ies$/y/
/[\/-]/s//\
/g
/^$/d
/^[0-9]*$/d
/^[a-z]*[0-9]*$/p
/^[a-z]*$/p' | sort -u > key.raw
echo "Removing common words from key.raw"
comm -23 key.raw $KPATH/ignore | comm -23 - $KPATH/include |
 sort -u > klist

if test -s klist
then
   echo "# put a % by each word going to the $KPATH/include list,
# anything else will be sent to the $KPATH/ignore list." > ked
   cat klist >> ked
   vi ked
echo "C)ontinue or Q)uit?\c "
read cq
case $cq in
  [Cc]) ;;
  [Qq]) exit;;
esac
echo "building inc and and ign"
sed '/^#/d
/^%/{
s///w 'inc'
d
} ' ked |
sed 's/[\/-]/\
/g
s/+//g
s/\]//g' > ign
rm ked
fi

echo "Building ktemp"
if test -s inc
then
   echo "Adding inc to $KPATH/include list..."
   cat inc >> $KPATH/include
   sort -u $KPATH/include -o $KPATH/include
   comm -12 key.raw $KPATH/include | sed 's/$/: '$1'/' > ktemp
else
    comm -12 key.raw $KPATH/include | sed 's/$/: '$1'/' > ktemp
fi

if test -s ign
then
   echo "Adding ign to $KPATH/ignore list..."
   sort -u ign $KPATH/ignore -o $KPATH/ignore
fi

echo "Adding KEY to ktemp file"

if test -f KEY
then
   cp KEY KEY.O
fi
sort KEY ktemp -o ktemp
echo "Rebuilding KEY file"
bkey ktemp > KEY
