Annotation of src/usr.bin/spell/spell.ksh, Revision 1.4
1.1 millert 1: #!/bin/ksh -
2: #
1.4 ! pvalchev 3: # $OpenBSD: spell.ksh,v 1.3 2002/11/27 01:18:34 margarida Exp $
1.1 millert 4: #
5: # Copyright (c) 2001 Todd C. Miller <Todd.Miller@courtesan.com>
6: # All rights reserved.
7: #
8: # Redistribution and use in source and binary forms, with or without
9: # modification, are permitted provided that the following conditions
10: # are met:
11: # 1. Redistributions of source code must retain the above copyright
12: # notice, this list of conditions and the following disclaimer.
13: # 2. Redistributions in binary form must reproduce the above copyright
14: # notice, this list of conditions and the following disclaimer in the
15: # documentation and/or other materials provided with the distribution.
16: # 3. The name of the author may not be used to endorse or promote products
17: # derived from this software without specific prior written permission.
18: #
19: # THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20: # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21: # AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
22: # THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23: # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24: # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25: # OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26: # WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27: # OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28: # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29: #
30: SPELLPROG=/usr/libexec/spellprog
31: DICT=/usr/share/dict/words
32: LOCAL_DICT=/usr/local/share/dict/words
33: STOP=/usr/share/dict/stop
34: LOCAL_STOP=/usr/local/share/dict/stop
35: AMERICAN=/usr/share/dict/american
36: BRITISH=/usr/share/dict/british
37: LANG=$AMERICAN
38: STOP_LANG=$BRITISH
39: EXTRA=
40: FLAGS=
41: DEROFF="deroff -w"
42: HISTFILE=
43: TMP=`mktemp /tmp/spell.XXXXXXXX` || exit 1
44: VTMP=
45: USAGE="usage: spell [-biltvx] [-d list] [-h spellhist] [-s stop] [+extra_list] [file ...]"
46:
47: trap "rm -f $TMP $VTMP; exit 0" 0
48:
49: # Use local word/stop lists if they exist
50: if [ -f $LOCAL_DICT ]; then
51: DICT="$DICT $LOCAL_DICT"
52: fi
53: if [ -f $LOCAL_STOP ]; then
54: STOP="$STOP $LOCAL_STOP"
55: fi
56:
57: # getopts will treat +foo the same as -foo so we have to make a copy
58: # of the args and quit the loop when we find something starting with '+'
59: set -A argv $0 "$@"
60: while test "${argv[$OPTIND]#+}" = "${argv[$OPTIND]}" && \
1.2 millert 61: getopts "biltvxd:h:m:s:" c; do
1.1 millert 62: case $c in
63: b) LANG=$BRITISH
64: STOP_LANG=$AMERICAN
65: FLAGS[${#FLAGS[@]}]="-b"
66: ;;
67: i) DEROFF="$DEROFF -i"
68: ;;
1.3 margarid 69: l) DEROFF="delatex"
1.2 millert 70: ;;
71: m) DEROFF="$DEROFF -m $OPTARG"
1.1 millert 72: ;;
73: t) DEROFF="detex"
74: ;;
1.4 ! pvalchev 75: v) VTMP=`mktemp /tmp/spell.XXXXXXXX` || {
! 76: rm -f ${TMP}
! 77: exit 1
! 78: }
1.1 millert 79: FLAGS[${#FLAGS[@]}]="-v"
80: FLAGS[${#FLAGS[@]}]="-o"
81: FLAGS[${#FLAGS[@]}]="$VTMP"
82: ;;
83: x) FLAGS[${#FLAGS[@]}]="-x"
84: ;;
85: d) DICT="$OPTARG"
86: LANG=
87: ;;
88: s) STOP="$OPTARG"
89: STOP_LANG=
90: LOCAL_STOP=
91: ;;
92: h) HISTFILE="$OPTARG"
93: ;;
94: *) echo "$USAGE" 1>&2
95: exit 1
96: ;;
97: esac
98: done
99: shift $(( $OPTIND - 1 ))
100:
101: while test $# -ne 0; do
102: case "$1" in
103: +*) EXTRA="$EXTRA ${1#+}"
104: shift
105: ;;
106: *) break
107: ;;
108: esac
109: done
110:
111: # Any parameters left are files to be checked, pass them to deroff
112: DEROFF="$DEROFF $@"
113:
114: if [ -n "$HISTFILE" ]; then
115: $DEROFF | sort -u | $SPELLPROG -o $TMP $STOP $STOP_LANG | \
116: $SPELLPROG ${FLAGS[*]} $DICT $LANG $EXTRA | sort -u -k1f - $TMP | \
117: tee -a $HISTFILE
118: who -m >> $HISTFILE
119: else
120: $DEROFF | sort -u | $SPELLPROG -o $TMP $STOP $STOP_LANG | \
121: $SPELLPROG ${FLAGS[*]} $DICT $LANG $EXTRA | sort -u -k1f - $TMP
122: fi
123:
124: if [ -n "$VTMP" ]; then
125: sort -u -k2f -k1 $VTMP
126: fi
127:
128: exit 0