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