xref: /titanic_50/usr/src/cmd/spell/spellprog.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
23*7c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*7c478bd9Sstevel@tonic-gate 
25*7c478bd9Sstevel@tonic-gate 
26*7c478bd9Sstevel@tonic-gate /*
27*7c478bd9Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
29*7c478bd9Sstevel@tonic-gate  */
30*7c478bd9Sstevel@tonic-gate 
31*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
32*7c478bd9Sstevel@tonic-gate 
33*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
34*7c478bd9Sstevel@tonic-gate #include <unistd.h>
35*7c478bd9Sstevel@tonic-gate #include <limits.h>
36*7c478bd9Sstevel@tonic-gate #include <string.h>
37*7c478bd9Sstevel@tonic-gate #include <stdio.h>
38*7c478bd9Sstevel@tonic-gate #include <ctype.h>
39*7c478bd9Sstevel@tonic-gate #include <locale.h>
40*7c478bd9Sstevel@tonic-gate #include "hash.h"
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate #define	Tolower(c) (isupper(c)?tolower(c):c)
43*7c478bd9Sstevel@tonic-gate #define	DLEV 2
44*7c478bd9Sstevel@tonic-gate 
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate  * ANSI prototypes
47*7c478bd9Sstevel@tonic-gate  */
48*7c478bd9Sstevel@tonic-gate static int	ily(char *, char *, char *, int);
49*7c478bd9Sstevel@tonic-gate static int	s(char *, char *, char *, int);
50*7c478bd9Sstevel@tonic-gate static int	es(char *, char *, char *, int);
51*7c478bd9Sstevel@tonic-gate static int	subst(char *, char *, char *, int);
52*7c478bd9Sstevel@tonic-gate static int	nop(void);
53*7c478bd9Sstevel@tonic-gate static int	bility(char *, char *, char *, int);
54*7c478bd9Sstevel@tonic-gate static int	i_to_y(char *, char *, char *, int);
55*7c478bd9Sstevel@tonic-gate static int	CCe(char *, char *, char *, int);
56*7c478bd9Sstevel@tonic-gate static int	y_to_e(char *, char *, char *, int);
57*7c478bd9Sstevel@tonic-gate static int	strip(char *, char *, char *, int);
58*7c478bd9Sstevel@tonic-gate static int	ize(char *, char *, char *, int);
59*7c478bd9Sstevel@tonic-gate static int	tion(char *, char *, char *, int);
60*7c478bd9Sstevel@tonic-gate static int	an(char *, char *, char *, int);
61*7c478bd9Sstevel@tonic-gate int		prime(char *);
62*7c478bd9Sstevel@tonic-gate static void	ise(void);
63*7c478bd9Sstevel@tonic-gate static int	tryword(char *, char *, int);
64*7c478bd9Sstevel@tonic-gate static int	trypref(char *, char *, int);
65*7c478bd9Sstevel@tonic-gate static int	trysuff(char *, int);
66*7c478bd9Sstevel@tonic-gate static int	vowel(int);
67*7c478bd9Sstevel@tonic-gate static int	dict(char *, char *);
68*7c478bd9Sstevel@tonic-gate static int	monosyl(char *, char *);
69*7c478bd9Sstevel@tonic-gate static int	VCe(char *, char *, char *, int);
70*7c478bd9Sstevel@tonic-gate static char	*skipv(char *);
71*7c478bd9Sstevel@tonic-gate static void	ztos(char *);
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate static struct suftab {
74*7c478bd9Sstevel@tonic-gate 	char *suf;
75*7c478bd9Sstevel@tonic-gate 	int (*p1)();
76*7c478bd9Sstevel@tonic-gate 	int n1;
77*7c478bd9Sstevel@tonic-gate 	char *d1;
78*7c478bd9Sstevel@tonic-gate 	char *a1;
79*7c478bd9Sstevel@tonic-gate 	int (*p2)();
80*7c478bd9Sstevel@tonic-gate 	int n2;
81*7c478bd9Sstevel@tonic-gate 	char *d2;
82*7c478bd9Sstevel@tonic-gate 	char *a2;
83*7c478bd9Sstevel@tonic-gate } suftab[] = {
84*7c478bd9Sstevel@tonic-gate 	{"ssen", ily, 4, "-y+iness", "+ness" },
85*7c478bd9Sstevel@tonic-gate 	{"ssel", ily, 4, "-y+i+less", "+less" },
86*7c478bd9Sstevel@tonic-gate 	{"se", s, 1, "", "+s", 	es, 2, "-y+ies", "+es" },
87*7c478bd9Sstevel@tonic-gate 	{"s'", s, 2, "", "+'s"},
88*7c478bd9Sstevel@tonic-gate 	{"s", s, 1, "", "+s"},
89*7c478bd9Sstevel@tonic-gate 	{"ecn", subst, 1, "-t+ce", ""},
90*7c478bd9Sstevel@tonic-gate 	{"ycn", subst, 1, "-t+cy", ""},
91*7c478bd9Sstevel@tonic-gate 	{"ytilb", nop, 0, "", ""},
92*7c478bd9Sstevel@tonic-gate 	{"ytilib", bility, 5, "-le+ility", ""},
93*7c478bd9Sstevel@tonic-gate 	{"elbaif", i_to_y, 4, "-y+iable", ""},
94*7c478bd9Sstevel@tonic-gate 	{"elba", CCe, 4, "-e+able", "+able"},
95*7c478bd9Sstevel@tonic-gate 	{"yti", CCe, 3, "-e+ity", "+ity"},
96*7c478bd9Sstevel@tonic-gate 	{"ylb", y_to_e, 1, "-e+y", ""},
97*7c478bd9Sstevel@tonic-gate 	{"yl", ily, 2, "-y+ily", "+ly"},
98*7c478bd9Sstevel@tonic-gate 	{"laci", strip, 2, "", "+al"},
99*7c478bd9Sstevel@tonic-gate 	{"latnem", strip, 2, "", "+al"},
100*7c478bd9Sstevel@tonic-gate 	{"lanoi", strip, 2, "", "+al"},
101*7c478bd9Sstevel@tonic-gate 	{"tnem", strip, 4, "", "+ment"},
102*7c478bd9Sstevel@tonic-gate 	{"gni", CCe, 3, "-e+ing", "+ing"},
103*7c478bd9Sstevel@tonic-gate 	{"reta", nop, 0, "", ""},
104*7c478bd9Sstevel@tonic-gate 	{"retc", nop, 0, "", ""},
105*7c478bd9Sstevel@tonic-gate 	{"re", strip, 1, "", "+r", i_to_y, 2, "-y+ier", "+er"},
106*7c478bd9Sstevel@tonic-gate 	{"de", strip, 1, "", "+d", i_to_y, 2, "-y+ied", "+ed"},
107*7c478bd9Sstevel@tonic-gate 	{"citsi", strip, 2, "", "+ic"},
108*7c478bd9Sstevel@tonic-gate 	{"citi", ize, 1, "-ic+e", ""},
109*7c478bd9Sstevel@tonic-gate 	{"cihparg", i_to_y, 1, "-y+ic", ""},
110*7c478bd9Sstevel@tonic-gate 	{"tse", strip, 2, "", "+st", 	i_to_y, 3, "-y+iest", "+est"},
111*7c478bd9Sstevel@tonic-gate 	{"cirtem", i_to_y, 1, "-y+ic", ""},
112*7c478bd9Sstevel@tonic-gate 	{"yrtem", subst, 0, "-er+ry", ""},
113*7c478bd9Sstevel@tonic-gate 	{"cigol", i_to_y, 1, "-y+ic", ""},
114*7c478bd9Sstevel@tonic-gate 	{"tsigol", i_to_y, 2, "-y+ist", ""},
115*7c478bd9Sstevel@tonic-gate 	{"tsi", CCe, 3, "-e+ist", "+ist"},
116*7c478bd9Sstevel@tonic-gate 	{"msi", CCe, 3, "-e+ism", "+ist"},
117*7c478bd9Sstevel@tonic-gate 	{"noitacifi", i_to_y, 6, "-y+ication", ""},
118*7c478bd9Sstevel@tonic-gate 	{"noitazi", ize, 4, "-e+ation", ""},
119*7c478bd9Sstevel@tonic-gate 	{"rota", tion, 2, "-e+or", ""},
120*7c478bd9Sstevel@tonic-gate 	{"rotc", tion, 2, "", "+or"},
121*7c478bd9Sstevel@tonic-gate 	{"noit", tion, 3, "-e+ion", "+ion"},
122*7c478bd9Sstevel@tonic-gate 	{"naino", an, 3, "", "+ian"},
123*7c478bd9Sstevel@tonic-gate 	{"na", an, 1, "", "+n"},
124*7c478bd9Sstevel@tonic-gate 	{"evi", subst, 0, "-ion+ive", ""},
125*7c478bd9Sstevel@tonic-gate 	{"ezi", CCe, 3, "-e+ize", "+ize"},
126*7c478bd9Sstevel@tonic-gate 	{"pihs", strip, 4, "", "+ship"},
127*7c478bd9Sstevel@tonic-gate 	{"dooh", ily, 4, "-y+ihood", "+hood"},
128*7c478bd9Sstevel@tonic-gate 	{"luf", ily, 3, "-y+iful", "+ful"},
129*7c478bd9Sstevel@tonic-gate 	{"ekil", strip, 4, "", "+like"},
130*7c478bd9Sstevel@tonic-gate 	0
131*7c478bd9Sstevel@tonic-gate };
132*7c478bd9Sstevel@tonic-gate 
133*7c478bd9Sstevel@tonic-gate static char *preftab[] = {
134*7c478bd9Sstevel@tonic-gate 	"anti",
135*7c478bd9Sstevel@tonic-gate 	"auto",
136*7c478bd9Sstevel@tonic-gate 	"bio",
137*7c478bd9Sstevel@tonic-gate 	"counter",
138*7c478bd9Sstevel@tonic-gate 	"dis",
139*7c478bd9Sstevel@tonic-gate 	"electro",
140*7c478bd9Sstevel@tonic-gate 	"en",
141*7c478bd9Sstevel@tonic-gate 	"fore",
142*7c478bd9Sstevel@tonic-gate 	"geo",
143*7c478bd9Sstevel@tonic-gate 	"hyper",
144*7c478bd9Sstevel@tonic-gate 	"intra",
145*7c478bd9Sstevel@tonic-gate 	"inter",
146*7c478bd9Sstevel@tonic-gate 	"iso",
147*7c478bd9Sstevel@tonic-gate 	"kilo",
148*7c478bd9Sstevel@tonic-gate 	"magneto",
149*7c478bd9Sstevel@tonic-gate 	"meta",
150*7c478bd9Sstevel@tonic-gate 	"micro",
151*7c478bd9Sstevel@tonic-gate 	"mid",
152*7c478bd9Sstevel@tonic-gate 	"milli",
153*7c478bd9Sstevel@tonic-gate 	"mis",
154*7c478bd9Sstevel@tonic-gate 	"mono",
155*7c478bd9Sstevel@tonic-gate 	"multi",
156*7c478bd9Sstevel@tonic-gate 	"non",
157*7c478bd9Sstevel@tonic-gate 	"out",
158*7c478bd9Sstevel@tonic-gate 	"over",
159*7c478bd9Sstevel@tonic-gate 	"photo",
160*7c478bd9Sstevel@tonic-gate 	"poly",
161*7c478bd9Sstevel@tonic-gate 	"pre",
162*7c478bd9Sstevel@tonic-gate 	"pseudo",
163*7c478bd9Sstevel@tonic-gate 	"psycho",
164*7c478bd9Sstevel@tonic-gate 	"re",
165*7c478bd9Sstevel@tonic-gate 	"semi",
166*7c478bd9Sstevel@tonic-gate 	"stereo",
167*7c478bd9Sstevel@tonic-gate 	"sub",
168*7c478bd9Sstevel@tonic-gate 	"super",
169*7c478bd9Sstevel@tonic-gate 	"tele",
170*7c478bd9Sstevel@tonic-gate 	"thermo",
171*7c478bd9Sstevel@tonic-gate 	"ultra",
172*7c478bd9Sstevel@tonic-gate 	"under",	/* must precede un */
173*7c478bd9Sstevel@tonic-gate 	"un",
174*7c478bd9Sstevel@tonic-gate 	0
175*7c478bd9Sstevel@tonic-gate };
176*7c478bd9Sstevel@tonic-gate 
177*7c478bd9Sstevel@tonic-gate static int vflag;
178*7c478bd9Sstevel@tonic-gate static int xflag;
179*7c478bd9Sstevel@tonic-gate static char *prog;
180*7c478bd9Sstevel@tonic-gate static char word[LINE_MAX];
181*7c478bd9Sstevel@tonic-gate static char original[LINE_MAX];
182*7c478bd9Sstevel@tonic-gate static char *deriv[LINE_MAX];
183*7c478bd9Sstevel@tonic-gate static char affix[LINE_MAX];
184*7c478bd9Sstevel@tonic-gate static FILE *file, *found;
185*7c478bd9Sstevel@tonic-gate /*
186*7c478bd9Sstevel@tonic-gate  *	deriv is stack of pointers to notes like +micro +ed
187*7c478bd9Sstevel@tonic-gate  *	affix is concatenated string of notes
188*7c478bd9Sstevel@tonic-gate  *	the buffer size 141 stems from the sizes of original and affix.
189*7c478bd9Sstevel@tonic-gate  */
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate /*
192*7c478bd9Sstevel@tonic-gate  *	in an attempt to defray future maintenance misunderstandings, here is
193*7c478bd9Sstevel@tonic-gate  *	an attempt to describe the input/output expectations of the spell
194*7c478bd9Sstevel@tonic-gate  *	program.
195*7c478bd9Sstevel@tonic-gate  *
196*7c478bd9Sstevel@tonic-gate  *	spellprog is intended to be called from the shell file spell.
197*7c478bd9Sstevel@tonic-gate  *	because of this, there is little error checking (this is historical, not
198*7c478bd9Sstevel@tonic-gate  *	necessarily advisable).
199*7c478bd9Sstevel@tonic-gate  *
200*7c478bd9Sstevel@tonic-gate  *	spellprog options hashed-list pass
201*7c478bd9Sstevel@tonic-gate  *
202*7c478bd9Sstevel@tonic-gate  *	the hashed-list is a list of the form made by spellin.
203*7c478bd9Sstevel@tonic-gate  *	there are 2 types of hashed lists:
204*7c478bd9Sstevel@tonic-gate  *		1. a stop list: this specifies words that by the rules embodied
205*7c478bd9Sstevel@tonic-gate  *		   in spellprog would be recognized as correct, BUT are really
206*7c478bd9Sstevel@tonic-gate  *		   errors.
207*7c478bd9Sstevel@tonic-gate  *		2. a dictionary of correctly spelled words.
208*7c478bd9Sstevel@tonic-gate  *	the pass number determines how the words found in the specified
209*7c478bd9Sstevel@tonic-gate  *	hashed-list are treated. If the pass number is 1, the hashed-list is
210*7c478bd9Sstevel@tonic-gate  *	treated as the stop-list, otherwise, it is treated as the regular
211*7c478bd9Sstevel@tonic-gate  *	dictionary list. in this case, the value of "pass" is a filename. Found
212*7c478bd9Sstevel@tonic-gate  *	words are written to this file.
213*7c478bd9Sstevel@tonic-gate  *
214*7c478bd9Sstevel@tonic-gate  *	In the normal case, the filename = /dev/null. However, if the v option
215*7c478bd9Sstevel@tonic-gate  *	is specified, the derivations are written to this file.
216*7c478bd9Sstevel@tonic-gate  *	The spellprog looks up words in the hashed-list; if a word is found, it
217*7c478bd9Sstevel@tonic-gate  *	is printed to the stdout. If the hashed-list was the stop-list, the
218*7c478bd9Sstevel@tonic-gate  *	words found are presumed to be misspellings. in this case,
219*7c478bd9Sstevel@tonic-gate  *	a control character is printed ( a "-" is appended to the word.
220*7c478bd9Sstevel@tonic-gate  *	a hyphen will never occur naturally in the input list because deroff
221*7c478bd9Sstevel@tonic-gate  *	is used in the shell file before calling spellprog.)
222*7c478bd9Sstevel@tonic-gate  *	If the regualar spelling list was used (hlista or hlistb), the words
223*7c478bd9Sstevel@tonic-gate  *	are correct, and may be ditched. (unless the -v option was used -
224*7c478bd9Sstevel@tonic-gate  *	see the manual page).
225*7c478bd9Sstevel@tonic-gate  *
226*7c478bd9Sstevel@tonic-gate  *	spellprog should be called twice : first with the stop-list, to flag all
227*7c478bd9Sstevel@tonic-gate  *	a priori incorrectly spelled words; second with the dictionary.
228*7c478bd9Sstevel@tonic-gate  *
229*7c478bd9Sstevel@tonic-gate  *	spellprog hstop 1 |\
230*7c478bd9Sstevel@tonic-gate  *	spellprog hlista /dev/null
231*7c478bd9Sstevel@tonic-gate  *
232*7c478bd9Sstevel@tonic-gate  *	for a complete scenario, see the shell file: spell.
233*7c478bd9Sstevel@tonic-gate  *
234*7c478bd9Sstevel@tonic-gate  */
235*7c478bd9Sstevel@tonic-gate 
236*7c478bd9Sstevel@tonic-gate void
237*7c478bd9Sstevel@tonic-gate main(int argc, char **argv)
238*7c478bd9Sstevel@tonic-gate {
239*7c478bd9Sstevel@tonic-gate 	register char *ep, *cp;
240*7c478bd9Sstevel@tonic-gate 	register char *dp;
241*7c478bd9Sstevel@tonic-gate 	int fold;
242*7c478bd9Sstevel@tonic-gate 	int c, j;
243*7c478bd9Sstevel@tonic-gate 	int pass;
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate 	/* Set locale environment variables local definitions */
246*7c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
247*7c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
248*7c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it wasn't */
249*7c478bd9Sstevel@tonic-gate #endif
250*7c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
251*7c478bd9Sstevel@tonic-gate 
252*7c478bd9Sstevel@tonic-gate 
253*7c478bd9Sstevel@tonic-gate 	prog = argv[0];
254*7c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "bvx")) != EOF) {
255*7c478bd9Sstevel@tonic-gate 		switch (c) {
256*7c478bd9Sstevel@tonic-gate 		case 'b':
257*7c478bd9Sstevel@tonic-gate 			ise();
258*7c478bd9Sstevel@tonic-gate 			break;
259*7c478bd9Sstevel@tonic-gate 		case 'v':
260*7c478bd9Sstevel@tonic-gate 			vflag++;
261*7c478bd9Sstevel@tonic-gate 			break;
262*7c478bd9Sstevel@tonic-gate 		case 'x':
263*7c478bd9Sstevel@tonic-gate 			xflag++;
264*7c478bd9Sstevel@tonic-gate 			break;
265*7c478bd9Sstevel@tonic-gate 		}
266*7c478bd9Sstevel@tonic-gate 	}
267*7c478bd9Sstevel@tonic-gate 
268*7c478bd9Sstevel@tonic-gate 	argc -= optind;
269*7c478bd9Sstevel@tonic-gate 	argv = &argv[optind];
270*7c478bd9Sstevel@tonic-gate 
271*7c478bd9Sstevel@tonic-gate 	if ((argc < 2) || !prime(*argv)) {
272*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
273*7c478bd9Sstevel@tonic-gate 		    gettext("%s: cannot initialize hash table\n"), prog);
274*7c478bd9Sstevel@tonic-gate 		exit(1);
275*7c478bd9Sstevel@tonic-gate 	}
276*7c478bd9Sstevel@tonic-gate 	argc--;
277*7c478bd9Sstevel@tonic-gate 	argv++;
278*7c478bd9Sstevel@tonic-gate 
279*7c478bd9Sstevel@tonic-gate /*
280*7c478bd9Sstevel@tonic-gate  *	if pass is not 1, it is assumed to be a filename.
281*7c478bd9Sstevel@tonic-gate  *	found words are written to this file.
282*7c478bd9Sstevel@tonic-gate  */
283*7c478bd9Sstevel@tonic-gate 	pass = **argv;
284*7c478bd9Sstevel@tonic-gate 	if (pass != '1')
285*7c478bd9Sstevel@tonic-gate 		found = fopen(*argv, "w");
286*7c478bd9Sstevel@tonic-gate 
287*7c478bd9Sstevel@tonic-gate 	for (;;) {
288*7c478bd9Sstevel@tonic-gate 		affix[0] = 0;
289*7c478bd9Sstevel@tonic-gate 		file = stdout;
290*7c478bd9Sstevel@tonic-gate 		for (ep = word; (*ep = j = getchar()) != '\n'; ep++)
291*7c478bd9Sstevel@tonic-gate 			if (j == EOF)
292*7c478bd9Sstevel@tonic-gate 				exit(0);
293*7c478bd9Sstevel@tonic-gate /*
294*7c478bd9Sstevel@tonic-gate  *	here is the hyphen processing. these words were found in the stop
295*7c478bd9Sstevel@tonic-gate  *	list. however, if they exist as is, (no derivations tried) in the
296*7c478bd9Sstevel@tonic-gate  *	dictionary, let them through as correct.
297*7c478bd9Sstevel@tonic-gate  *
298*7c478bd9Sstevel@tonic-gate  */
299*7c478bd9Sstevel@tonic-gate 		if (ep[-1] == '-') {
300*7c478bd9Sstevel@tonic-gate 			*--ep = 0;
301*7c478bd9Sstevel@tonic-gate 			if (!tryword(word, ep, 0))
302*7c478bd9Sstevel@tonic-gate 				(void) fprintf(file, "%s\n", word);
303*7c478bd9Sstevel@tonic-gate 			continue;
304*7c478bd9Sstevel@tonic-gate 		}
305*7c478bd9Sstevel@tonic-gate 		for (cp = word, dp = original; cp < ep; )
306*7c478bd9Sstevel@tonic-gate 			*dp++ = *cp++;
307*7c478bd9Sstevel@tonic-gate 		*dp = 0;
308*7c478bd9Sstevel@tonic-gate 		fold = 0;
309*7c478bd9Sstevel@tonic-gate 		for (cp = word; cp < ep; cp++)
310*7c478bd9Sstevel@tonic-gate 			if (islower(*cp))
311*7c478bd9Sstevel@tonic-gate 				goto lcase;
312*7c478bd9Sstevel@tonic-gate 		if (((ep - word) == 1) &&
313*7c478bd9Sstevel@tonic-gate 		    ((word[0] == 'A') || (word[0] == 'I')))
314*7c478bd9Sstevel@tonic-gate 			continue;
315*7c478bd9Sstevel@tonic-gate 		if (trypref(ep, ".", 0))
316*7c478bd9Sstevel@tonic-gate 			goto foundit;
317*7c478bd9Sstevel@tonic-gate 		++fold;
318*7c478bd9Sstevel@tonic-gate 		for (cp = original+1, dp = word+1; dp < ep; dp++, cp++)
319*7c478bd9Sstevel@tonic-gate 			*dp = Tolower(*cp);
320*7c478bd9Sstevel@tonic-gate lcase:
321*7c478bd9Sstevel@tonic-gate 		if (((ep - word) == 1) && (word[0] == 'a'))
322*7c478bd9Sstevel@tonic-gate 			continue;
323*7c478bd9Sstevel@tonic-gate 		if (trypref(ep, ".", 0)||trysuff(ep, 0))
324*7c478bd9Sstevel@tonic-gate 			goto foundit;
325*7c478bd9Sstevel@tonic-gate 		if (isupper(word[0])) {
326*7c478bd9Sstevel@tonic-gate 			for (cp = original, dp = word; *dp = *cp++; dp++)
327*7c478bd9Sstevel@tonic-gate 				if (fold) *dp = Tolower(*dp);
328*7c478bd9Sstevel@tonic-gate 			word[0] = Tolower(word[0]);
329*7c478bd9Sstevel@tonic-gate 			goto lcase;
330*7c478bd9Sstevel@tonic-gate 		}
331*7c478bd9Sstevel@tonic-gate 		(void) fprintf(file, "%s\n", original);
332*7c478bd9Sstevel@tonic-gate 		continue;
333*7c478bd9Sstevel@tonic-gate 
334*7c478bd9Sstevel@tonic-gate foundit:
335*7c478bd9Sstevel@tonic-gate 		if (pass == '1')
336*7c478bd9Sstevel@tonic-gate 			(void) fprintf(file, "%s-\n", original);
337*7c478bd9Sstevel@tonic-gate 		else if (affix[0] != 0 && affix[0] != '.') {
338*7c478bd9Sstevel@tonic-gate 			file = found;
339*7c478bd9Sstevel@tonic-gate 			(void) fprintf(file, "%s\t%s\n", affix,
340*7c478bd9Sstevel@tonic-gate 			    original);
341*7c478bd9Sstevel@tonic-gate 		}
342*7c478bd9Sstevel@tonic-gate 	}
343*7c478bd9Sstevel@tonic-gate }
344*7c478bd9Sstevel@tonic-gate 
345*7c478bd9Sstevel@tonic-gate /*
346*7c478bd9Sstevel@tonic-gate  *	strip exactly one suffix and do
347*7c478bd9Sstevel@tonic-gate  *	indicated routine(s), which may recursively
348*7c478bd9Sstevel@tonic-gate  *	strip suffixes
349*7c478bd9Sstevel@tonic-gate  */
350*7c478bd9Sstevel@tonic-gate 
351*7c478bd9Sstevel@tonic-gate static int
352*7c478bd9Sstevel@tonic-gate trysuff(char *ep, int lev)
353*7c478bd9Sstevel@tonic-gate {
354*7c478bd9Sstevel@tonic-gate 	register struct suftab	*t;
355*7c478bd9Sstevel@tonic-gate 	register char *cp, *sp;
356*7c478bd9Sstevel@tonic-gate 
357*7c478bd9Sstevel@tonic-gate 	lev += DLEV;
358*7c478bd9Sstevel@tonic-gate 	deriv[lev] = deriv[lev-1] = 0;
359*7c478bd9Sstevel@tonic-gate 	for (t = &suftab[0]; (sp = t->suf) != 0; t++) {
360*7c478bd9Sstevel@tonic-gate 		cp = ep;
361*7c478bd9Sstevel@tonic-gate 		while (*sp)
362*7c478bd9Sstevel@tonic-gate 			if (*--cp != *sp++)
363*7c478bd9Sstevel@tonic-gate 				goto next;
364*7c478bd9Sstevel@tonic-gate 		for (sp = cp; --sp >= word && !vowel(*sp); );
365*7c478bd9Sstevel@tonic-gate 		if (sp < word)
366*7c478bd9Sstevel@tonic-gate 			return (0);
367*7c478bd9Sstevel@tonic-gate 		if ((*t->p1)(ep-t->n1, t->d1, t->a1, lev+1))
368*7c478bd9Sstevel@tonic-gate 			return (1);
369*7c478bd9Sstevel@tonic-gate 		if (t->p2 != 0) {
370*7c478bd9Sstevel@tonic-gate 			deriv[lev] = deriv[lev+1] = 0;
371*7c478bd9Sstevel@tonic-gate 			return ((*t->p2)(ep-t->n2, t->d2, t->a2, lev));
372*7c478bd9Sstevel@tonic-gate 		}
373*7c478bd9Sstevel@tonic-gate 		return (0);
374*7c478bd9Sstevel@tonic-gate next:;
375*7c478bd9Sstevel@tonic-gate 	}
376*7c478bd9Sstevel@tonic-gate 	return (0);
377*7c478bd9Sstevel@tonic-gate }
378*7c478bd9Sstevel@tonic-gate 
379*7c478bd9Sstevel@tonic-gate static int
380*7c478bd9Sstevel@tonic-gate nop(void)
381*7c478bd9Sstevel@tonic-gate {
382*7c478bd9Sstevel@tonic-gate 	return (0);
383*7c478bd9Sstevel@tonic-gate }
384*7c478bd9Sstevel@tonic-gate 
385*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
386*7c478bd9Sstevel@tonic-gate static int
387*7c478bd9Sstevel@tonic-gate strip(char *ep, char *d, char *a, int lev)
388*7c478bd9Sstevel@tonic-gate {
389*7c478bd9Sstevel@tonic-gate 	return (trypref(ep, a, lev)||trysuff(ep, lev));
390*7c478bd9Sstevel@tonic-gate }
391*7c478bd9Sstevel@tonic-gate 
392*7c478bd9Sstevel@tonic-gate static int
393*7c478bd9Sstevel@tonic-gate s(char *ep, char *d, char *a, int lev)
394*7c478bd9Sstevel@tonic-gate {
395*7c478bd9Sstevel@tonic-gate 	if (lev > DLEV+1)
396*7c478bd9Sstevel@tonic-gate 		return (0);
397*7c478bd9Sstevel@tonic-gate 	if (*ep == 's' && ep[-1] == 's')
398*7c478bd9Sstevel@tonic-gate 		return (0);
399*7c478bd9Sstevel@tonic-gate 	return (strip(ep, d, a, lev));
400*7c478bd9Sstevel@tonic-gate }
401*7c478bd9Sstevel@tonic-gate 
402*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
403*7c478bd9Sstevel@tonic-gate static int
404*7c478bd9Sstevel@tonic-gate an(char *ep, char *d, char *a, int lev)
405*7c478bd9Sstevel@tonic-gate {
406*7c478bd9Sstevel@tonic-gate 	if (!isupper(*word))	/* must be proper name */
407*7c478bd9Sstevel@tonic-gate 		return (0);
408*7c478bd9Sstevel@tonic-gate 	return (trypref(ep, a, lev));
409*7c478bd9Sstevel@tonic-gate }
410*7c478bd9Sstevel@tonic-gate 
411*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
412*7c478bd9Sstevel@tonic-gate static int
413*7c478bd9Sstevel@tonic-gate ize(char *ep, char *d, char *a, int lev)
414*7c478bd9Sstevel@tonic-gate {
415*7c478bd9Sstevel@tonic-gate 	ep[-1] = 'e';
416*7c478bd9Sstevel@tonic-gate 	return (strip(ep, "", d, lev));
417*7c478bd9Sstevel@tonic-gate }
418*7c478bd9Sstevel@tonic-gate 
419*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
420*7c478bd9Sstevel@tonic-gate static int
421*7c478bd9Sstevel@tonic-gate y_to_e(char *ep, char *d, char *a, int lev)
422*7c478bd9Sstevel@tonic-gate {
423*7c478bd9Sstevel@tonic-gate 	*ep++ = 'e';
424*7c478bd9Sstevel@tonic-gate 	return (strip(ep, "", d, lev));
425*7c478bd9Sstevel@tonic-gate }
426*7c478bd9Sstevel@tonic-gate 
427*7c478bd9Sstevel@tonic-gate static int
428*7c478bd9Sstevel@tonic-gate ily(char *ep, char *d, char *a, int lev)
429*7c478bd9Sstevel@tonic-gate {
430*7c478bd9Sstevel@tonic-gate 	if (ep[-1] == 'i')
431*7c478bd9Sstevel@tonic-gate 		return (i_to_y(ep, d, a, lev));
432*7c478bd9Sstevel@tonic-gate 	else
433*7c478bd9Sstevel@tonic-gate 		return (strip(ep, d, a, lev));
434*7c478bd9Sstevel@tonic-gate }
435*7c478bd9Sstevel@tonic-gate 
436*7c478bd9Sstevel@tonic-gate static int
437*7c478bd9Sstevel@tonic-gate bility(char *ep, char *d, char *a, int lev)
438*7c478bd9Sstevel@tonic-gate {
439*7c478bd9Sstevel@tonic-gate 	*ep++ = 'l';
440*7c478bd9Sstevel@tonic-gate 	return (y_to_e(ep, d, a, lev));
441*7c478bd9Sstevel@tonic-gate }
442*7c478bd9Sstevel@tonic-gate 
443*7c478bd9Sstevel@tonic-gate static int
444*7c478bd9Sstevel@tonic-gate i_to_y(char *ep, char *d, char *a, int lev)
445*7c478bd9Sstevel@tonic-gate {
446*7c478bd9Sstevel@tonic-gate 	if (ep[-1] == 'i') {
447*7c478bd9Sstevel@tonic-gate 		ep[-1] = 'y';
448*7c478bd9Sstevel@tonic-gate 		a = d;
449*7c478bd9Sstevel@tonic-gate 	}
450*7c478bd9Sstevel@tonic-gate 	return (strip(ep, "", a, lev));
451*7c478bd9Sstevel@tonic-gate }
452*7c478bd9Sstevel@tonic-gate 
453*7c478bd9Sstevel@tonic-gate static int
454*7c478bd9Sstevel@tonic-gate es(char *ep, char *d, char *a, int lev)
455*7c478bd9Sstevel@tonic-gate {
456*7c478bd9Sstevel@tonic-gate 	if (lev > DLEV)
457*7c478bd9Sstevel@tonic-gate 		return (0);
458*7c478bd9Sstevel@tonic-gate 	switch (ep[-1]) {
459*7c478bd9Sstevel@tonic-gate 	default:
460*7c478bd9Sstevel@tonic-gate 		return (0);
461*7c478bd9Sstevel@tonic-gate 	case 'i':
462*7c478bd9Sstevel@tonic-gate 		return (i_to_y(ep, d, a, lev));
463*7c478bd9Sstevel@tonic-gate 	case 's':
464*7c478bd9Sstevel@tonic-gate 	case 'h':
465*7c478bd9Sstevel@tonic-gate 	case 'z':
466*7c478bd9Sstevel@tonic-gate 	case 'x':
467*7c478bd9Sstevel@tonic-gate 		return (strip(ep, d, a, lev));
468*7c478bd9Sstevel@tonic-gate 	}
469*7c478bd9Sstevel@tonic-gate }
470*7c478bd9Sstevel@tonic-gate 
471*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
472*7c478bd9Sstevel@tonic-gate static int
473*7c478bd9Sstevel@tonic-gate subst(char *ep, char *d, char *a, int lev)
474*7c478bd9Sstevel@tonic-gate {
475*7c478bd9Sstevel@tonic-gate 	char *u, *t;
476*7c478bd9Sstevel@tonic-gate 
477*7c478bd9Sstevel@tonic-gate 	if (skipv(skipv(ep-1)) < word)
478*7c478bd9Sstevel@tonic-gate 		return (0);
479*7c478bd9Sstevel@tonic-gate 	for (t = d; *t != '+'; t++)
480*7c478bd9Sstevel@tonic-gate 		continue;
481*7c478bd9Sstevel@tonic-gate 	for (u = ep; *--t != '-'; )
482*7c478bd9Sstevel@tonic-gate 		*--u = *t;
483*7c478bd9Sstevel@tonic-gate 	return (strip(ep, "", d, lev));
484*7c478bd9Sstevel@tonic-gate }
485*7c478bd9Sstevel@tonic-gate 
486*7c478bd9Sstevel@tonic-gate 
487*7c478bd9Sstevel@tonic-gate static int
488*7c478bd9Sstevel@tonic-gate tion(char *ep, char *d, char *a, int lev)
489*7c478bd9Sstevel@tonic-gate {
490*7c478bd9Sstevel@tonic-gate 	switch (ep[-2]) {
491*7c478bd9Sstevel@tonic-gate 	case 'c':
492*7c478bd9Sstevel@tonic-gate 	case 'r':
493*7c478bd9Sstevel@tonic-gate 		return (trypref(ep, a, lev));
494*7c478bd9Sstevel@tonic-gate 	case 'a':
495*7c478bd9Sstevel@tonic-gate 		return (y_to_e(ep, d, a, lev));
496*7c478bd9Sstevel@tonic-gate 	}
497*7c478bd9Sstevel@tonic-gate 	return (0);
498*7c478bd9Sstevel@tonic-gate }
499*7c478bd9Sstevel@tonic-gate 
500*7c478bd9Sstevel@tonic-gate /*	possible consonant-consonant-e ending */
501*7c478bd9Sstevel@tonic-gate static int
502*7c478bd9Sstevel@tonic-gate CCe(char *ep, char *d, char *a, int lev)
503*7c478bd9Sstevel@tonic-gate {
504*7c478bd9Sstevel@tonic-gate 	switch (ep[-1]) {
505*7c478bd9Sstevel@tonic-gate 	case 'r':
506*7c478bd9Sstevel@tonic-gate 		if (ep[-2] == 't')
507*7c478bd9Sstevel@tonic-gate 			return (y_to_e(ep, d, a, lev));
508*7c478bd9Sstevel@tonic-gate 		break;
509*7c478bd9Sstevel@tonic-gate 	case 'l':
510*7c478bd9Sstevel@tonic-gate 		if (vowel(ep[-2]))
511*7c478bd9Sstevel@tonic-gate 			break;
512*7c478bd9Sstevel@tonic-gate 		switch (ep[-2]) {
513*7c478bd9Sstevel@tonic-gate 		case 'l':
514*7c478bd9Sstevel@tonic-gate 		case 'r':
515*7c478bd9Sstevel@tonic-gate 		case 'w':
516*7c478bd9Sstevel@tonic-gate 			break;
517*7c478bd9Sstevel@tonic-gate 		default:
518*7c478bd9Sstevel@tonic-gate 			return (y_to_e(ep, d, a, lev));
519*7c478bd9Sstevel@tonic-gate 		}
520*7c478bd9Sstevel@tonic-gate 		break;
521*7c478bd9Sstevel@tonic-gate 	case 's':
522*7c478bd9Sstevel@tonic-gate 		if (ep[-2] == 's')
523*7c478bd9Sstevel@tonic-gate 			break;
524*7c478bd9Sstevel@tonic-gate 		if (*ep == 'a')
525*7c478bd9Sstevel@tonic-gate 			return (0);
526*7c478bd9Sstevel@tonic-gate 		if (vowel(ep[-2]))
527*7c478bd9Sstevel@tonic-gate 			break;
528*7c478bd9Sstevel@tonic-gate 		if (y_to_e(ep, d, a, lev))
529*7c478bd9Sstevel@tonic-gate 			return (1);
530*7c478bd9Sstevel@tonic-gate 		if (!(ep[-2] == 'n' && ep[-1] == 'g'))
531*7c478bd9Sstevel@tonic-gate 			return (0);
532*7c478bd9Sstevel@tonic-gate 		break;
533*7c478bd9Sstevel@tonic-gate 	case 'c':
534*7c478bd9Sstevel@tonic-gate 	case 'g':
535*7c478bd9Sstevel@tonic-gate 		if (*ep == 'a')
536*7c478bd9Sstevel@tonic-gate 			return (0);
537*7c478bd9Sstevel@tonic-gate 		if (vowel(ep[-2]))
538*7c478bd9Sstevel@tonic-gate 			break;
539*7c478bd9Sstevel@tonic-gate 		if (y_to_e(ep, d, a, lev))
540*7c478bd9Sstevel@tonic-gate 			return (1);
541*7c478bd9Sstevel@tonic-gate 		if (!(ep[-2] == 'n' && ep[-1] == 'g'))
542*7c478bd9Sstevel@tonic-gate 			return (0);
543*7c478bd9Sstevel@tonic-gate 		break;
544*7c478bd9Sstevel@tonic-gate 	case 'v':
545*7c478bd9Sstevel@tonic-gate 	case 'z':
546*7c478bd9Sstevel@tonic-gate 		if (vowel(ep[-2]))
547*7c478bd9Sstevel@tonic-gate 			break;
548*7c478bd9Sstevel@tonic-gate 		if (y_to_e(ep, d, a, lev))
549*7c478bd9Sstevel@tonic-gate 			return (1);
550*7c478bd9Sstevel@tonic-gate 		if (!(ep[-2] == 'n' && ep[-1] == 'g'))
551*7c478bd9Sstevel@tonic-gate 			return (0);
552*7c478bd9Sstevel@tonic-gate 		break;
553*7c478bd9Sstevel@tonic-gate 	case 'u':
554*7c478bd9Sstevel@tonic-gate 		if (y_to_e(ep, d, a, lev))
555*7c478bd9Sstevel@tonic-gate 			return (1);
556*7c478bd9Sstevel@tonic-gate 		if (!(ep[-2] == 'n' && ep[-1] == 'g'))
557*7c478bd9Sstevel@tonic-gate 			return (0);
558*7c478bd9Sstevel@tonic-gate 		break;
559*7c478bd9Sstevel@tonic-gate 	}
560*7c478bd9Sstevel@tonic-gate 	return (VCe(ep, d, a, lev));
561*7c478bd9Sstevel@tonic-gate }
562*7c478bd9Sstevel@tonic-gate 
563*7c478bd9Sstevel@tonic-gate /*	possible consonant-vowel-consonant-e ending */
564*7c478bd9Sstevel@tonic-gate static int
565*7c478bd9Sstevel@tonic-gate VCe(char *ep, char *d, char *a, int lev)
566*7c478bd9Sstevel@tonic-gate {
567*7c478bd9Sstevel@tonic-gate 	char c;
568*7c478bd9Sstevel@tonic-gate 	c = ep[-1];
569*7c478bd9Sstevel@tonic-gate 	if (c == 'e')
570*7c478bd9Sstevel@tonic-gate 		return (0);
571*7c478bd9Sstevel@tonic-gate 	if (!vowel(c) && vowel(ep[-2])) {
572*7c478bd9Sstevel@tonic-gate 		c = *ep;
573*7c478bd9Sstevel@tonic-gate 		*ep++ = 'e';
574*7c478bd9Sstevel@tonic-gate 		if (trypref(ep, d, lev)||trysuff(ep, lev))
575*7c478bd9Sstevel@tonic-gate 			return (1);
576*7c478bd9Sstevel@tonic-gate 		ep--;
577*7c478bd9Sstevel@tonic-gate 		*ep = c;
578*7c478bd9Sstevel@tonic-gate 	}
579*7c478bd9Sstevel@tonic-gate 	return (strip(ep, d, a, lev));
580*7c478bd9Sstevel@tonic-gate }
581*7c478bd9Sstevel@tonic-gate 
582*7c478bd9Sstevel@tonic-gate static char *
583*7c478bd9Sstevel@tonic-gate lookuppref(char **wp, char *ep)
584*7c478bd9Sstevel@tonic-gate {
585*7c478bd9Sstevel@tonic-gate 	register char **sp;
586*7c478bd9Sstevel@tonic-gate 	register char *bp, *cp;
587*7c478bd9Sstevel@tonic-gate 
588*7c478bd9Sstevel@tonic-gate 	for (sp = preftab; *sp; sp++) {
589*7c478bd9Sstevel@tonic-gate 		bp = *wp;
590*7c478bd9Sstevel@tonic-gate 		for (cp = *sp; *cp; cp++, bp++)
591*7c478bd9Sstevel@tonic-gate 			if (Tolower(*bp) != *cp)
592*7c478bd9Sstevel@tonic-gate 				goto next;
593*7c478bd9Sstevel@tonic-gate 		for (cp = bp; cp < ep; cp++)
594*7c478bd9Sstevel@tonic-gate 			if (vowel(*cp)) {
595*7c478bd9Sstevel@tonic-gate 				*wp = bp;
596*7c478bd9Sstevel@tonic-gate 				return (*sp);
597*7c478bd9Sstevel@tonic-gate 			}
598*7c478bd9Sstevel@tonic-gate next:;
599*7c478bd9Sstevel@tonic-gate 	}
600*7c478bd9Sstevel@tonic-gate 	return (0);
601*7c478bd9Sstevel@tonic-gate }
602*7c478bd9Sstevel@tonic-gate 
603*7c478bd9Sstevel@tonic-gate /*
604*7c478bd9Sstevel@tonic-gate  *	while word is not in dictionary try stripping
605*7c478bd9Sstevel@tonic-gate  *	prefixes. Fail if no more prefixes.
606*7c478bd9Sstevel@tonic-gate  */
607*7c478bd9Sstevel@tonic-gate static int
608*7c478bd9Sstevel@tonic-gate trypref(char *ep, char *a, int lev)
609*7c478bd9Sstevel@tonic-gate {
610*7c478bd9Sstevel@tonic-gate 	register char *cp;
611*7c478bd9Sstevel@tonic-gate 	char *bp;
612*7c478bd9Sstevel@tonic-gate 	register char *pp;
613*7c478bd9Sstevel@tonic-gate 	int val = 0;
614*7c478bd9Sstevel@tonic-gate 	char space[LINE_MAX * 2];
615*7c478bd9Sstevel@tonic-gate 	deriv[lev] = a;
616*7c478bd9Sstevel@tonic-gate 	if (tryword(word, ep, lev))
617*7c478bd9Sstevel@tonic-gate 		return (1);
618*7c478bd9Sstevel@tonic-gate 	bp = word;
619*7c478bd9Sstevel@tonic-gate 	pp = space;
620*7c478bd9Sstevel@tonic-gate 	deriv[lev+1] = pp;
621*7c478bd9Sstevel@tonic-gate 	while (cp = lookuppref(&bp, ep)) {
622*7c478bd9Sstevel@tonic-gate 		*pp++ = '+';
623*7c478bd9Sstevel@tonic-gate 		while (*pp = *cp++)
624*7c478bd9Sstevel@tonic-gate 			pp++;
625*7c478bd9Sstevel@tonic-gate 		if (tryword(bp, ep, lev+1)) {
626*7c478bd9Sstevel@tonic-gate 			val = 1;
627*7c478bd9Sstevel@tonic-gate 			break;
628*7c478bd9Sstevel@tonic-gate 		}
629*7c478bd9Sstevel@tonic-gate 	}
630*7c478bd9Sstevel@tonic-gate 	deriv[lev+1] = deriv[lev+2] = 0;
631*7c478bd9Sstevel@tonic-gate 	return (val);
632*7c478bd9Sstevel@tonic-gate }
633*7c478bd9Sstevel@tonic-gate 
634*7c478bd9Sstevel@tonic-gate static int
635*7c478bd9Sstevel@tonic-gate tryword(char *bp, char *ep, int lev)
636*7c478bd9Sstevel@tonic-gate {
637*7c478bd9Sstevel@tonic-gate 	register i, j;
638*7c478bd9Sstevel@tonic-gate 	char duple[3];
639*7c478bd9Sstevel@tonic-gate 	if (ep-bp <= 1)
640*7c478bd9Sstevel@tonic-gate 		return (0);
641*7c478bd9Sstevel@tonic-gate 	if (vowel(*ep)) {
642*7c478bd9Sstevel@tonic-gate 		if (monosyl(bp, ep))
643*7c478bd9Sstevel@tonic-gate 			return (0);
644*7c478bd9Sstevel@tonic-gate 	}
645*7c478bd9Sstevel@tonic-gate 	i = dict(bp, ep);
646*7c478bd9Sstevel@tonic-gate 	if (i == 0 && vowel(*ep) && ep[-1] == ep[-2] && monosyl(bp, ep-1)) {
647*7c478bd9Sstevel@tonic-gate 		ep--;
648*7c478bd9Sstevel@tonic-gate 		deriv[++lev] = duple;
649*7c478bd9Sstevel@tonic-gate 		duple[0] = '+';
650*7c478bd9Sstevel@tonic-gate 		duple[1] = *ep;
651*7c478bd9Sstevel@tonic-gate 		duple[2] = 0;
652*7c478bd9Sstevel@tonic-gate 		i = dict(bp, ep);
653*7c478bd9Sstevel@tonic-gate 	}
654*7c478bd9Sstevel@tonic-gate 	if (vflag == 0 || i == 0)
655*7c478bd9Sstevel@tonic-gate 		return (i);
656*7c478bd9Sstevel@tonic-gate 	/*
657*7c478bd9Sstevel@tonic-gate 	 *	when derivations are wanted, collect them
658*7c478bd9Sstevel@tonic-gate 	 *	for printing
659*7c478bd9Sstevel@tonic-gate 	 */
660*7c478bd9Sstevel@tonic-gate 	j = lev;
661*7c478bd9Sstevel@tonic-gate 	do {
662*7c478bd9Sstevel@tonic-gate 		if (deriv[j])
663*7c478bd9Sstevel@tonic-gate 			(void) strcat(affix, deriv[j]);
664*7c478bd9Sstevel@tonic-gate 	} while (--j > 0);
665*7c478bd9Sstevel@tonic-gate 	return (i);
666*7c478bd9Sstevel@tonic-gate }
667*7c478bd9Sstevel@tonic-gate 
668*7c478bd9Sstevel@tonic-gate 
669*7c478bd9Sstevel@tonic-gate static int
670*7c478bd9Sstevel@tonic-gate monosyl(char *bp, char *ep)
671*7c478bd9Sstevel@tonic-gate {
672*7c478bd9Sstevel@tonic-gate 	if (ep < bp+2)
673*7c478bd9Sstevel@tonic-gate 		return (0);
674*7c478bd9Sstevel@tonic-gate 	if (vowel(*--ep) || !vowel(*--ep) || ep[1] == 'x' || ep[1] == 'w')
675*7c478bd9Sstevel@tonic-gate 		return (0);
676*7c478bd9Sstevel@tonic-gate 	while (--ep >= bp)
677*7c478bd9Sstevel@tonic-gate 		if (vowel(*ep))
678*7c478bd9Sstevel@tonic-gate 			return (0);
679*7c478bd9Sstevel@tonic-gate 	return (1);
680*7c478bd9Sstevel@tonic-gate }
681*7c478bd9Sstevel@tonic-gate 
682*7c478bd9Sstevel@tonic-gate static char *
683*7c478bd9Sstevel@tonic-gate skipv(char *s)
684*7c478bd9Sstevel@tonic-gate {
685*7c478bd9Sstevel@tonic-gate 	if (s >= word&&vowel(*s))
686*7c478bd9Sstevel@tonic-gate 		s--;
687*7c478bd9Sstevel@tonic-gate 	while (s >= word && !vowel(*s))
688*7c478bd9Sstevel@tonic-gate 		s--;
689*7c478bd9Sstevel@tonic-gate 	return (s);
690*7c478bd9Sstevel@tonic-gate }
691*7c478bd9Sstevel@tonic-gate 
692*7c478bd9Sstevel@tonic-gate static int
693*7c478bd9Sstevel@tonic-gate vowel(int c)
694*7c478bd9Sstevel@tonic-gate {
695*7c478bd9Sstevel@tonic-gate 	switch (Tolower(c)) {
696*7c478bd9Sstevel@tonic-gate 	case 'a':
697*7c478bd9Sstevel@tonic-gate 	case 'e':
698*7c478bd9Sstevel@tonic-gate 	case 'i':
699*7c478bd9Sstevel@tonic-gate 	case 'o':
700*7c478bd9Sstevel@tonic-gate 	case 'u':
701*7c478bd9Sstevel@tonic-gate 	case 'y':
702*7c478bd9Sstevel@tonic-gate 		return (1);
703*7c478bd9Sstevel@tonic-gate 	}
704*7c478bd9Sstevel@tonic-gate 	return (0);
705*7c478bd9Sstevel@tonic-gate }
706*7c478bd9Sstevel@tonic-gate 
707*7c478bd9Sstevel@tonic-gate /* crummy way to Britishise */
708*7c478bd9Sstevel@tonic-gate static void
709*7c478bd9Sstevel@tonic-gate ise(void)
710*7c478bd9Sstevel@tonic-gate {
711*7c478bd9Sstevel@tonic-gate 	register struct suftab *p;
712*7c478bd9Sstevel@tonic-gate 
713*7c478bd9Sstevel@tonic-gate 	for (p = suftab; p->suf; p++) {
714*7c478bd9Sstevel@tonic-gate 		ztos(p->suf);
715*7c478bd9Sstevel@tonic-gate 		ztos(p->d1);
716*7c478bd9Sstevel@tonic-gate 		ztos(p->a1);
717*7c478bd9Sstevel@tonic-gate 	}
718*7c478bd9Sstevel@tonic-gate }
719*7c478bd9Sstevel@tonic-gate 
720*7c478bd9Sstevel@tonic-gate static void
721*7c478bd9Sstevel@tonic-gate ztos(char *s)
722*7c478bd9Sstevel@tonic-gate {
723*7c478bd9Sstevel@tonic-gate 	for (; *s; s++)
724*7c478bd9Sstevel@tonic-gate 		if (*s == 'z')
725*7c478bd9Sstevel@tonic-gate 			*s = 's';
726*7c478bd9Sstevel@tonic-gate }
727*7c478bd9Sstevel@tonic-gate 
728*7c478bd9Sstevel@tonic-gate static int
729*7c478bd9Sstevel@tonic-gate dict(char *bp, char *ep)
730*7c478bd9Sstevel@tonic-gate {
731*7c478bd9Sstevel@tonic-gate 	register temp, result;
732*7c478bd9Sstevel@tonic-gate 	if (xflag)
733*7c478bd9Sstevel@tonic-gate 		(void) fprintf(stdout, "=%.*s\n", ep-bp, bp);
734*7c478bd9Sstevel@tonic-gate 	temp = *ep;
735*7c478bd9Sstevel@tonic-gate 	*ep = 0;
736*7c478bd9Sstevel@tonic-gate 	result = hashlook(bp);
737*7c478bd9Sstevel@tonic-gate 	*ep = temp;
738*7c478bd9Sstevel@tonic-gate 	return (result);
739*7c478bd9Sstevel@tonic-gate }
740