#!/bin/sh
# Shell script to spell check files.  Mixed case words are split up

# Author:  Christopher Hylands
# Version: $Id: ptspell,v 1.22 2005/02/28 20:51:09 cxh Exp $
#
# Copyright (c) 1999-2005 The Regents of the University of California.
# 	All Rights Reserved.
#
# Permission is hereby granted, without written agreement and without
# license or royalty fees, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that the
# above copyright notice and the following two paragraphs appear in all
# copies of this software.
#
# IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
# FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
# ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
# THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
# THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
# INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
# PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
# CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
# ENHANCEMENTS, OR MODIFICATIONS.
#
# 						PT_COPYRIGHT_VERSION_2
# 						COPYRIGHTENDKEY

# Spell check the arguments.
# Mixed case words are split into their constituent words

# If the local dictionary can be found, use it
# Keep the local dictionary in sort order
LOCALFILE=
if [ -f "$PTII/util/testsuite/ptlocaldict" ]; then
	LOCALFILE="$PTII/util/testsuite/ptlocaldict"
else
	echo "$0: The Ptolemy II local dictionary at '$PTII/util/testsuite/ptlocaldict' can't be found"
fi

ISPELL=/usr/local/bin/ispell
if [ -f $ISPELL ]; then
    cat ${1+"$@"} |$ISPELL -l -p $LOCALFILE | \
	sed -e 's/\./ /g' | $ISPELL -l -p $LOCALFILE | \
	sed -e 's/\([a-z]\)\([A-Z]\)/\1 \2/g' | $ISPELL -l -p $LOCALFILE | \
	sed -e 's/^\([A-Z]*\)\([A-Z]\)/\1 \2/g' | \
        $ISPELL -l -p $LOCALFILE | sort

else
    # Determine if we are on windows
    windows=no
    case "`uname -s`" in
	CYGWIN*) 
	    windows=yes;;
        # Tcsh
        Windows*)
	    windows=yes;;
    esac

    if [ "$windows" = "yes" ]; then
	echo "$0: Could not find"
	echo "  '$ISPELL'."
    fi


    # The sed calls split up words with internal capitalization
    spell +$LOCALFILE ${1+"$@"} | \
	sed -e 's/\./ /g' \
	    -e 's/&quot;/ /g' \
	    -e 's/&amp;/ /g' \
	    -e 's/&nbsp;/ /g' \
	    -e 's/nbsp;/ /g' \
	    -e 's/&lt;/ /g' \
	    -e 's/&gt;/ /g' \
	    -e 's/&lt/ /g' \
	    -e 's/&gt/ /g' \
	    -e 's/lt;/ /g' \
	    -e 's/gt;/ /g' \
	    -e 's/quot;/ /g' \
	    | spell +$LOCALFILE | \
	sed -e 's/\([a-z]\)\([A-Z]\)/\1 \2/g' | spell +$LOCALFILE | \
	sed -e 's/^\([A-Z]*\)\([A-Z]\)/\1 \2/g' \
        | spell +$LOCALFILE
fi
