1fcc96823Sperry#!/bin/sh 2fcc96823Sperry# 3*d3a0b4c8Swiz# $NetBSD: spell.sh,v 1.2 2005/07/06 08:01:13 wiz Exp $ 4fcc96823Sperry# 5fcc96823Sperry# Taken from: 6fcc96823Sperry# OpenBSD: spell.ksh,v 1.8 2004/02/02 22:36:50 fgsch Exp 7fcc96823Sperry# 8fcc96823Sperry# Converted to sh from ksh by Perry E. Metzger 9fcc96823Sperry# 10fcc96823Sperry# Copyright (c) 2001, 2003 Todd C. Miller <Todd.Miller@courtesan.com> 11fcc96823Sperry# 12fcc96823Sperry# Permission to use, copy, modify, and distribute this software for any 13fcc96823Sperry# purpose with or without fee is hereby granted, provided that the above 14fcc96823Sperry# copyright notice and this permission notice appear in all copies. 15fcc96823Sperry# 16fcc96823Sperry# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 17fcc96823Sperry# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 18fcc96823Sperry# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 19fcc96823Sperry# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 20fcc96823Sperry# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 21fcc96823Sperry# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 22fcc96823Sperry# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 23fcc96823Sperry# 24fcc96823Sperry# Sponsored in part by the Defense Advanced Research Projects 25fcc96823Sperry# Agency (DARPA) and Air Force Research Laboratory, Air Force 26fcc96823Sperry# Materiel Command, USAF, under agreement number F39502-99-1-0512. 27fcc96823Sperry# 28fcc96823SperrySPELLPROG=/usr/libexec/spellprog 29fcc96823SperryDICT=/usr/share/dict/words 30fcc96823SperryLOCAL_DICT=/usr/local/share/dict/words 31fcc96823SperrySTOP=/usr/share/dict/stop 32fcc96823SperryLOCAL_STOP=/usr/local/share/dict/stop 33fcc96823SperryAMERICAN=/usr/share/dict/american 34fcc96823SperryBRITISH=/usr/share/dict/british 35fcc96823SperryLANG=$AMERICAN 36fcc96823SperrySTOP_LANG=$BRITISH 37fcc96823SperryEXTRA= 38fcc96823SperryFLAGS= 39fcc96823SperryDEROFF="deroff -w" 40fcc96823SperryHISTFILE= 41fcc96823SperryTMP=`mktemp /tmp/spell.XXXXXXXX` || exit 1 42fcc96823SperryVTMP= 43*d3a0b4c8SwizUSAGE="usage: spell [-biltvx] [-d list] [-h spellhist] [-m a | e | l | m | s]\n\t[-s stop] [+extra_list] [file ...]" 44fcc96823Sperry 45fcc96823Sperrytrap "rm -f $TMP $VTMP; exit 0" 0 1 2 15 46fcc96823Sperry 47fcc96823Sperry# Use local word/stop lists if they exist 48fcc96823Sperryif [ -f $LOCAL_DICT ]; then 49fcc96823Sperry DICT="$DICT $LOCAL_DICT" 50fcc96823Sperryfi 51fcc96823Sperryif [ -f $LOCAL_STOP ]; then 52fcc96823Sperry STOP="$STOP $LOCAL_STOP" 53fcc96823Sperryfi 54fcc96823Sperry 55fcc96823Sperrywhile getopts "biltvxd:h:m:s:" c; do 56fcc96823Sperry case $c in 57fcc96823Sperry b) LANG=$BRITISH 58fcc96823Sperry STOP_LANG=$AMERICAN 59fcc96823Sperry FLAGS="$FLAGS -b" 60fcc96823Sperry ;; 61fcc96823Sperry i) DEROFF="$DEROFF -i" 62fcc96823Sperry ;; 63fcc96823Sperry l) DEROFF="delatex" 64fcc96823Sperry ;; 65fcc96823Sperry m) DEROFF="$DEROFF -m $OPTARG" 66fcc96823Sperry ;; 67fcc96823Sperry t) DEROFF="detex" 68fcc96823Sperry ;; 69fcc96823Sperry v) VTMP=`mktemp /tmp/spell.XXXXXXXX` || { 70fcc96823Sperry rm -f $TMP 71fcc96823Sperry exit 1 72fcc96823Sperry } 73fcc96823Sperry FLAGS="$FLAGS -v -o $VTMP" 74fcc96823Sperry ;; 75fcc96823Sperry x) FLAGS="$FLAGS -x" 76fcc96823Sperry ;; 77fcc96823Sperry d) DICT="$OPTARG" 78fcc96823Sperry LANG= 79fcc96823Sperry ;; 80fcc96823Sperry s) STOP="$OPTARG" 81fcc96823Sperry STOP_LANG= 82fcc96823Sperry LOCAL_STOP= 83fcc96823Sperry ;; 84fcc96823Sperry h) HISTFILE="$OPTARG" 85fcc96823Sperry ;; 86fcc96823Sperry *) echo "$USAGE" 1>&2 87fcc96823Sperry exit 1 88fcc96823Sperry ;; 89fcc96823Sperry esac 90fcc96823Sperrydone 91fcc96823Sperryshift $(( $OPTIND - 1 )) 92fcc96823Sperry 93fcc96823Sperrywhile test $# -ne 0; do 94fcc96823Sperry case "$1" in 95fcc96823Sperry +*) EXTRA="$EXTRA ${1#+}" 96fcc96823Sperry shift 97fcc96823Sperry ;; 98fcc96823Sperry *) break 99fcc96823Sperry ;; 100fcc96823Sperry esac 101fcc96823Sperrydone 102fcc96823Sperry 103fcc96823Sperry# Any parameters left are files to be checked, pass them to deroff 104fcc96823SperryDEROFF="$DEROFF $@" 105fcc96823Sperry 106fcc96823Sperryif [ -n "$HISTFILE" ]; then 107fcc96823Sperry $DEROFF | sort -u | $SPELLPROG -o $TMP $STOP $STOP_LANG | \ 108fcc96823Sperry $SPELLPROG $FLAGS $DICT $LANG $EXTRA | sort -u -k1f - $TMP | \ 109fcc96823Sperry tee -a $HISTFILE 110fcc96823Sperry who -m >> $HISTFILE 111fcc96823Sperryelse 112fcc96823Sperry $DEROFF | sort -u | $SPELLPROG -o $TMP $STOP $STOP_LANG | \ 113fcc96823Sperry $SPELLPROG $FLAGS $DICT $LANG $EXTRA | sort -u -k1f - $TMP 114fcc96823Sperryfi 115fcc96823Sperry 116fcc96823Sperryif [ -n "$VTMP" ]; then 117fcc96823Sperry sort -u -k2f -k1 $VTMP 118fcc96823Sperryfi 119fcc96823Sperry 120fcc96823Sperryexit 0 121