#!/bin/sh
# Every file a patch touches is written in American spelling, which the
# process file asks for and which I broke by writing "colour" through a
# whole patch. A word list is a poor guard when it lives in a document;
# this one is run by cut_patch.sh, so a British spelling stops a cut.
#
# sh devlog/devscripts/check_spelling.sh <file>...
#
# With no arguments it reads every changed file, as check_deprecated.sh
# does. Autogenerated files and the locale folders are left alone: their
# wording comes from elsewhere.
here=`dirname "$0"`
if [ $# -eq 0 ]; then
files=`git diff --name-only confirmed-head 2>/dev/null`
else
files="$@"
fi
found=0
for one in $files
do
case "$one" in
*/locale/*|*PublicHelpPages.php|src/data/*|*.db|\
*dev_process_for_llms.html)
continue
;;
esac
if [ ! -f "$one" ]; then
continue
fi
words='\b([Cc]olour|[Cc]olours|[Cc]oloured|[Bb]ehaviour'
words="$words|[Nn]ormalise|[Nn]ormalised|[Cc]entre|[Gg]rey"
words="$words|[Ll]icence|[Aa]nalyse)\b"
hits=`grep -n -E "$words" "$one" 2>/dev/null`
if [ -n "$hits" ]; then
echo "$one:"
echo "$hits" | head -5 | sed 's/^/ /'
found=`expr $found + 1`
fi
done
if [ "$found" -gt 0 ]; then
echo "check: $found file(s) hold a British spelling; the process asks"
echo " for American spelling in code, comments and prose."
exit 1
fi
echo "check: American spelling throughout"
exit 0