#!/bin/sh
# spelldict - Utilise ispell et des filtres pour contrler facilement,
#   en ligne de commande, l'orthographe d'un fichier.

# Il est invitable que certains mots soient signals  tort comme
#   incorrects. Sauvez-les simplement dans un fichier, un par ligne, 
#   et assurez-vous que la variable okaywords pointe vers ce fichier.

okaywords="$HOME/.okaywords" 
tempout="/tmp/spell.tmp.$$" 
spell="ispell -d french"   #  adapter selon les cas

trap "/bin/rm -f $tempout" EXIT

if [ -z "$1" ] ; then
  echo "Syntaxe: spelldict fichier" >&2; exit 1 
elif [ ! -f $okaywords ] ; then 
  echo "Dictionnaire personnel introuvable." >&2
  echo "Crez-en un et excutez cette commande  nouveau." >&2
  echo "Votre fichier dictionnaire: $okaywords." >&2 
  exit 1
fi

for filename
do 
  $spell -a < $filename | \
  grep -v '@(#)' | sed "s/\'//g" | \
    awk '{ if (length($0) > 15 && length($2) > 2) print $2 }' | \
  grep -vif $okaywords | \
  grep '[[:lower:]]' | grep -v '[[:digit:]]' | sort -u | \
  sed 's/^/   /' > $tempout

  if [ -s $tempout ] ; then 
    sed "s/^/${filename}: /" $tempout 
  fi 
done

exit 0
