Annotation of src/usr.bin/spell/spell.ksh, Revision 1.3
1.1 millert 1: #!/bin/ksh -
2: #
1.3 ! margarid 3: # $OpenBSD: spell.ksh,v 1.2 2002/03/02 16:33:51 millert 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: ;;
75: v) VTMP=`mktemp /tmp/spell.XXXXXXXX` || exit 1
76: FLAGS[${#FLAGS[@]}]="-v"
77: FLAGS[${#FLAGS[@]}]="-o"
78: FLAGS[${#FLAGS[@]}]="$VTMP"
79: ;;
80: x) FLAGS[${#FLAGS[@]}]="-x"
81: ;;
82: d) DICT="$OPTARG"
83: LANG=
84: ;;
85: s) STOP="$OPTARG"
86: STOP_LANG=
87: LOCAL_STOP=
88: ;;
89: h) HISTFILE="$OPTARG"
90: ;;
91: *) echo "$USAGE" 1>&2
92: exit 1
93: ;;
94: esac
95: done
96: shift $(( $OPTIND - 1 ))
97:
98: while test $# -ne 0; do
99: case "$1" in
100: +*) EXTRA="$EXTRA ${1#+}"
101: shift
102: ;;
103: *) break
104: ;;
105: esac
106: done
107:
108: # Any parameters left are files to be checked, pass them to deroff
109: DEROFF="$DEROFF $@"
110:
111: if [ -n "$HISTFILE" ]; then
112: $DEROFF | sort -u | $SPELLPROG -o $TMP $STOP $STOP_LANG | \
113: $SPELLPROG ${FLAGS[*]} $DICT $LANG $EXTRA | sort -u -k1f - $TMP | \
114: tee -a $HISTFILE
115: who -m >> $HISTFILE
116: else
117: $DEROFF | sort -u | $SPELLPROG -o $TMP $STOP $STOP_LANG | \
118: $SPELLPROG ${FLAGS[*]} $DICT $LANG $EXTRA | sort -u -k1f - $TMP
119: fi
120:
121: if [ -n "$VTMP" ]; then
122: sort -u -k2f -k1 $VTMP
123: fi
124:
125: exit 0