xref: /illumos-gate/usr/src/cmd/spell/spellprog.c (revision 17723245)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
23*17723245SGary Mills  * Copyright 2015 Gary Mills
240d8b5334Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
257c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
280d8b5334Sceastha /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
290d8b5334Sceastha /*	  All Rights Reserved  	*/
300d8b5334Sceastha 
317c478bd9Sstevel@tonic-gate #include <stdlib.h>
327c478bd9Sstevel@tonic-gate #include <unistd.h>
337c478bd9Sstevel@tonic-gate #include <limits.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate #include <stdio.h>
367c478bd9Sstevel@tonic-gate #include <ctype.h>
377c478bd9Sstevel@tonic-gate #include <locale.h>
387c478bd9Sstevel@tonic-gate #include "hash.h"
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #define	Tolower(c) (isupper(c)?tolower(c):c)
417c478bd9Sstevel@tonic-gate #define	DLEV 2
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /*
447c478bd9Sstevel@tonic-gate  * ANSI prototypes
457c478bd9Sstevel@tonic-gate  */
467c478bd9Sstevel@tonic-gate static int	ily(char *, char *, char *, int);
477c478bd9Sstevel@tonic-gate static int	s(char *, char *, char *, int);
487c478bd9Sstevel@tonic-gate static int	es(char *, char *, char *, int);
497c478bd9Sstevel@tonic-gate static int	subst(char *, char *, char *, int);
507c478bd9Sstevel@tonic-gate static int	nop(void);
517c478bd9Sstevel@tonic-gate static int	bility(char *, char *, char *, int);
527c478bd9Sstevel@tonic-gate static int	i_to_y(char *, char *, char *, int);
537c478bd9Sstevel@tonic-gate static int	CCe(char *, char *, char *, int);
547c478bd9Sstevel@tonic-gate static int	y_to_e(char *, char *, char *, int);
557c478bd9Sstevel@tonic-gate static int	strip(char *, char *, char *, int);
567c478bd9Sstevel@tonic-gate static int	ize(char *, char *, char *, int);
577c478bd9Sstevel@tonic-gate static int	tion(char *, char *, char *, int);
587c478bd9Sstevel@tonic-gate static int	an(char *, char *, char *, int);
597c478bd9Sstevel@tonic-gate int		prime(char *);
607c478bd9Sstevel@tonic-gate static int	tryword(char *, char *, int);
617c478bd9Sstevel@tonic-gate static int	trypref(char *, char *, int);
627c478bd9Sstevel@tonic-gate static int	trysuff(char *, int);
637c478bd9Sstevel@tonic-gate static int	vowel(int);
647c478bd9Sstevel@tonic-gate static int	dict(char *, char *);
657c478bd9Sstevel@tonic-gate static int	monosyl(char *, char *);
667c478bd9Sstevel@tonic-gate static int	VCe(char *, char *, char *, int);
677c478bd9Sstevel@tonic-gate static char	*skipv(char *);
687c478bd9Sstevel@tonic-gate 
69*17723245SGary Mills struct suftab {
707c478bd9Sstevel@tonic-gate 	char *suf;
717c478bd9Sstevel@tonic-gate 	int (*p1)();
727c478bd9Sstevel@tonic-gate 	int n1;
737c478bd9Sstevel@tonic-gate 	char *d1;
747c478bd9Sstevel@tonic-gate 	char *a1;
757c478bd9Sstevel@tonic-gate 	int (*p2)();
767c478bd9Sstevel@tonic-gate 	int n2;
777c478bd9Sstevel@tonic-gate 	char *d2;
787c478bd9Sstevel@tonic-gate 	char *a2;
79*17723245SGary Mills };
80*17723245SGary Mills 
81*17723245SGary Mills static struct suftab sufa[] = {
827c478bd9Sstevel@tonic-gate 	{"ssen", ily, 4, "-y+iness", "+ness" },
837c478bd9Sstevel@tonic-gate 	{"ssel", ily, 4, "-y+i+less", "+less" },
847c478bd9Sstevel@tonic-gate 	{"se", s, 1, "", "+s", 	es, 2, "-y+ies", "+es" },
857c478bd9Sstevel@tonic-gate 	{"s'", s, 2, "", "+'s"},
867c478bd9Sstevel@tonic-gate 	{"s", s, 1, "", "+s"},
877c478bd9Sstevel@tonic-gate 	{"ecn", subst, 1, "-t+ce", ""},
887c478bd9Sstevel@tonic-gate 	{"ycn", subst, 1, "-t+cy", ""},
897c478bd9Sstevel@tonic-gate 	{"ytilb", nop, 0, "", ""},
907c478bd9Sstevel@tonic-gate 	{"ytilib", bility, 5, "-le+ility", ""},
917c478bd9Sstevel@tonic-gate 	{"elbaif", i_to_y, 4, "-y+iable", ""},
927c478bd9Sstevel@tonic-gate 	{"elba", CCe, 4, "-e+able", "+able"},
937c478bd9Sstevel@tonic-gate 	{"yti", CCe, 3, "-e+ity", "+ity"},
947c478bd9Sstevel@tonic-gate 	{"ylb", y_to_e, 1, "-e+y", ""},
957c478bd9Sstevel@tonic-gate 	{"yl", ily, 2, "-y+ily", "+ly"},
967c478bd9Sstevel@tonic-gate 	{"laci", strip, 2, "", "+al"},
977c478bd9Sstevel@tonic-gate 	{"latnem", strip, 2, "", "+al"},
987c478bd9Sstevel@tonic-gate 	{"lanoi", strip, 2, "", "+al"},
997c478bd9Sstevel@tonic-gate 	{"tnem", strip, 4, "", "+ment"},
1007c478bd9Sstevel@tonic-gate 	{"gni", CCe, 3, "-e+ing", "+ing"},
1017c478bd9Sstevel@tonic-gate 	{"reta", nop, 0, "", ""},
1027c478bd9Sstevel@tonic-gate 	{"retc", nop, 0, "", ""},
1037c478bd9Sstevel@tonic-gate 	{"re", strip, 1, "", "+r", i_to_y, 2, "-y+ier", "+er"},
1047c478bd9Sstevel@tonic-gate 	{"de", strip, 1, "", "+d", i_to_y, 2, "-y+ied", "+ed"},
1057c478bd9Sstevel@tonic-gate 	{"citsi", strip, 2, "", "+ic"},
1067c478bd9Sstevel@tonic-gate 	{"citi", ize, 1, "-ic+e", ""},
1077c478bd9Sstevel@tonic-gate 	{"cihparg", i_to_y, 1, "-y+ic", ""},
1087c478bd9Sstevel@tonic-gate 	{"tse", strip, 2, "", "+st", 	i_to_y, 3, "-y+iest", "+est"},
1097c478bd9Sstevel@tonic-gate 	{"cirtem", i_to_y, 1, "-y+ic", ""},
1107c478bd9Sstevel@tonic-gate 	{"yrtem", subst, 0, "-er+ry", ""},
1117c478bd9Sstevel@tonic-gate 	{"cigol", i_to_y, 1, "-y+ic", ""},
1127c478bd9Sstevel@tonic-gate 	{"tsigol", i_to_y, 2, "-y+ist", ""},
1137c478bd9Sstevel@tonic-gate 	{"tsi", CCe, 3, "-e+ist", "+ist"},
1147c478bd9Sstevel@tonic-gate 	{"msi", CCe, 3, "-e+ism", "+ist"},
1157c478bd9Sstevel@tonic-gate 	{"noitacifi", i_to_y, 6, "-y+ication", ""},
1167c478bd9Sstevel@tonic-gate 	{"noitazi", ize, 4, "-e+ation", ""},
1177c478bd9Sstevel@tonic-gate 	{"rota", tion, 2, "-e+or", ""},
1187c478bd9Sstevel@tonic-gate 	{"rotc", tion, 2, "", "+or"},
1197c478bd9Sstevel@tonic-gate 	{"noit", tion, 3, "-e+ion", "+ion"},
1207c478bd9Sstevel@tonic-gate 	{"naino", an, 3, "", "+ian"},
1217c478bd9Sstevel@tonic-gate 	{"na", an, 1, "", "+n"},
1227c478bd9Sstevel@tonic-gate 	{"evi", subst, 0, "-ion+ive", ""},
1237c478bd9Sstevel@tonic-gate 	{"ezi", CCe, 3, "-e+ize", "+ize"},
1247c478bd9Sstevel@tonic-gate 	{"pihs", strip, 4, "", "+ship"},
1257c478bd9Sstevel@tonic-gate 	{"dooh", ily, 4, "-y+ihood", "+hood"},
1267c478bd9Sstevel@tonic-gate 	{"luf", ily, 3, "-y+iful", "+ful"},
1277c478bd9Sstevel@tonic-gate 	{"ekil", strip, 4, "", "+like"},
1287c478bd9Sstevel@tonic-gate 	0
1297c478bd9Sstevel@tonic-gate };
1307c478bd9Sstevel@tonic-gate 
131*17723245SGary Mills static struct suftab sufb[] = {
132*17723245SGary Mills 	{"ssen", ily, 4, "-y+iness", "+ness" },
133*17723245SGary Mills 	{"ssel", ily, 4, "-y+i+less", "+less" },
134*17723245SGary Mills 	{"se", s, 1, "", "+s", 	es, 2, "-y+ies", "+es" },
135*17723245SGary Mills 	{"s'", s, 2, "", "+'s"},
136*17723245SGary Mills 	{"s", s, 1, "", "+s"},
137*17723245SGary Mills 	{"ecn", subst, 1, "-t+ce", ""},
138*17723245SGary Mills 	{"ycn", subst, 1, "-t+cy", ""},
139*17723245SGary Mills 	{"ytilb", nop, 0, "", ""},
140*17723245SGary Mills 	{"ytilib", bility, 5, "-le+ility", ""},
141*17723245SGary Mills 	{"elbaif", i_to_y, 4, "-y+iable", ""},
142*17723245SGary Mills 	{"elba", CCe, 4, "-e+able", "+able"},
143*17723245SGary Mills 	{"yti", CCe, 3, "-e+ity", "+ity"},
144*17723245SGary Mills 	{"ylb", y_to_e, 1, "-e+y", ""},
145*17723245SGary Mills 	{"yl", ily, 2, "-y+ily", "+ly"},
146*17723245SGary Mills 	{"laci", strip, 2, "", "+al"},
147*17723245SGary Mills 	{"latnem", strip, 2, "", "+al"},
148*17723245SGary Mills 	{"lanoi", strip, 2, "", "+al"},
149*17723245SGary Mills 	{"tnem", strip, 4, "", "+ment"},
150*17723245SGary Mills 	{"gni", CCe, 3, "-e+ing", "+ing"},
151*17723245SGary Mills 	{"reta", nop, 0, "", ""},
152*17723245SGary Mills 	{"retc", nop, 0, "", ""},
153*17723245SGary Mills 	{"re", strip, 1, "", "+r", i_to_y, 2, "-y+ier", "+er"},
154*17723245SGary Mills 	{"de", strip, 1, "", "+d", i_to_y, 2, "-y+ied", "+ed"},
155*17723245SGary Mills 	{"citsi", strip, 2, "", "+ic"},
156*17723245SGary Mills 	{"citi", ize, 1, "-ic+e", ""},
157*17723245SGary Mills 	{"cihparg", i_to_y, 1, "-y+ic", ""},
158*17723245SGary Mills 	{"tse", strip, 2, "", "+st", 	i_to_y, 3, "-y+iest", "+est"},
159*17723245SGary Mills 	{"cirtem", i_to_y, 1, "-y+ic", ""},
160*17723245SGary Mills 	{"yrtem", subst, 0, "-er+ry", ""},
161*17723245SGary Mills 	{"cigol", i_to_y, 1, "-y+ic", ""},
162*17723245SGary Mills 	{"tsigol", i_to_y, 2, "-y+ist", ""},
163*17723245SGary Mills 	{"tsi", CCe, 3, "-e+ist", "+ist"},
164*17723245SGary Mills 	{"msi", CCe, 3, "-e+ism", "+ist"},
165*17723245SGary Mills 	{"noitacifi", i_to_y, 6, "-y+ication", ""},
166*17723245SGary Mills 	{"noitasi", ize, 4, "-e+ation", ""},
167*17723245SGary Mills 	{"rota", tion, 2, "-e+or", ""},
168*17723245SGary Mills 	{"rotc", tion, 2, "", "+or"},
169*17723245SGary Mills 	{"noit", tion, 3, "-e+ion", "+ion"},
170*17723245SGary Mills 	{"naino", an, 3, "", "+ian"},
171*17723245SGary Mills 	{"na", an, 1, "", "+n"},
172*17723245SGary Mills 	{"evi", subst, 0, "-ion+ive", ""},
173*17723245SGary Mills 	{"esi", CCe, 3, "-e+ise", "+ise"},
174*17723245SGary Mills 	{"pihs", strip, 4, "", "+ship"},
175*17723245SGary Mills 	{"dooh", ily, 4, "-y+ihood", "+hood"},
176*17723245SGary Mills 	{"luf", ily, 3, "-y+iful", "+ful"},
177*17723245SGary Mills 	{"ekil", strip, 4, "", "+like"},
178*17723245SGary Mills 	0
179*17723245SGary Mills };
180*17723245SGary Mills 
1817c478bd9Sstevel@tonic-gate static char *preftab[] = {
1827c478bd9Sstevel@tonic-gate 	"anti",
1837c478bd9Sstevel@tonic-gate 	"auto",
1847c478bd9Sstevel@tonic-gate 	"bio",
1857c478bd9Sstevel@tonic-gate 	"counter",
1867c478bd9Sstevel@tonic-gate 	"dis",
1877c478bd9Sstevel@tonic-gate 	"electro",
1887c478bd9Sstevel@tonic-gate 	"en",
1897c478bd9Sstevel@tonic-gate 	"fore",
1907c478bd9Sstevel@tonic-gate 	"geo",
1917c478bd9Sstevel@tonic-gate 	"hyper",
1927c478bd9Sstevel@tonic-gate 	"intra",
1937c478bd9Sstevel@tonic-gate 	"inter",
1947c478bd9Sstevel@tonic-gate 	"iso",
1957c478bd9Sstevel@tonic-gate 	"kilo",
1967c478bd9Sstevel@tonic-gate 	"magneto",
1977c478bd9Sstevel@tonic-gate 	"meta",
1987c478bd9Sstevel@tonic-gate 	"micro",
1997c478bd9Sstevel@tonic-gate 	"mid",
2007c478bd9Sstevel@tonic-gate 	"milli",
2017c478bd9Sstevel@tonic-gate 	"mis",
2027c478bd9Sstevel@tonic-gate 	"mono",
2037c478bd9Sstevel@tonic-gate 	"multi",
2047c478bd9Sstevel@tonic-gate 	"non",
2057c478bd9Sstevel@tonic-gate 	"out",
2067c478bd9Sstevel@tonic-gate 	"over",
2077c478bd9Sstevel@tonic-gate 	"photo",
2087c478bd9Sstevel@tonic-gate 	"poly",
2097c478bd9Sstevel@tonic-gate 	"pre",
2107c478bd9Sstevel@tonic-gate 	"pseudo",
2117c478bd9Sstevel@tonic-gate 	"psycho",
2127c478bd9Sstevel@tonic-gate 	"re",
2137c478bd9Sstevel@tonic-gate 	"semi",
2147c478bd9Sstevel@tonic-gate 	"stereo",
2157c478bd9Sstevel@tonic-gate 	"sub",
2167c478bd9Sstevel@tonic-gate 	"super",
2177c478bd9Sstevel@tonic-gate 	"tele",
2187c478bd9Sstevel@tonic-gate 	"thermo",
2197c478bd9Sstevel@tonic-gate 	"ultra",
2207c478bd9Sstevel@tonic-gate 	"under",	/* must precede un */
2217c478bd9Sstevel@tonic-gate 	"un",
2227c478bd9Sstevel@tonic-gate 	0
2237c478bd9Sstevel@tonic-gate };
2247c478bd9Sstevel@tonic-gate 
225*17723245SGary Mills static int bflag;
2267c478bd9Sstevel@tonic-gate static int vflag;
2277c478bd9Sstevel@tonic-gate static int xflag;
228*17723245SGary Mills static struct suftab *suftab;
2297c478bd9Sstevel@tonic-gate static char *prog;
2307c478bd9Sstevel@tonic-gate static char word[LINE_MAX];
2317c478bd9Sstevel@tonic-gate static char original[LINE_MAX];
2327c478bd9Sstevel@tonic-gate static char *deriv[LINE_MAX];
2337c478bd9Sstevel@tonic-gate static char affix[LINE_MAX];
2347c478bd9Sstevel@tonic-gate static FILE *file, *found;
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate  *	deriv is stack of pointers to notes like +micro +ed
2377c478bd9Sstevel@tonic-gate  *	affix is concatenated string of notes
2387c478bd9Sstevel@tonic-gate  *	the buffer size 141 stems from the sizes of original and affix.
2397c478bd9Sstevel@tonic-gate  */
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate /*
2427c478bd9Sstevel@tonic-gate  *	in an attempt to defray future maintenance misunderstandings, here is
2437c478bd9Sstevel@tonic-gate  *	an attempt to describe the input/output expectations of the spell
2447c478bd9Sstevel@tonic-gate  *	program.
2457c478bd9Sstevel@tonic-gate  *
2467c478bd9Sstevel@tonic-gate  *	spellprog is intended to be called from the shell file spell.
2477c478bd9Sstevel@tonic-gate  *	because of this, there is little error checking (this is historical, not
2487c478bd9Sstevel@tonic-gate  *	necessarily advisable).
2497c478bd9Sstevel@tonic-gate  *
2507c478bd9Sstevel@tonic-gate  *	spellprog options hashed-list pass
2517c478bd9Sstevel@tonic-gate  *
2527c478bd9Sstevel@tonic-gate  *	the hashed-list is a list of the form made by spellin.
2537c478bd9Sstevel@tonic-gate  *	there are 2 types of hashed lists:
2547c478bd9Sstevel@tonic-gate  *		1. a stop list: this specifies words that by the rules embodied
2557c478bd9Sstevel@tonic-gate  *		   in spellprog would be recognized as correct, BUT are really
2567c478bd9Sstevel@tonic-gate  *		   errors.
2577c478bd9Sstevel@tonic-gate  *		2. a dictionary of correctly spelled words.
2587c478bd9Sstevel@tonic-gate  *	the pass number determines how the words found in the specified
2597c478bd9Sstevel@tonic-gate  *	hashed-list are treated. If the pass number is 1, the hashed-list is
2607c478bd9Sstevel@tonic-gate  *	treated as the stop-list, otherwise, it is treated as the regular
2617c478bd9Sstevel@tonic-gate  *	dictionary list. in this case, the value of "pass" is a filename. Found
2627c478bd9Sstevel@tonic-gate  *	words are written to this file.
2637c478bd9Sstevel@tonic-gate  *
2647c478bd9Sstevel@tonic-gate  *	In the normal case, the filename = /dev/null. However, if the v option
2657c478bd9Sstevel@tonic-gate  *	is specified, the derivations are written to this file.
2667c478bd9Sstevel@tonic-gate  *	The spellprog looks up words in the hashed-list; if a word is found, it
2677c478bd9Sstevel@tonic-gate  *	is printed to the stdout. If the hashed-list was the stop-list, the
2687c478bd9Sstevel@tonic-gate  *	words found are presumed to be misspellings. in this case,
2697c478bd9Sstevel@tonic-gate  *	a control character is printed ( a "-" is appended to the word.
2707c478bd9Sstevel@tonic-gate  *	a hyphen will never occur naturally in the input list because deroff
2717c478bd9Sstevel@tonic-gate  *	is used in the shell file before calling spellprog.)
2727c478bd9Sstevel@tonic-gate  *	If the regualar spelling list was used (hlista or hlistb), the words
2737c478bd9Sstevel@tonic-gate  *	are correct, and may be ditched. (unless the -v option was used -
2747c478bd9Sstevel@tonic-gate  *	see the manual page).
2757c478bd9Sstevel@tonic-gate  *
2767c478bd9Sstevel@tonic-gate  *	spellprog should be called twice : first with the stop-list, to flag all
2777c478bd9Sstevel@tonic-gate  *	a priori incorrectly spelled words; second with the dictionary.
2787c478bd9Sstevel@tonic-gate  *
2797c478bd9Sstevel@tonic-gate  *	spellprog hstop 1 |\
2807c478bd9Sstevel@tonic-gate  *	spellprog hlista /dev/null
2817c478bd9Sstevel@tonic-gate  *
2827c478bd9Sstevel@tonic-gate  *	for a complete scenario, see the shell file: spell.
2837c478bd9Sstevel@tonic-gate  *
2847c478bd9Sstevel@tonic-gate  */
2857c478bd9Sstevel@tonic-gate 
2860d8b5334Sceastha int
main(int argc,char ** argv)2877c478bd9Sstevel@tonic-gate main(int argc, char **argv)
2887c478bd9Sstevel@tonic-gate {
2890d8b5334Sceastha 	char *ep, *cp;
2900d8b5334Sceastha 	char *dp;
2917c478bd9Sstevel@tonic-gate 	int fold;
2927c478bd9Sstevel@tonic-gate 	int c, j;
2937c478bd9Sstevel@tonic-gate 	int pass;
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 	/* Set locale environment variables local definitions */
2967c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
2977c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
2987c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it wasn't */
2997c478bd9Sstevel@tonic-gate #endif
3007c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	prog = argv[0];
3047c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "bvx")) != EOF) {
3057c478bd9Sstevel@tonic-gate 		switch (c) {
3067c478bd9Sstevel@tonic-gate 		case 'b':
307*17723245SGary Mills 			bflag++;
3087c478bd9Sstevel@tonic-gate 			break;
3097c478bd9Sstevel@tonic-gate 		case 'v':
3107c478bd9Sstevel@tonic-gate 			vflag++;
3117c478bd9Sstevel@tonic-gate 			break;
3127c478bd9Sstevel@tonic-gate 		case 'x':
3137c478bd9Sstevel@tonic-gate 			xflag++;
3147c478bd9Sstevel@tonic-gate 			break;
3157c478bd9Sstevel@tonic-gate 		}
3167c478bd9Sstevel@tonic-gate 	}
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 	argc -= optind;
3197c478bd9Sstevel@tonic-gate 	argv = &argv[optind];
3207c478bd9Sstevel@tonic-gate 
3217c478bd9Sstevel@tonic-gate 	if ((argc < 2) || !prime(*argv)) {
3227c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
3237c478bd9Sstevel@tonic-gate 		    gettext("%s: cannot initialize hash table\n"), prog);
3247c478bd9Sstevel@tonic-gate 		exit(1);
3257c478bd9Sstevel@tonic-gate 	}
3267c478bd9Sstevel@tonic-gate 	argc--;
3277c478bd9Sstevel@tonic-gate 	argv++;
3287c478bd9Sstevel@tonic-gate 
329*17723245SGary Mills 	/* Select the correct suffix table */
330*17723245SGary Mills 	suftab = (bflag == 0) ? sufa : sufb;
331*17723245SGary Mills 
3327c478bd9Sstevel@tonic-gate /*
3337c478bd9Sstevel@tonic-gate  *	if pass is not 1, it is assumed to be a filename.
3347c478bd9Sstevel@tonic-gate  *	found words are written to this file.
3357c478bd9Sstevel@tonic-gate  */
3367c478bd9Sstevel@tonic-gate 	pass = **argv;
3377c478bd9Sstevel@tonic-gate 	if (pass != '1')
3387c478bd9Sstevel@tonic-gate 		found = fopen(*argv, "w");
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 	for (;;) {
3417c478bd9Sstevel@tonic-gate 		affix[0] = 0;
3427c478bd9Sstevel@tonic-gate 		file = stdout;
3437c478bd9Sstevel@tonic-gate 		for (ep = word; (*ep = j = getchar()) != '\n'; ep++)
3447c478bd9Sstevel@tonic-gate 			if (j == EOF)
3457c478bd9Sstevel@tonic-gate 				exit(0);
3467c478bd9Sstevel@tonic-gate /*
3477c478bd9Sstevel@tonic-gate  *	here is the hyphen processing. these words were found in the stop
3487c478bd9Sstevel@tonic-gate  *	list. however, if they exist as is, (no derivations tried) in the
3497c478bd9Sstevel@tonic-gate  *	dictionary, let them through as correct.
3507c478bd9Sstevel@tonic-gate  *
3517c478bd9Sstevel@tonic-gate  */
3527c478bd9Sstevel@tonic-gate 		if (ep[-1] == '-') {
3537c478bd9Sstevel@tonic-gate 			*--ep = 0;
3547c478bd9Sstevel@tonic-gate 			if (!tryword(word, ep, 0))
3557c478bd9Sstevel@tonic-gate 				(void) fprintf(file, "%s\n", word);
3567c478bd9Sstevel@tonic-gate 			continue;
3577c478bd9Sstevel@tonic-gate 		}
3587c478bd9Sstevel@tonic-gate 		for (cp = word, dp = original; cp < ep; )
3597c478bd9Sstevel@tonic-gate 			*dp++ = *cp++;
3607c478bd9Sstevel@tonic-gate 		*dp = 0;
3617c478bd9Sstevel@tonic-gate 		fold = 0;
3627c478bd9Sstevel@tonic-gate 		for (cp = word; cp < ep; cp++)
3637c478bd9Sstevel@tonic-gate 			if (islower(*cp))
3647c478bd9Sstevel@tonic-gate 				goto lcase;
3657c478bd9Sstevel@tonic-gate 		if (((ep - word) == 1) &&
3667c478bd9Sstevel@tonic-gate 		    ((word[0] == 'A') || (word[0] == 'I')))
3677c478bd9Sstevel@tonic-gate 			continue;
3687c478bd9Sstevel@tonic-gate 		if (trypref(ep, ".", 0))
3697c478bd9Sstevel@tonic-gate 			goto foundit;
3707c478bd9Sstevel@tonic-gate 		++fold;
3717c478bd9Sstevel@tonic-gate 		for (cp = original+1, dp = word+1; dp < ep; dp++, cp++)
3727c478bd9Sstevel@tonic-gate 			*dp = Tolower(*cp);
3737c478bd9Sstevel@tonic-gate lcase:
3747c478bd9Sstevel@tonic-gate 		if (((ep - word) == 1) && (word[0] == 'a'))
3757c478bd9Sstevel@tonic-gate 			continue;
3767c478bd9Sstevel@tonic-gate 		if (trypref(ep, ".", 0)||trysuff(ep, 0))
3777c478bd9Sstevel@tonic-gate 			goto foundit;
3787c478bd9Sstevel@tonic-gate 		if (isupper(word[0])) {
3797c478bd9Sstevel@tonic-gate 			for (cp = original, dp = word; *dp = *cp++; dp++)
3807c478bd9Sstevel@tonic-gate 				if (fold) *dp = Tolower(*dp);
3817c478bd9Sstevel@tonic-gate 			word[0] = Tolower(word[0]);
3827c478bd9Sstevel@tonic-gate 			goto lcase;
3837c478bd9Sstevel@tonic-gate 		}
3847c478bd9Sstevel@tonic-gate 		(void) fprintf(file, "%s\n", original);
3857c478bd9Sstevel@tonic-gate 		continue;
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate foundit:
3887c478bd9Sstevel@tonic-gate 		if (pass == '1')
3897c478bd9Sstevel@tonic-gate 			(void) fprintf(file, "%s-\n", original);
3907c478bd9Sstevel@tonic-gate 		else if (affix[0] != 0 && affix[0] != '.') {
3917c478bd9Sstevel@tonic-gate 			file = found;
3927c478bd9Sstevel@tonic-gate 			(void) fprintf(file, "%s\t%s\n", affix,
3937c478bd9Sstevel@tonic-gate 			    original);
3947c478bd9Sstevel@tonic-gate 		}
3957c478bd9Sstevel@tonic-gate 	}
3967c478bd9Sstevel@tonic-gate }
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate /*
3997c478bd9Sstevel@tonic-gate  *	strip exactly one suffix and do
4007c478bd9Sstevel@tonic-gate  *	indicated routine(s), which may recursively
4017c478bd9Sstevel@tonic-gate  *	strip suffixes
4027c478bd9Sstevel@tonic-gate  */
4037c478bd9Sstevel@tonic-gate 
4047c478bd9Sstevel@tonic-gate static int
trysuff(char * ep,int lev)4057c478bd9Sstevel@tonic-gate trysuff(char *ep, int lev)
4067c478bd9Sstevel@tonic-gate {
4070d8b5334Sceastha 	struct suftab	*t;
4080d8b5334Sceastha 	char *cp, *sp;
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate 	lev += DLEV;
4117c478bd9Sstevel@tonic-gate 	deriv[lev] = deriv[lev-1] = 0;
412*17723245SGary Mills 	for (t = &suftab[0]; (t != 0 && (sp = t->suf) != 0); t++) {
4137c478bd9Sstevel@tonic-gate 		cp = ep;
4147c478bd9Sstevel@tonic-gate 		while (*sp)
4157c478bd9Sstevel@tonic-gate 			if (*--cp != *sp++)
4167c478bd9Sstevel@tonic-gate 				goto next;
417*17723245SGary Mills 		for (sp = cp; --sp >= word && !vowel(*sp); )
418*17723245SGary Mills 			;
4197c478bd9Sstevel@tonic-gate 		if (sp < word)
4207c478bd9Sstevel@tonic-gate 			return (0);
4217c478bd9Sstevel@tonic-gate 		if ((*t->p1)(ep-t->n1, t->d1, t->a1, lev+1))
4227c478bd9Sstevel@tonic-gate 			return (1);
4237c478bd9Sstevel@tonic-gate 		if (t->p2 != 0) {
4247c478bd9Sstevel@tonic-gate 			deriv[lev] = deriv[lev+1] = 0;
4257c478bd9Sstevel@tonic-gate 			return ((*t->p2)(ep-t->n2, t->d2, t->a2, lev));
4267c478bd9Sstevel@tonic-gate 		}
4277c478bd9Sstevel@tonic-gate 		return (0);
4287c478bd9Sstevel@tonic-gate next:;
4297c478bd9Sstevel@tonic-gate 	}
4307c478bd9Sstevel@tonic-gate 	return (0);
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate static int
nop(void)4347c478bd9Sstevel@tonic-gate nop(void)
4357c478bd9Sstevel@tonic-gate {
4367c478bd9Sstevel@tonic-gate 	return (0);
4377c478bd9Sstevel@tonic-gate }
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate /* ARGSUSED */
4407c478bd9Sstevel@tonic-gate static int
strip(char * ep,char * d,char * a,int lev)4417c478bd9Sstevel@tonic-gate strip(char *ep, char *d, char *a, int lev)
4427c478bd9Sstevel@tonic-gate {
4437c478bd9Sstevel@tonic-gate 	return (trypref(ep, a, lev)||trysuff(ep, lev));
4447c478bd9Sstevel@tonic-gate }
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate static int
s(char * ep,char * d,char * a,int lev)4477c478bd9Sstevel@tonic-gate s(char *ep, char *d, char *a, int lev)
4487c478bd9Sstevel@tonic-gate {
4497c478bd9Sstevel@tonic-gate 	if (lev > DLEV+1)
4507c478bd9Sstevel@tonic-gate 		return (0);
4517c478bd9Sstevel@tonic-gate 	if (*ep == 's' && ep[-1] == 's')
4527c478bd9Sstevel@tonic-gate 		return (0);
4537c478bd9Sstevel@tonic-gate 	return (strip(ep, d, a, lev));
4547c478bd9Sstevel@tonic-gate }
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate /* ARGSUSED */
4577c478bd9Sstevel@tonic-gate static int
an(char * ep,char * d,char * a,int lev)4587c478bd9Sstevel@tonic-gate an(char *ep, char *d, char *a, int lev)
4597c478bd9Sstevel@tonic-gate {
4607c478bd9Sstevel@tonic-gate 	if (!isupper(*word))	/* must be proper name */
4617c478bd9Sstevel@tonic-gate 		return (0);
4627c478bd9Sstevel@tonic-gate 	return (trypref(ep, a, lev));
4637c478bd9Sstevel@tonic-gate }
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate /* ARGSUSED */
4667c478bd9Sstevel@tonic-gate static int
ize(char * ep,char * d,char * a,int lev)4677c478bd9Sstevel@tonic-gate ize(char *ep, char *d, char *a, int lev)
4687c478bd9Sstevel@tonic-gate {
4697c478bd9Sstevel@tonic-gate 	ep[-1] = 'e';
4707c478bd9Sstevel@tonic-gate 	return (strip(ep, "", d, lev));
4717c478bd9Sstevel@tonic-gate }
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate /* ARGSUSED */
4747c478bd9Sstevel@tonic-gate static int
y_to_e(char * ep,char * d,char * a,int lev)4757c478bd9Sstevel@tonic-gate y_to_e(char *ep, char *d, char *a, int lev)
4767c478bd9Sstevel@tonic-gate {
4777c478bd9Sstevel@tonic-gate 	*ep++ = 'e';
4787c478bd9Sstevel@tonic-gate 	return (strip(ep, "", d, lev));
4797c478bd9Sstevel@tonic-gate }
4807c478bd9Sstevel@tonic-gate 
4817c478bd9Sstevel@tonic-gate static int
ily(char * ep,char * d,char * a,int lev)4827c478bd9Sstevel@tonic-gate ily(char *ep, char *d, char *a, int lev)
4837c478bd9Sstevel@tonic-gate {
4847c478bd9Sstevel@tonic-gate 	if (ep[-1] == 'i')
4857c478bd9Sstevel@tonic-gate 		return (i_to_y(ep, d, a, lev));
4867c478bd9Sstevel@tonic-gate 	else
4877c478bd9Sstevel@tonic-gate 		return (strip(ep, d, a, lev));
4887c478bd9Sstevel@tonic-gate }
4897c478bd9Sstevel@tonic-gate 
4907c478bd9Sstevel@tonic-gate static int
bility(char * ep,char * d,char * a,int lev)4917c478bd9Sstevel@tonic-gate bility(char *ep, char *d, char *a, int lev)
4927c478bd9Sstevel@tonic-gate {
4937c478bd9Sstevel@tonic-gate 	*ep++ = 'l';
4947c478bd9Sstevel@tonic-gate 	return (y_to_e(ep, d, a, lev));
4957c478bd9Sstevel@tonic-gate }
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate static int
i_to_y(char * ep,char * d,char * a,int lev)4987c478bd9Sstevel@tonic-gate i_to_y(char *ep, char *d, char *a, int lev)
4997c478bd9Sstevel@tonic-gate {
5007c478bd9Sstevel@tonic-gate 	if (ep[-1] == 'i') {
5017c478bd9Sstevel@tonic-gate 		ep[-1] = 'y';
5027c478bd9Sstevel@tonic-gate 		a = d;
5037c478bd9Sstevel@tonic-gate 	}
5047c478bd9Sstevel@tonic-gate 	return (strip(ep, "", a, lev));
5057c478bd9Sstevel@tonic-gate }
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate static int
es(char * ep,char * d,char * a,int lev)5087c478bd9Sstevel@tonic-gate es(char *ep, char *d, char *a, int lev)
5097c478bd9Sstevel@tonic-gate {
5107c478bd9Sstevel@tonic-gate 	if (lev > DLEV)
5117c478bd9Sstevel@tonic-gate 		return (0);
5127c478bd9Sstevel@tonic-gate 	switch (ep[-1]) {
5137c478bd9Sstevel@tonic-gate 	default:
5147c478bd9Sstevel@tonic-gate 		return (0);
5157c478bd9Sstevel@tonic-gate 	case 'i':
5167c478bd9Sstevel@tonic-gate 		return (i_to_y(ep, d, a, lev));
5177c478bd9Sstevel@tonic-gate 	case 's':
5187c478bd9Sstevel@tonic-gate 	case 'h':
5197c478bd9Sstevel@tonic-gate 	case 'z':
5207c478bd9Sstevel@tonic-gate 	case 'x':
5217c478bd9Sstevel@tonic-gate 		return (strip(ep, d, a, lev));
5227c478bd9Sstevel@tonic-gate 	}
5237c478bd9Sstevel@tonic-gate }
5247c478bd9Sstevel@tonic-gate 
5257c478bd9Sstevel@tonic-gate /* ARGSUSED */
5267c478bd9Sstevel@tonic-gate static int
subst(char * ep,char * d,char * a,int lev)5277c478bd9Sstevel@tonic-gate subst(char *ep, char *d, char *a, int lev)
5287c478bd9Sstevel@tonic-gate {
5297c478bd9Sstevel@tonic-gate 	char *u, *t;
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 	if (skipv(skipv(ep-1)) < word)
5327c478bd9Sstevel@tonic-gate 		return (0);
5337c478bd9Sstevel@tonic-gate 	for (t = d; *t != '+'; t++)
5347c478bd9Sstevel@tonic-gate 		continue;
5357c478bd9Sstevel@tonic-gate 	for (u = ep; *--t != '-'; )
5367c478bd9Sstevel@tonic-gate 		*--u = *t;
5377c478bd9Sstevel@tonic-gate 	return (strip(ep, "", d, lev));
5387c478bd9Sstevel@tonic-gate }
5397c478bd9Sstevel@tonic-gate 
5407c478bd9Sstevel@tonic-gate 
5417c478bd9Sstevel@tonic-gate static int
tion(char * ep,char * d,char * a,int lev)5427c478bd9Sstevel@tonic-gate tion(char *ep, char *d, char *a, int lev)
5437c478bd9Sstevel@tonic-gate {
5447c478bd9Sstevel@tonic-gate 	switch (ep[-2]) {
5457c478bd9Sstevel@tonic-gate 	case 'c':
5467c478bd9Sstevel@tonic-gate 	case 'r':
5477c478bd9Sstevel@tonic-gate 		return (trypref(ep, a, lev));
5487c478bd9Sstevel@tonic-gate 	case 'a':
5497c478bd9Sstevel@tonic-gate 		return (y_to_e(ep, d, a, lev));
5507c478bd9Sstevel@tonic-gate 	}
5517c478bd9Sstevel@tonic-gate 	return (0);
5527c478bd9Sstevel@tonic-gate }
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate /*	possible consonant-consonant-e ending */
5557c478bd9Sstevel@tonic-gate static int
CCe(char * ep,char * d,char * a,int lev)5567c478bd9Sstevel@tonic-gate CCe(char *ep, char *d, char *a, int lev)
5577c478bd9Sstevel@tonic-gate {
5587c478bd9Sstevel@tonic-gate 	switch (ep[-1]) {
5597c478bd9Sstevel@tonic-gate 	case 'r':
5607c478bd9Sstevel@tonic-gate 		if (ep[-2] == 't')
5617c478bd9Sstevel@tonic-gate 			return (y_to_e(ep, d, a, lev));
5627c478bd9Sstevel@tonic-gate 		break;
5637c478bd9Sstevel@tonic-gate 	case 'l':
5647c478bd9Sstevel@tonic-gate 		if (vowel(ep[-2]))
5657c478bd9Sstevel@tonic-gate 			break;
5667c478bd9Sstevel@tonic-gate 		switch (ep[-2]) {
5677c478bd9Sstevel@tonic-gate 		case 'l':
5687c478bd9Sstevel@tonic-gate 		case 'r':
5697c478bd9Sstevel@tonic-gate 		case 'w':
5707c478bd9Sstevel@tonic-gate 			break;
5717c478bd9Sstevel@tonic-gate 		default:
5727c478bd9Sstevel@tonic-gate 			return (y_to_e(ep, d, a, lev));
5737c478bd9Sstevel@tonic-gate 		}
5747c478bd9Sstevel@tonic-gate 		break;
5757c478bd9Sstevel@tonic-gate 	case 's':
5767c478bd9Sstevel@tonic-gate 		if (ep[-2] == 's')
5777c478bd9Sstevel@tonic-gate 			break;
5787c478bd9Sstevel@tonic-gate 		if (*ep == 'a')
5797c478bd9Sstevel@tonic-gate 			return (0);
5807c478bd9Sstevel@tonic-gate 		if (vowel(ep[-2]))
5817c478bd9Sstevel@tonic-gate 			break;
5827c478bd9Sstevel@tonic-gate 		if (y_to_e(ep, d, a, lev))
5837c478bd9Sstevel@tonic-gate 			return (1);
5847c478bd9Sstevel@tonic-gate 		if (!(ep[-2] == 'n' && ep[-1] == 'g'))
5857c478bd9Sstevel@tonic-gate 			return (0);
5867c478bd9Sstevel@tonic-gate 		break;
5877c478bd9Sstevel@tonic-gate 	case 'c':
5887c478bd9Sstevel@tonic-gate 	case 'g':
5897c478bd9Sstevel@tonic-gate 		if (*ep == 'a')
5907c478bd9Sstevel@tonic-gate 			return (0);
5917c478bd9Sstevel@tonic-gate 		if (vowel(ep[-2]))
5927c478bd9Sstevel@tonic-gate 			break;
5937c478bd9Sstevel@tonic-gate 		if (y_to_e(ep, d, a, lev))
5947c478bd9Sstevel@tonic-gate 			return (1);
5957c478bd9Sstevel@tonic-gate 		if (!(ep[-2] == 'n' && ep[-1] == 'g'))
5967c478bd9Sstevel@tonic-gate 			return (0);
5977c478bd9Sstevel@tonic-gate 		break;
5987c478bd9Sstevel@tonic-gate 	case 'v':
5997c478bd9Sstevel@tonic-gate 	case 'z':
6007c478bd9Sstevel@tonic-gate 		if (vowel(ep[-2]))
6017c478bd9Sstevel@tonic-gate 			break;
6027c478bd9Sstevel@tonic-gate 		if (y_to_e(ep, d, a, lev))
6037c478bd9Sstevel@tonic-gate 			return (1);
6047c478bd9Sstevel@tonic-gate 		if (!(ep[-2] == 'n' && ep[-1] == 'g'))
6057c478bd9Sstevel@tonic-gate 			return (0);
6067c478bd9Sstevel@tonic-gate 		break;
6077c478bd9Sstevel@tonic-gate 	case 'u':
6087c478bd9Sstevel@tonic-gate 		if (y_to_e(ep, d, a, lev))
6097c478bd9Sstevel@tonic-gate 			return (1);
6107c478bd9Sstevel@tonic-gate 		if (!(ep[-2] == 'n' && ep[-1] == 'g'))
6117c478bd9Sstevel@tonic-gate 			return (0);
6127c478bd9Sstevel@tonic-gate 		break;
6137c478bd9Sstevel@tonic-gate 	}
6147c478bd9Sstevel@tonic-gate 	return (VCe(ep, d, a, lev));
6157c478bd9Sstevel@tonic-gate }
6167c478bd9Sstevel@tonic-gate 
6177c478bd9Sstevel@tonic-gate /*	possible consonant-vowel-consonant-e ending */
6187c478bd9Sstevel@tonic-gate static int
VCe(char * ep,char * d,char * a,int lev)6197c478bd9Sstevel@tonic-gate VCe(char *ep, char *d, char *a, int lev)
6207c478bd9Sstevel@tonic-gate {
6217c478bd9Sstevel@tonic-gate 	char c;
6227c478bd9Sstevel@tonic-gate 	c = ep[-1];
6237c478bd9Sstevel@tonic-gate 	if (c == 'e')
6247c478bd9Sstevel@tonic-gate 		return (0);
6257c478bd9Sstevel@tonic-gate 	if (!vowel(c) && vowel(ep[-2])) {
6267c478bd9Sstevel@tonic-gate 		c = *ep;
6277c478bd9Sstevel@tonic-gate 		*ep++ = 'e';
6287c478bd9Sstevel@tonic-gate 		if (trypref(ep, d, lev)||trysuff(ep, lev))
6297c478bd9Sstevel@tonic-gate 			return (1);
6307c478bd9Sstevel@tonic-gate 		ep--;
6317c478bd9Sstevel@tonic-gate 		*ep = c;
6327c478bd9Sstevel@tonic-gate 	}
6337c478bd9Sstevel@tonic-gate 	return (strip(ep, d, a, lev));
6347c478bd9Sstevel@tonic-gate }
6357c478bd9Sstevel@tonic-gate 
6367c478bd9Sstevel@tonic-gate static char *
lookuppref(char ** wp,char * ep)6377c478bd9Sstevel@tonic-gate lookuppref(char **wp, char *ep)
6387c478bd9Sstevel@tonic-gate {
6390d8b5334Sceastha 	char **sp;
6400d8b5334Sceastha 	char *bp, *cp;
6417c478bd9Sstevel@tonic-gate 
6427c478bd9Sstevel@tonic-gate 	for (sp = preftab; *sp; sp++) {
6437c478bd9Sstevel@tonic-gate 		bp = *wp;
6447c478bd9Sstevel@tonic-gate 		for (cp = *sp; *cp; cp++, bp++)
6457c478bd9Sstevel@tonic-gate 			if (Tolower(*bp) != *cp)
6467c478bd9Sstevel@tonic-gate 				goto next;
6477c478bd9Sstevel@tonic-gate 		for (cp = bp; cp < ep; cp++)
6487c478bd9Sstevel@tonic-gate 			if (vowel(*cp)) {
6497c478bd9Sstevel@tonic-gate 				*wp = bp;
6507c478bd9Sstevel@tonic-gate 				return (*sp);
6517c478bd9Sstevel@tonic-gate 			}
6527c478bd9Sstevel@tonic-gate next:;
6537c478bd9Sstevel@tonic-gate 	}
6547c478bd9Sstevel@tonic-gate 	return (0);
6557c478bd9Sstevel@tonic-gate }
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate /*
6587c478bd9Sstevel@tonic-gate  *	while word is not in dictionary try stripping
6597c478bd9Sstevel@tonic-gate  *	prefixes. Fail if no more prefixes.
6607c478bd9Sstevel@tonic-gate  */
6617c478bd9Sstevel@tonic-gate static int
trypref(char * ep,char * a,int lev)6627c478bd9Sstevel@tonic-gate trypref(char *ep, char *a, int lev)
6637c478bd9Sstevel@tonic-gate {
6640d8b5334Sceastha 	char *cp;
6657c478bd9Sstevel@tonic-gate 	char *bp;
6660d8b5334Sceastha 	char *pp;
6677c478bd9Sstevel@tonic-gate 	int val = 0;
6687c478bd9Sstevel@tonic-gate 	char space[LINE_MAX * 2];
6697c478bd9Sstevel@tonic-gate 	deriv[lev] = a;
6707c478bd9Sstevel@tonic-gate 	if (tryword(word, ep, lev))
6717c478bd9Sstevel@tonic-gate 		return (1);
6727c478bd9Sstevel@tonic-gate 	bp = word;
6737c478bd9Sstevel@tonic-gate 	pp = space;
6747c478bd9Sstevel@tonic-gate 	deriv[lev+1] = pp;
6757c478bd9Sstevel@tonic-gate 	while (cp = lookuppref(&bp, ep)) {
6767c478bd9Sstevel@tonic-gate 		*pp++ = '+';
6777c478bd9Sstevel@tonic-gate 		while (*pp = *cp++)
6787c478bd9Sstevel@tonic-gate 			pp++;
6797c478bd9Sstevel@tonic-gate 		if (tryword(bp, ep, lev+1)) {
6807c478bd9Sstevel@tonic-gate 			val = 1;
6817c478bd9Sstevel@tonic-gate 			break;
6827c478bd9Sstevel@tonic-gate 		}
6837c478bd9Sstevel@tonic-gate 	}
6847c478bd9Sstevel@tonic-gate 	deriv[lev+1] = deriv[lev+2] = 0;
6857c478bd9Sstevel@tonic-gate 	return (val);
6867c478bd9Sstevel@tonic-gate }
6877c478bd9Sstevel@tonic-gate 
6887c478bd9Sstevel@tonic-gate static int
tryword(char * bp,char * ep,int lev)6897c478bd9Sstevel@tonic-gate tryword(char *bp, char *ep, int lev)
6907c478bd9Sstevel@tonic-gate {
6910d8b5334Sceastha 	int i, j;
6927c478bd9Sstevel@tonic-gate 	char duple[3];
6937c478bd9Sstevel@tonic-gate 	if (ep-bp <= 1)
6947c478bd9Sstevel@tonic-gate 		return (0);
6957c478bd9Sstevel@tonic-gate 	if (vowel(*ep)) {
6967c478bd9Sstevel@tonic-gate 		if (monosyl(bp, ep))
6977c478bd9Sstevel@tonic-gate 			return (0);
6987c478bd9Sstevel@tonic-gate 	}
6997c478bd9Sstevel@tonic-gate 	i = dict(bp, ep);
7007c478bd9Sstevel@tonic-gate 	if (i == 0 && vowel(*ep) && ep[-1] == ep[-2] && monosyl(bp, ep-1)) {
7017c478bd9Sstevel@tonic-gate 		ep--;
7027c478bd9Sstevel@tonic-gate 		deriv[++lev] = duple;
7037c478bd9Sstevel@tonic-gate 		duple[0] = '+';
7047c478bd9Sstevel@tonic-gate 		duple[1] = *ep;
7057c478bd9Sstevel@tonic-gate 		duple[2] = 0;
7067c478bd9Sstevel@tonic-gate 		i = dict(bp, ep);
7077c478bd9Sstevel@tonic-gate 	}
7087c478bd9Sstevel@tonic-gate 	if (vflag == 0 || i == 0)
7097c478bd9Sstevel@tonic-gate 		return (i);
7107c478bd9Sstevel@tonic-gate 	/*
7117c478bd9Sstevel@tonic-gate 	 *	when derivations are wanted, collect them
7127c478bd9Sstevel@tonic-gate 	 *	for printing
7137c478bd9Sstevel@tonic-gate 	 */
7147c478bd9Sstevel@tonic-gate 	j = lev;
7157c478bd9Sstevel@tonic-gate 	do {
7167c478bd9Sstevel@tonic-gate 		if (deriv[j])
7177c478bd9Sstevel@tonic-gate 			(void) strcat(affix, deriv[j]);
7187c478bd9Sstevel@tonic-gate 	} while (--j > 0);
7197c478bd9Sstevel@tonic-gate 	return (i);
7207c478bd9Sstevel@tonic-gate }
7217c478bd9Sstevel@tonic-gate 
7227c478bd9Sstevel@tonic-gate 
7237c478bd9Sstevel@tonic-gate static int
monosyl(char * bp,char * ep)7247c478bd9Sstevel@tonic-gate monosyl(char *bp, char *ep)
7257c478bd9Sstevel@tonic-gate {
7267c478bd9Sstevel@tonic-gate 	if (ep < bp+2)
7277c478bd9Sstevel@tonic-gate 		return (0);
7287c478bd9Sstevel@tonic-gate 	if (vowel(*--ep) || !vowel(*--ep) || ep[1] == 'x' || ep[1] == 'w')
7297c478bd9Sstevel@tonic-gate 		return (0);
7307c478bd9Sstevel@tonic-gate 	while (--ep >= bp)
7317c478bd9Sstevel@tonic-gate 		if (vowel(*ep))
7327c478bd9Sstevel@tonic-gate 			return (0);
7337c478bd9Sstevel@tonic-gate 	return (1);
7347c478bd9Sstevel@tonic-gate }
7357c478bd9Sstevel@tonic-gate 
7367c478bd9Sstevel@tonic-gate static char *
skipv(char * s)7377c478bd9Sstevel@tonic-gate skipv(char *s)
7387c478bd9Sstevel@tonic-gate {
7397c478bd9Sstevel@tonic-gate 	if (s >= word&&vowel(*s))
7407c478bd9Sstevel@tonic-gate 		s--;
7417c478bd9Sstevel@tonic-gate 	while (s >= word && !vowel(*s))
7427c478bd9Sstevel@tonic-gate 		s--;
7437c478bd9Sstevel@tonic-gate 	return (s);
7447c478bd9Sstevel@tonic-gate }
7457c478bd9Sstevel@tonic-gate 
7467c478bd9Sstevel@tonic-gate static int
vowel(int c)7477c478bd9Sstevel@tonic-gate vowel(int c)
7487c478bd9Sstevel@tonic-gate {
7497c478bd9Sstevel@tonic-gate 	switch (Tolower(c)) {
7507c478bd9Sstevel@tonic-gate 	case 'a':
7517c478bd9Sstevel@tonic-gate 	case 'e':
7527c478bd9Sstevel@tonic-gate 	case 'i':
7537c478bd9Sstevel@tonic-gate 	case 'o':
7547c478bd9Sstevel@tonic-gate 	case 'u':
7557c478bd9Sstevel@tonic-gate 	case 'y':
7567c478bd9Sstevel@tonic-gate 		return (1);
7577c478bd9Sstevel@tonic-gate 	}
7587c478bd9Sstevel@tonic-gate 	return (0);
7597c478bd9Sstevel@tonic-gate }
7607c478bd9Sstevel@tonic-gate 
7617c478bd9Sstevel@tonic-gate static int
dict(char * bp,char * ep)7627c478bd9Sstevel@tonic-gate dict(char *bp, char *ep)
7637c478bd9Sstevel@tonic-gate {
7640d8b5334Sceastha 	int temp, result;
7657c478bd9Sstevel@tonic-gate 	if (xflag)
7667c478bd9Sstevel@tonic-gate 		(void) fprintf(stdout, "=%.*s\n", ep-bp, bp);
7677c478bd9Sstevel@tonic-gate 	temp = *ep;
7687c478bd9Sstevel@tonic-gate 	*ep = 0;
7697c478bd9Sstevel@tonic-gate 	result = hashlook(bp);
7707c478bd9Sstevel@tonic-gate 	*ep = temp;
7717c478bd9Sstevel@tonic-gate 	return (result);
7727c478bd9Sstevel@tonic-gate }
773