xref: /titanic_52/usr/src/cmd/spell/spell.sh (revision 03831d35f7499c87d51205817c93e9a8d42c4bae)
1#!/usr/bin/ksh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
24#	  All Rights Reserved
25
26
27#	Copyright (c) 1998, 2000 by Sun Microsystems, Inc.
28#	All rights reserved.
29
30#ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.11	*/
31#	spell program
32# B_SPELL flags, D_SPELL dictionary, F_SPELL input files, H_SPELL history,
33# S_SPELL stop, V_SPELL data for -v
34# L_SPELL sed script, I_SPELL -i option to deroff
35PATH=/usr/lib/spell:/usr/bin:$PATH
36
37SPELLPROG=/usr/lib/spell/spellprog
38
39H_SPELL=${H_SPELL:-/var/adm/spellhist}
40V_SPELL=/dev/null
41F_SPELL=
42FT_SPELL=
43B_SPELL=
44L_SPELL="/usr/bin/sed -e \"/^[.'].*[.'][ 	]*nx[ 	]*\/usr\/lib/d\" -e \"/^[.'].*[.'][ 	]*so[ 	]*\/usr\/lib/d\" -e \"/^[.'][ 	]*so[ 	]*\/usr\/lib/d\" -e \"/^[.'][ 	]*nx[ 	]*\/usr\/lib/d\" "
45
46LOCAL=
47
48# mktmpdir - Create a private (mode 0700) temporary directory inside of /tmp
49# for this process's temporary files.  We set up a trap to remove the
50# directory on exit (trap 0), and also on SIGHUP, SIGINT, SIGQUIT, and
51# SIGTERM.
52#
53mktmpdir() {
54	tmpdir=/tmp/spell.$$
55	trap "/usr/bin/rm -rf $tmpdir; exit" 0 1 2 13 15
56	/usr/bin/mkdir -m 700 $tmpdir || exit 1
57}
58
59mktmpdir
60
61# figure out whether or not we can use deroff
62if [ -x /usr/bin/deroff ]
63then
64	DEROFF="deroff \$I_SPELL"
65else
66	DEROFF="cat"
67fi
68
69# Filter out + arguments that are incorrectly handled by getopts
70set -A args xxx "$@"
71while [ x${args[$OPTIND]#+} = x${args[$OPTIND]} ] && getopts ablvxi A
72do
73	case $A in
74	v)	if [ -r /bin/pdp11 ] && /bin/pdp11
75		then	gettext "spell: -v option not supported on pdp11\n" 1>&2
76			EXIT_SPELL="exit 1"
77		else	B_SPELL="$B_SPELL -v"
78			V_SPELL=$tmpdir/spell.$$
79		fi ;;
80	b) 	D_SPELL=${LB_SPELL:-/usr/lib/spell/hlistb}
81		B_SPELL="$B_SPELL -b" ;;
82	x)	B_SPELL="$B_SPELL -x" ;;
83	l)	L_SPELL="cat" ;;
84	i)	I_SPELL="-i" ;;
85	?)	gettext "Usage: spell [-bvxli] [+local_file] [files...]\n" 1>&2
86		exit 1;;
87	esac
88done
89shift $(($OPTIND - 1))
90
91for A in $*
92do
93	case $A in
94	+*)	if [ "$FIRSTPLUS" = "+" ]
95			then	gettext "spell: multiple + options in spell, all but the last are ignored" 1>&2
96		fi;
97		FIRSTPLUS="$FIRSTPLUS"+
98		if  LOCAL=`expr $A : '+\(.*\)' 2>/dev/null`;
99		then if test ! -r $LOCAL;
100			then printf "`gettext 'spell: Cannot read %s'`\n" "$LOCAL" 1>&2; EXIT_SPELL="exit 1";
101		     fi
102		else gettext "spell: Cannot identify local spell file\n" 1>&2; EXIT_SPELL="exit 1";
103		fi ;;
104	*)	FT_SPELL="$FT_SPELL $A"
105		if [ -r $A ]; then
106			F_SPELL="$F_SPELL $A"
107		else
108			printf "`gettext 'spell: Cannot read file %s'`\n" "$A" 1>&2
109		fi
110	esac
111done
112${EXIT_SPELL:-:}
113
114if [ "x$FT_SPELL" != "x$F_SPELL" ] && [ "x$F_SPELL" = "x" ]; then
115	exit 1
116fi
117
118(cat $F_SPELL; printf "\n";) | eval $L_SPELL |\
119 eval $DEROFF |\
120 /usr/bin/tr -cs "[A-Z][a-z][0-9]\'\&\.\,\;\?\:" "[\012*]" |\
121 /usr/bin/sed '1,$s/^[^A-Za-z0-9]*//' | /usr/bin/sed '1,$s/[^A-Za-z0-9]*$//' |\
122 /usr/bin/sed -n "/[A-Za-z]/p" | /usr/bin/sort -u +0 |\
123 $SPELLPROG ${S_SPELL:-/usr/lib/spell/hstop} 1 |\
124 $SPELLPROG $B_SPELL ${D_SPELL:-/usr/lib/spell/hlista} $V_SPELL |\
125 comm -23 - ${LOCAL:-/dev/null} |\
126 tee -a $H_SPELL
127/usr/bin/who am i >>$H_SPELL 2>/dev/null
128case $V_SPELL in
129/dev/null)
130	exit
131esac
132/usr/bin/sed '/^\./d' $V_SPELL | /usr/bin/sort -u +1f +0
133