xref: /titanic_41/usr/src/cmd/spell/spellprog.c (revision 0d8b53344490faab75b127936edb53a2f1e0dc01)
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*0d8b5334Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
27*0d8b5334Sceastha /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28*0d8b5334Sceastha /*	  All Rights Reserved  	*/
29*0d8b5334Sceastha 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #include <stdlib.h>
337c478bd9Sstevel@tonic-gate #include <unistd.h>
347c478bd9Sstevel@tonic-gate #include <limits.h>
357c478bd9Sstevel@tonic-gate #include <string.h>
367c478bd9Sstevel@tonic-gate #include <stdio.h>
377c478bd9Sstevel@tonic-gate #include <ctype.h>
387c478bd9Sstevel@tonic-gate #include <locale.h>
397c478bd9Sstevel@tonic-gate #include "hash.h"
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #define	Tolower(c) (isupper(c)?tolower(c):c)
427c478bd9Sstevel@tonic-gate #define	DLEV 2
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate /*
457c478bd9Sstevel@tonic-gate  * ANSI prototypes
467c478bd9Sstevel@tonic-gate  */
477c478bd9Sstevel@tonic-gate static int	ily(char *, char *, char *, int);
487c478bd9Sstevel@tonic-gate static int	s(char *, char *, char *, int);
497c478bd9Sstevel@tonic-gate static int	es(char *, char *, char *, int);
507c478bd9Sstevel@tonic-gate static int	subst(char *, char *, char *, int);
517c478bd9Sstevel@tonic-gate static int	nop(void);
527c478bd9Sstevel@tonic-gate static int	bility(char *, char *, char *, int);
537c478bd9Sstevel@tonic-gate static int	i_to_y(char *, char *, char *, int);
547c478bd9Sstevel@tonic-gate static int	CCe(char *, char *, char *, int);
557c478bd9Sstevel@tonic-gate static int	y_to_e(char *, char *, char *, int);
567c478bd9Sstevel@tonic-gate static int	strip(char *, char *, char *, int);
577c478bd9Sstevel@tonic-gate static int	ize(char *, char *, char *, int);
587c478bd9Sstevel@tonic-gate static int	tion(char *, char *, char *, int);
597c478bd9Sstevel@tonic-gate static int	an(char *, char *, char *, int);
607c478bd9Sstevel@tonic-gate int		prime(char *);
617c478bd9Sstevel@tonic-gate static void	ise(void);
627c478bd9Sstevel@tonic-gate static int	tryword(char *, char *, int);
637c478bd9Sstevel@tonic-gate static int	trypref(char *, char *, int);
647c478bd9Sstevel@tonic-gate static int	trysuff(char *, int);
657c478bd9Sstevel@tonic-gate static int	vowel(int);
667c478bd9Sstevel@tonic-gate static int	dict(char *, char *);
677c478bd9Sstevel@tonic-gate static int	monosyl(char *, char *);
687c478bd9Sstevel@tonic-gate static int	VCe(char *, char *, char *, int);
697c478bd9Sstevel@tonic-gate static char	*skipv(char *);
707c478bd9Sstevel@tonic-gate static void	ztos(char *);
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate static struct suftab {
737c478bd9Sstevel@tonic-gate 	char *suf;
747c478bd9Sstevel@tonic-gate 	int (*p1)();
757c478bd9Sstevel@tonic-gate 	int n1;
767c478bd9Sstevel@tonic-gate 	char *d1;
777c478bd9Sstevel@tonic-gate 	char *a1;
787c478bd9Sstevel@tonic-gate 	int (*p2)();
797c478bd9Sstevel@tonic-gate 	int n2;
807c478bd9Sstevel@tonic-gate 	char *d2;
817c478bd9Sstevel@tonic-gate 	char *a2;
827c478bd9Sstevel@tonic-gate } suftab[] = {
837c478bd9Sstevel@tonic-gate 	{"ssen", ily, 4, "-y+iness", "+ness" },
847c478bd9Sstevel@tonic-gate 	{"ssel", ily, 4, "-y+i+less", "+less" },
857c478bd9Sstevel@tonic-gate 	{"se", s, 1, "", "+s", 	es, 2, "-y+ies", "+es" },
867c478bd9Sstevel@tonic-gate 	{"s'", s, 2, "", "+'s"},
877c478bd9Sstevel@tonic-gate 	{"s", s, 1, "", "+s"},
887c478bd9Sstevel@tonic-gate 	{"ecn", subst, 1, "-t+ce", ""},
897c478bd9Sstevel@tonic-gate 	{"ycn", subst, 1, "-t+cy", ""},
907c478bd9Sstevel@tonic-gate 	{"ytilb", nop, 0, "", ""},
917c478bd9Sstevel@tonic-gate 	{"ytilib", bility, 5, "-le+ility", ""},
927c478bd9Sstevel@tonic-gate 	{"elbaif", i_to_y, 4, "-y+iable", ""},
937c478bd9Sstevel@tonic-gate 	{"elba", CCe, 4, "-e+able", "+able"},
947c478bd9Sstevel@tonic-gate 	{"yti", CCe, 3, "-e+ity", "+ity"},
957c478bd9Sstevel@tonic-gate 	{"ylb", y_to_e, 1, "-e+y", ""},
967c478bd9Sstevel@tonic-gate 	{"yl", ily, 2, "-y+ily", "+ly"},
977c478bd9Sstevel@tonic-gate 	{"laci", strip, 2, "", "+al"},
987c478bd9Sstevel@tonic-gate 	{"latnem", strip, 2, "", "+al"},
997c478bd9Sstevel@tonic-gate 	{"lanoi", strip, 2, "", "+al"},
1007c478bd9Sstevel@tonic-gate 	{"tnem", strip, 4, "", "+ment"},
1017c478bd9Sstevel@tonic-gate 	{"gni", CCe, 3, "-e+ing", "+ing"},
1027c478bd9Sstevel@tonic-gate 	{"reta", nop, 0, "", ""},
1037c478bd9Sstevel@tonic-gate 	{"retc", nop, 0, "", ""},
1047c478bd9Sstevel@tonic-gate 	{"re", strip, 1, "", "+r", i_to_y, 2, "-y+ier", "+er"},
1057c478bd9Sstevel@tonic-gate 	{"de", strip, 1, "", "+d", i_to_y, 2, "-y+ied", "+ed"},
1067c478bd9Sstevel@tonic-gate 	{"citsi", strip, 2, "", "+ic"},
1077c478bd9Sstevel@tonic-gate 	{"citi", ize, 1, "-ic+e", ""},
1087c478bd9Sstevel@tonic-gate 	{"cihparg", i_to_y, 1, "-y+ic", ""},
1097c478bd9Sstevel@tonic-gate 	{"tse", strip, 2, "", "+st", 	i_to_y, 3, "-y+iest", "+est"},
1107c478bd9Sstevel@tonic-gate 	{"cirtem", i_to_y, 1, "-y+ic", ""},
1117c478bd9Sstevel@tonic-gate 	{"yrtem", subst, 0, "-er+ry", ""},
1127c478bd9Sstevel@tonic-gate 	{"cigol", i_to_y, 1, "-y+ic", ""},
1137c478bd9Sstevel@tonic-gate 	{"tsigol", i_to_y, 2, "-y+ist", ""},
1147c478bd9Sstevel@tonic-gate 	{"tsi", CCe, 3, "-e+ist", "+ist"},
1157c478bd9Sstevel@tonic-gate 	{"msi", CCe, 3, "-e+ism", "+ist"},
1167c478bd9Sstevel@tonic-gate 	{"noitacifi", i_to_y, 6, "-y+ication", ""},
1177c478bd9Sstevel@tonic-gate 	{"noitazi", ize, 4, "-e+ation", ""},
1187c478bd9Sstevel@tonic-gate 	{"rota", tion, 2, "-e+or", ""},
1197c478bd9Sstevel@tonic-gate 	{"rotc", tion, 2, "", "+or"},
1207c478bd9Sstevel@tonic-gate 	{"noit", tion, 3, "-e+ion", "+ion"},
1217c478bd9Sstevel@tonic-gate 	{"naino", an, 3, "", "+ian"},
1227c478bd9Sstevel@tonic-gate 	{"na", an, 1, "", "+n"},
1237c478bd9Sstevel@tonic-gate 	{"evi", subst, 0, "-ion+ive", ""},
1247c478bd9Sstevel@tonic-gate 	{"ezi", CCe, 3, "-e+ize", "+ize"},
1257c478bd9Sstevel@tonic-gate 	{"pihs", strip, 4, "", "+ship"},
1267c478bd9Sstevel@tonic-gate 	{"dooh", ily, 4, "-y+ihood", "+hood"},
1277c478bd9Sstevel@tonic-gate 	{"luf", ily, 3, "-y+iful", "+ful"},
1287c478bd9Sstevel@tonic-gate 	{"ekil", strip, 4, "", "+like"},
1297c478bd9Sstevel@tonic-gate 	0
1307c478bd9Sstevel@tonic-gate };
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate static char *preftab[] = {
1337c478bd9Sstevel@tonic-gate 	"anti",
1347c478bd9Sstevel@tonic-gate 	"auto",
1357c478bd9Sstevel@tonic-gate 	"bio",
1367c478bd9Sstevel@tonic-gate 	"counter",
1377c478bd9Sstevel@tonic-gate 	"dis",
1387c478bd9Sstevel@tonic-gate 	"electro",
1397c478bd9Sstevel@tonic-gate 	"en",
1407c478bd9Sstevel@tonic-gate 	"fore",
1417c478bd9Sstevel@tonic-gate 	"geo",
1427c478bd9Sstevel@tonic-gate 	"hyper",
1437c478bd9Sstevel@tonic-gate 	"intra",
1447c478bd9Sstevel@tonic-gate 	"inter",
1457c478bd9Sstevel@tonic-gate 	"iso",
1467c478bd9Sstevel@tonic-gate 	"kilo",
1477c478bd9Sstevel@tonic-gate 	"magneto",
1487c478bd9Sstevel@tonic-gate 	"meta",
1497c478bd9Sstevel@tonic-gate 	"micro",
1507c478bd9Sstevel@tonic-gate 	"mid",
1517c478bd9Sstevel@tonic-gate 	"milli",
1527c478bd9Sstevel@tonic-gate 	"mis",
1537c478bd9Sstevel@tonic-gate 	"mono",
1547c478bd9Sstevel@tonic-gate 	"multi",
1557c478bd9Sstevel@tonic-gate 	"non",
1567c478bd9Sstevel@tonic-gate 	"out",
1577c478bd9Sstevel@tonic-gate 	"over",
1587c478bd9Sstevel@tonic-gate 	"photo",
1597c478bd9Sstevel@tonic-gate 	"poly",
1607c478bd9Sstevel@tonic-gate 	"pre",
1617c478bd9Sstevel@tonic-gate 	"pseudo",
1627c478bd9Sstevel@tonic-gate 	"psycho",
1637c478bd9Sstevel@tonic-gate 	"re",
1647c478bd9Sstevel@tonic-gate 	"semi",
1657c478bd9Sstevel@tonic-gate 	"stereo",
1667c478bd9Sstevel@tonic-gate 	"sub",
1677c478bd9Sstevel@tonic-gate 	"super",
1687c478bd9Sstevel@tonic-gate 	"tele",
1697c478bd9Sstevel@tonic-gate 	"thermo",
1707c478bd9Sstevel@tonic-gate 	"ultra",
1717c478bd9Sstevel@tonic-gate 	"under",	/* must precede un */
1727c478bd9Sstevel@tonic-gate 	"un",
1737c478bd9Sstevel@tonic-gate 	0
1747c478bd9Sstevel@tonic-gate };
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate static int vflag;
1777c478bd9Sstevel@tonic-gate static int xflag;
1787c478bd9Sstevel@tonic-gate static char *prog;
1797c478bd9Sstevel@tonic-gate static char word[LINE_MAX];
1807c478bd9Sstevel@tonic-gate static char original[LINE_MAX];
1817c478bd9Sstevel@tonic-gate static char *deriv[LINE_MAX];
1827c478bd9Sstevel@tonic-gate static char affix[LINE_MAX];
1837c478bd9Sstevel@tonic-gate static FILE *file, *found;
1847c478bd9Sstevel@tonic-gate /*
1857c478bd9Sstevel@tonic-gate  *	deriv is stack of pointers to notes like +micro +ed
1867c478bd9Sstevel@tonic-gate  *	affix is concatenated string of notes
1877c478bd9Sstevel@tonic-gate  *	the buffer size 141 stems from the sizes of original and affix.
1887c478bd9Sstevel@tonic-gate  */
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate /*
1917c478bd9Sstevel@tonic-gate  *	in an attempt to defray future maintenance misunderstandings, here is
1927c478bd9Sstevel@tonic-gate  *	an attempt to describe the input/output expectations of the spell
1937c478bd9Sstevel@tonic-gate  *	program.
1947c478bd9Sstevel@tonic-gate  *
1957c478bd9Sstevel@tonic-gate  *	spellprog is intended to be called from the shell file spell.
1967c478bd9Sstevel@tonic-gate  *	because of this, there is little error checking (this is historical, not
1977c478bd9Sstevel@tonic-gate  *	necessarily advisable).
1987c478bd9Sstevel@tonic-gate  *
1997c478bd9Sstevel@tonic-gate  *	spellprog options hashed-list pass
2007c478bd9Sstevel@tonic-gate  *
2017c478bd9Sstevel@tonic-gate  *	the hashed-list is a list of the form made by spellin.
2027c478bd9Sstevel@tonic-gate  *	there are 2 types of hashed lists:
2037c478bd9Sstevel@tonic-gate  *		1. a stop list: this specifies words that by the rules embodied
2047c478bd9Sstevel@tonic-gate  *		   in spellprog would be recognized as correct, BUT are really
2057c478bd9Sstevel@tonic-gate  *		   errors.
2067c478bd9Sstevel@tonic-gate  *		2. a dictionary of correctly spelled words.
2077c478bd9Sstevel@tonic-gate  *	the pass number determines how the words found in the specified
2087c478bd9Sstevel@tonic-gate  *	hashed-list are treated. If the pass number is 1, the hashed-list is
2097c478bd9Sstevel@tonic-gate  *	treated as the stop-list, otherwise, it is treated as the regular
2107c478bd9Sstevel@tonic-gate  *	dictionary list. in this case, the value of "pass" is a filename. Found
2117c478bd9Sstevel@tonic-gate  *	words are written to this file.
2127c478bd9Sstevel@tonic-gate  *
2137c478bd9Sstevel@tonic-gate  *	In the normal case, the filename = /dev/null. However, if the v option
2147c478bd9Sstevel@tonic-gate  *	is specified, the derivations are written to this file.
2157c478bd9Sstevel@tonic-gate  *	The spellprog looks up words in the hashed-list; if a word is found, it
2167c478bd9Sstevel@tonic-gate  *	is printed to the stdout. If the hashed-list was the stop-list, the
2177c478bd9Sstevel@tonic-gate  *	words found are presumed to be misspellings. in this case,
2187c478bd9Sstevel@tonic-gate  *	a control character is printed ( a "-" is appended to the word.
2197c478bd9Sstevel@tonic-gate  *	a hyphen will never occur naturally in the input list because deroff
2207c478bd9Sstevel@tonic-gate  *	is used in the shell file before calling spellprog.)
2217c478bd9Sstevel@tonic-gate  *	If the regualar spelling list was used (hlista or hlistb), the words
2227c478bd9Sstevel@tonic-gate  *	are correct, and may be ditched. (unless the -v option was used -
2237c478bd9Sstevel@tonic-gate  *	see the manual page).
2247c478bd9Sstevel@tonic-gate  *
2257c478bd9Sstevel@tonic-gate  *	spellprog should be called twice : first with the stop-list, to flag all
2267c478bd9Sstevel@tonic-gate  *	a priori incorrectly spelled words; second with the dictionary.
2277c478bd9Sstevel@tonic-gate  *
2287c478bd9Sstevel@tonic-gate  *	spellprog hstop 1 |\
2297c478bd9Sstevel@tonic-gate  *	spellprog hlista /dev/null
2307c478bd9Sstevel@tonic-gate  *
2317c478bd9Sstevel@tonic-gate  *	for a complete scenario, see the shell file: spell.
2327c478bd9Sstevel@tonic-gate  *
2337c478bd9Sstevel@tonic-gate  */
2347c478bd9Sstevel@tonic-gate 
235*0d8b5334Sceastha int
2367c478bd9Sstevel@tonic-gate main(int argc, char **argv)
2377c478bd9Sstevel@tonic-gate {
238*0d8b5334Sceastha 	char *ep, *cp;
239*0d8b5334Sceastha 	char *dp;
2407c478bd9Sstevel@tonic-gate 	int fold;
2417c478bd9Sstevel@tonic-gate 	int c, j;
2427c478bd9Sstevel@tonic-gate 	int pass;
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	/* Set locale environment variables local definitions */
2457c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
2467c478bd9Sstevel@tonic-gate #if !defined(TEXT_DOMAIN)	/* Should be defined by cc -D */
2477c478bd9Sstevel@tonic-gate #define	TEXT_DOMAIN "SYS_TEST"	/* Use this only if it wasn't */
2487c478bd9Sstevel@tonic-gate #endif
2497c478bd9Sstevel@tonic-gate 	(void) textdomain(TEXT_DOMAIN);
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 	prog = argv[0];
2537c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "bvx")) != EOF) {
2547c478bd9Sstevel@tonic-gate 		switch (c) {
2557c478bd9Sstevel@tonic-gate 		case 'b':
2567c478bd9Sstevel@tonic-gate 			ise();
2577c478bd9Sstevel@tonic-gate 			break;
2587c478bd9Sstevel@tonic-gate 		case 'v':
2597c478bd9Sstevel@tonic-gate 			vflag++;
2607c478bd9Sstevel@tonic-gate 			break;
2617c478bd9Sstevel@tonic-gate 		case 'x':
2627c478bd9Sstevel@tonic-gate 			xflag++;
2637c478bd9Sstevel@tonic-gate 			break;
2647c478bd9Sstevel@tonic-gate 		}
2657c478bd9Sstevel@tonic-gate 	}
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 	argc -= optind;
2687c478bd9Sstevel@tonic-gate 	argv = &argv[optind];
2697c478bd9Sstevel@tonic-gate 
2707c478bd9Sstevel@tonic-gate 	if ((argc < 2) || !prime(*argv)) {
2717c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
2727c478bd9Sstevel@tonic-gate 		    gettext("%s: cannot initialize hash table\n"), prog);
2737c478bd9Sstevel@tonic-gate 		exit(1);
2747c478bd9Sstevel@tonic-gate 	}
2757c478bd9Sstevel@tonic-gate 	argc--;
2767c478bd9Sstevel@tonic-gate 	argv++;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate /*
2797c478bd9Sstevel@tonic-gate  *	if pass is not 1, it is assumed to be a filename.
2807c478bd9Sstevel@tonic-gate  *	found words are written to this file.
2817c478bd9Sstevel@tonic-gate  */
2827c478bd9Sstevel@tonic-gate 	pass = **argv;
2837c478bd9Sstevel@tonic-gate 	if (pass != '1')
2847c478bd9Sstevel@tonic-gate 		found = fopen(*argv, "w");
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	for (;;) {
2877c478bd9Sstevel@tonic-gate 		affix[0] = 0;
2887c478bd9Sstevel@tonic-gate 		file = stdout;
2897c478bd9Sstevel@tonic-gate 		for (ep = word; (*ep = j = getchar()) != '\n'; ep++)
2907c478bd9Sstevel@tonic-gate 			if (j == EOF)
2917c478bd9Sstevel@tonic-gate 				exit(0);
2927c478bd9Sstevel@tonic-gate /*
2937c478bd9Sstevel@tonic-gate  *	here is the hyphen processing. these words were found in the stop
2947c478bd9Sstevel@tonic-gate  *	list. however, if they exist as is, (no derivations tried) in the
2957c478bd9Sstevel@tonic-gate  *	dictionary, let them through as correct.
2967c478bd9Sstevel@tonic-gate  *
2977c478bd9Sstevel@tonic-gate  */
2987c478bd9Sstevel@tonic-gate 		if (ep[-1] == '-') {
2997c478bd9Sstevel@tonic-gate 			*--ep = 0;
3007c478bd9Sstevel@tonic-gate 			if (!tryword(word, ep, 0))
3017c478bd9Sstevel@tonic-gate 				(void) fprintf(file, "%s\n", word);
3027c478bd9Sstevel@tonic-gate 			continue;
3037c478bd9Sstevel@tonic-gate 		}
3047c478bd9Sstevel@tonic-gate 		for (cp = word, dp = original; cp < ep; )
3057c478bd9Sstevel@tonic-gate 			*dp++ = *cp++;
3067c478bd9Sstevel@tonic-gate 		*dp = 0;
3077c478bd9Sstevel@tonic-gate 		fold = 0;
3087c478bd9Sstevel@tonic-gate 		for (cp = word; cp < ep; cp++)
3097c478bd9Sstevel@tonic-gate 			if (islower(*cp))
3107c478bd9Sstevel@tonic-gate 				goto lcase;
3117c478bd9Sstevel@tonic-gate 		if (((ep - word) == 1) &&
3127c478bd9Sstevel@tonic-gate 		    ((word[0] == 'A') || (word[0] == 'I')))
3137c478bd9Sstevel@tonic-gate 			continue;
3147c478bd9Sstevel@tonic-gate 		if (trypref(ep, ".", 0))
3157c478bd9Sstevel@tonic-gate 			goto foundit;
3167c478bd9Sstevel@tonic-gate 		++fold;
3177c478bd9Sstevel@tonic-gate 		for (cp = original+1, dp = word+1; dp < ep; dp++, cp++)
3187c478bd9Sstevel@tonic-gate 			*dp = Tolower(*cp);
3197c478bd9Sstevel@tonic-gate lcase:
3207c478bd9Sstevel@tonic-gate 		if (((ep - word) == 1) && (word[0] == 'a'))
3217c478bd9Sstevel@tonic-gate 			continue;
3227c478bd9Sstevel@tonic-gate 		if (trypref(ep, ".", 0)||trysuff(ep, 0))
3237c478bd9Sstevel@tonic-gate 			goto foundit;
3247c478bd9Sstevel@tonic-gate 		if (isupper(word[0])) {
3257c478bd9Sstevel@tonic-gate 			for (cp = original, dp = word; *dp = *cp++; dp++)
3267c478bd9Sstevel@tonic-gate 				if (fold) *dp = Tolower(*dp);
3277c478bd9Sstevel@tonic-gate 			word[0] = Tolower(word[0]);
3287c478bd9Sstevel@tonic-gate 			goto lcase;
3297c478bd9Sstevel@tonic-gate 		}
3307c478bd9Sstevel@tonic-gate 		(void) fprintf(file, "%s\n", original);
3317c478bd9Sstevel@tonic-gate 		continue;
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate foundit:
3347c478bd9Sstevel@tonic-gate 		if (pass == '1')
3357c478bd9Sstevel@tonic-gate 			(void) fprintf(file, "%s-\n", original);
3367c478bd9Sstevel@tonic-gate 		else if (affix[0] != 0 && affix[0] != '.') {
3377c478bd9Sstevel@tonic-gate 			file = found;
3387c478bd9Sstevel@tonic-gate 			(void) fprintf(file, "%s\t%s\n", affix,
3397c478bd9Sstevel@tonic-gate 			    original);
3407c478bd9Sstevel@tonic-gate 		}
3417c478bd9Sstevel@tonic-gate 	}
3427c478bd9Sstevel@tonic-gate }
3437c478bd9Sstevel@tonic-gate 
3447c478bd9Sstevel@tonic-gate /*
3457c478bd9Sstevel@tonic-gate  *	strip exactly one suffix and do
3467c478bd9Sstevel@tonic-gate  *	indicated routine(s), which may recursively
3477c478bd9Sstevel@tonic-gate  *	strip suffixes
3487c478bd9Sstevel@tonic-gate  */
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate static int
3517c478bd9Sstevel@tonic-gate trysuff(char *ep, int lev)
3527c478bd9Sstevel@tonic-gate {
353*0d8b5334Sceastha 	struct suftab	*t;
354*0d8b5334Sceastha 	char *cp, *sp;
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate 	lev += DLEV;
3577c478bd9Sstevel@tonic-gate 	deriv[lev] = deriv[lev-1] = 0;
3587c478bd9Sstevel@tonic-gate 	for (t = &suftab[0]; (sp = t->suf) != 0; t++) {
3597c478bd9Sstevel@tonic-gate 		cp = ep;
3607c478bd9Sstevel@tonic-gate 		while (*sp)
3617c478bd9Sstevel@tonic-gate 			if (*--cp != *sp++)
3627c478bd9Sstevel@tonic-gate 				goto next;
3637c478bd9Sstevel@tonic-gate 		for (sp = cp; --sp >= word && !vowel(*sp); );
3647c478bd9Sstevel@tonic-gate 		if (sp < word)
3657c478bd9Sstevel@tonic-gate 			return (0);
3667c478bd9Sstevel@tonic-gate 		if ((*t->p1)(ep-t->n1, t->d1, t->a1, lev+1))
3677c478bd9Sstevel@tonic-gate 			return (1);
3687c478bd9Sstevel@tonic-gate 		if (t->p2 != 0) {
3697c478bd9Sstevel@tonic-gate 			deriv[lev] = deriv[lev+1] = 0;
3707c478bd9Sstevel@tonic-gate 			return ((*t->p2)(ep-t->n2, t->d2, t->a2, lev));
3717c478bd9Sstevel@tonic-gate 		}
3727c478bd9Sstevel@tonic-gate 		return (0);
3737c478bd9Sstevel@tonic-gate next:;
3747c478bd9Sstevel@tonic-gate 	}
3757c478bd9Sstevel@tonic-gate 	return (0);
3767c478bd9Sstevel@tonic-gate }
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate static int
3797c478bd9Sstevel@tonic-gate nop(void)
3807c478bd9Sstevel@tonic-gate {
3817c478bd9Sstevel@tonic-gate 	return (0);
3827c478bd9Sstevel@tonic-gate }
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate /* ARGSUSED */
3857c478bd9Sstevel@tonic-gate static int
3867c478bd9Sstevel@tonic-gate strip(char *ep, char *d, char *a, int lev)
3877c478bd9Sstevel@tonic-gate {
3887c478bd9Sstevel@tonic-gate 	return (trypref(ep, a, lev)||trysuff(ep, lev));
3897c478bd9Sstevel@tonic-gate }
3907c478bd9Sstevel@tonic-gate 
3917c478bd9Sstevel@tonic-gate static int
3927c478bd9Sstevel@tonic-gate s(char *ep, char *d, char *a, int lev)
3937c478bd9Sstevel@tonic-gate {
3947c478bd9Sstevel@tonic-gate 	if (lev > DLEV+1)
3957c478bd9Sstevel@tonic-gate 		return (0);
3967c478bd9Sstevel@tonic-gate 	if (*ep == 's' && ep[-1] == 's')
3977c478bd9Sstevel@tonic-gate 		return (0);
3987c478bd9Sstevel@tonic-gate 	return (strip(ep, d, a, lev));
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate /* ARGSUSED */
4027c478bd9Sstevel@tonic-gate static int
4037c478bd9Sstevel@tonic-gate an(char *ep, char *d, char *a, int lev)
4047c478bd9Sstevel@tonic-gate {
4057c478bd9Sstevel@tonic-gate 	if (!isupper(*word))	/* must be proper name */
4067c478bd9Sstevel@tonic-gate 		return (0);
4077c478bd9Sstevel@tonic-gate 	return (trypref(ep, a, lev));
4087c478bd9Sstevel@tonic-gate }
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate /* ARGSUSED */
4117c478bd9Sstevel@tonic-gate static int
4127c478bd9Sstevel@tonic-gate ize(char *ep, char *d, char *a, int lev)
4137c478bd9Sstevel@tonic-gate {
4147c478bd9Sstevel@tonic-gate 	ep[-1] = 'e';
4157c478bd9Sstevel@tonic-gate 	return (strip(ep, "", d, lev));
4167c478bd9Sstevel@tonic-gate }
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate /* ARGSUSED */
4197c478bd9Sstevel@tonic-gate static int
4207c478bd9Sstevel@tonic-gate y_to_e(char *ep, char *d, char *a, int lev)
4217c478bd9Sstevel@tonic-gate {
4227c478bd9Sstevel@tonic-gate 	*ep++ = 'e';
4237c478bd9Sstevel@tonic-gate 	return (strip(ep, "", d, lev));
4247c478bd9Sstevel@tonic-gate }
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate static int
4277c478bd9Sstevel@tonic-gate ily(char *ep, char *d, char *a, int lev)
4287c478bd9Sstevel@tonic-gate {
4297c478bd9Sstevel@tonic-gate 	if (ep[-1] == 'i')
4307c478bd9Sstevel@tonic-gate 		return (i_to_y(ep, d, a, lev));
4317c478bd9Sstevel@tonic-gate 	else
4327c478bd9Sstevel@tonic-gate 		return (strip(ep, d, a, lev));
4337c478bd9Sstevel@tonic-gate }
4347c478bd9Sstevel@tonic-gate 
4357c478bd9Sstevel@tonic-gate static int
4367c478bd9Sstevel@tonic-gate bility(char *ep, char *d, char *a, int lev)
4377c478bd9Sstevel@tonic-gate {
4387c478bd9Sstevel@tonic-gate 	*ep++ = 'l';
4397c478bd9Sstevel@tonic-gate 	return (y_to_e(ep, d, a, lev));
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate 
4427c478bd9Sstevel@tonic-gate static int
4437c478bd9Sstevel@tonic-gate i_to_y(char *ep, char *d, char *a, int lev)
4447c478bd9Sstevel@tonic-gate {
4457c478bd9Sstevel@tonic-gate 	if (ep[-1] == 'i') {
4467c478bd9Sstevel@tonic-gate 		ep[-1] = 'y';
4477c478bd9Sstevel@tonic-gate 		a = d;
4487c478bd9Sstevel@tonic-gate 	}
4497c478bd9Sstevel@tonic-gate 	return (strip(ep, "", a, lev));
4507c478bd9Sstevel@tonic-gate }
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate static int
4537c478bd9Sstevel@tonic-gate es(char *ep, char *d, char *a, int lev)
4547c478bd9Sstevel@tonic-gate {
4557c478bd9Sstevel@tonic-gate 	if (lev > DLEV)
4567c478bd9Sstevel@tonic-gate 		return (0);
4577c478bd9Sstevel@tonic-gate 	switch (ep[-1]) {
4587c478bd9Sstevel@tonic-gate 	default:
4597c478bd9Sstevel@tonic-gate 		return (0);
4607c478bd9Sstevel@tonic-gate 	case 'i':
4617c478bd9Sstevel@tonic-gate 		return (i_to_y(ep, d, a, lev));
4627c478bd9Sstevel@tonic-gate 	case 's':
4637c478bd9Sstevel@tonic-gate 	case 'h':
4647c478bd9Sstevel@tonic-gate 	case 'z':
4657c478bd9Sstevel@tonic-gate 	case 'x':
4667c478bd9Sstevel@tonic-gate 		return (strip(ep, d, a, lev));
4677c478bd9Sstevel@tonic-gate 	}
4687c478bd9Sstevel@tonic-gate }
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate /* ARGSUSED */
4717c478bd9Sstevel@tonic-gate static int
4727c478bd9Sstevel@tonic-gate subst(char *ep, char *d, char *a, int lev)
4737c478bd9Sstevel@tonic-gate {
4747c478bd9Sstevel@tonic-gate 	char *u, *t;
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate 	if (skipv(skipv(ep-1)) < word)
4777c478bd9Sstevel@tonic-gate 		return (0);
4787c478bd9Sstevel@tonic-gate 	for (t = d; *t != '+'; t++)
4797c478bd9Sstevel@tonic-gate 		continue;
4807c478bd9Sstevel@tonic-gate 	for (u = ep; *--t != '-'; )
4817c478bd9Sstevel@tonic-gate 		*--u = *t;
4827c478bd9Sstevel@tonic-gate 	return (strip(ep, "", d, lev));
4837c478bd9Sstevel@tonic-gate }
4847c478bd9Sstevel@tonic-gate 
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate static int
4877c478bd9Sstevel@tonic-gate tion(char *ep, char *d, char *a, int lev)
4887c478bd9Sstevel@tonic-gate {
4897c478bd9Sstevel@tonic-gate 	switch (ep[-2]) {
4907c478bd9Sstevel@tonic-gate 	case 'c':
4917c478bd9Sstevel@tonic-gate 	case 'r':
4927c478bd9Sstevel@tonic-gate 		return (trypref(ep, a, lev));
4937c478bd9Sstevel@tonic-gate 	case 'a':
4947c478bd9Sstevel@tonic-gate 		return (y_to_e(ep, d, a, lev));
4957c478bd9Sstevel@tonic-gate 	}
4967c478bd9Sstevel@tonic-gate 	return (0);
4977c478bd9Sstevel@tonic-gate }
4987c478bd9Sstevel@tonic-gate 
4997c478bd9Sstevel@tonic-gate /*	possible consonant-consonant-e ending */
5007c478bd9Sstevel@tonic-gate static int
5017c478bd9Sstevel@tonic-gate CCe(char *ep, char *d, char *a, int lev)
5027c478bd9Sstevel@tonic-gate {
5037c478bd9Sstevel@tonic-gate 	switch (ep[-1]) {
5047c478bd9Sstevel@tonic-gate 	case 'r':
5057c478bd9Sstevel@tonic-gate 		if (ep[-2] == 't')
5067c478bd9Sstevel@tonic-gate 			return (y_to_e(ep, d, a, lev));
5077c478bd9Sstevel@tonic-gate 		break;
5087c478bd9Sstevel@tonic-gate 	case 'l':
5097c478bd9Sstevel@tonic-gate 		if (vowel(ep[-2]))
5107c478bd9Sstevel@tonic-gate 			break;
5117c478bd9Sstevel@tonic-gate 		switch (ep[-2]) {
5127c478bd9Sstevel@tonic-gate 		case 'l':
5137c478bd9Sstevel@tonic-gate 		case 'r':
5147c478bd9Sstevel@tonic-gate 		case 'w':
5157c478bd9Sstevel@tonic-gate 			break;
5167c478bd9Sstevel@tonic-gate 		default:
5177c478bd9Sstevel@tonic-gate 			return (y_to_e(ep, d, a, lev));
5187c478bd9Sstevel@tonic-gate 		}
5197c478bd9Sstevel@tonic-gate 		break;
5207c478bd9Sstevel@tonic-gate 	case 's':
5217c478bd9Sstevel@tonic-gate 		if (ep[-2] == 's')
5227c478bd9Sstevel@tonic-gate 			break;
5237c478bd9Sstevel@tonic-gate 		if (*ep == 'a')
5247c478bd9Sstevel@tonic-gate 			return (0);
5257c478bd9Sstevel@tonic-gate 		if (vowel(ep[-2]))
5267c478bd9Sstevel@tonic-gate 			break;
5277c478bd9Sstevel@tonic-gate 		if (y_to_e(ep, d, a, lev))
5287c478bd9Sstevel@tonic-gate 			return (1);
5297c478bd9Sstevel@tonic-gate 		if (!(ep[-2] == 'n' && ep[-1] == 'g'))
5307c478bd9Sstevel@tonic-gate 			return (0);
5317c478bd9Sstevel@tonic-gate 		break;
5327c478bd9Sstevel@tonic-gate 	case 'c':
5337c478bd9Sstevel@tonic-gate 	case 'g':
5347c478bd9Sstevel@tonic-gate 		if (*ep == 'a')
5357c478bd9Sstevel@tonic-gate 			return (0);
5367c478bd9Sstevel@tonic-gate 		if (vowel(ep[-2]))
5377c478bd9Sstevel@tonic-gate 			break;
5387c478bd9Sstevel@tonic-gate 		if (y_to_e(ep, d, a, lev))
5397c478bd9Sstevel@tonic-gate 			return (1);
5407c478bd9Sstevel@tonic-gate 		if (!(ep[-2] == 'n' && ep[-1] == 'g'))
5417c478bd9Sstevel@tonic-gate 			return (0);
5427c478bd9Sstevel@tonic-gate 		break;
5437c478bd9Sstevel@tonic-gate 	case 'v':
5447c478bd9Sstevel@tonic-gate 	case 'z':
5457c478bd9Sstevel@tonic-gate 		if (vowel(ep[-2]))
5467c478bd9Sstevel@tonic-gate 			break;
5477c478bd9Sstevel@tonic-gate 		if (y_to_e(ep, d, a, lev))
5487c478bd9Sstevel@tonic-gate 			return (1);
5497c478bd9Sstevel@tonic-gate 		if (!(ep[-2] == 'n' && ep[-1] == 'g'))
5507c478bd9Sstevel@tonic-gate 			return (0);
5517c478bd9Sstevel@tonic-gate 		break;
5527c478bd9Sstevel@tonic-gate 	case 'u':
5537c478bd9Sstevel@tonic-gate 		if (y_to_e(ep, d, a, lev))
5547c478bd9Sstevel@tonic-gate 			return (1);
5557c478bd9Sstevel@tonic-gate 		if (!(ep[-2] == 'n' && ep[-1] == 'g'))
5567c478bd9Sstevel@tonic-gate 			return (0);
5577c478bd9Sstevel@tonic-gate 		break;
5587c478bd9Sstevel@tonic-gate 	}
5597c478bd9Sstevel@tonic-gate 	return (VCe(ep, d, a, lev));
5607c478bd9Sstevel@tonic-gate }
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate /*	possible consonant-vowel-consonant-e ending */
5637c478bd9Sstevel@tonic-gate static int
5647c478bd9Sstevel@tonic-gate VCe(char *ep, char *d, char *a, int lev)
5657c478bd9Sstevel@tonic-gate {
5667c478bd9Sstevel@tonic-gate 	char c;
5677c478bd9Sstevel@tonic-gate 	c = ep[-1];
5687c478bd9Sstevel@tonic-gate 	if (c == 'e')
5697c478bd9Sstevel@tonic-gate 		return (0);
5707c478bd9Sstevel@tonic-gate 	if (!vowel(c) && vowel(ep[-2])) {
5717c478bd9Sstevel@tonic-gate 		c = *ep;
5727c478bd9Sstevel@tonic-gate 		*ep++ = 'e';
5737c478bd9Sstevel@tonic-gate 		if (trypref(ep, d, lev)||trysuff(ep, lev))
5747c478bd9Sstevel@tonic-gate 			return (1);
5757c478bd9Sstevel@tonic-gate 		ep--;
5767c478bd9Sstevel@tonic-gate 		*ep = c;
5777c478bd9Sstevel@tonic-gate 	}
5787c478bd9Sstevel@tonic-gate 	return (strip(ep, d, a, lev));
5797c478bd9Sstevel@tonic-gate }
5807c478bd9Sstevel@tonic-gate 
5817c478bd9Sstevel@tonic-gate static char *
5827c478bd9Sstevel@tonic-gate lookuppref(char **wp, char *ep)
5837c478bd9Sstevel@tonic-gate {
584*0d8b5334Sceastha 	char **sp;
585*0d8b5334Sceastha 	char *bp, *cp;
5867c478bd9Sstevel@tonic-gate 
5877c478bd9Sstevel@tonic-gate 	for (sp = preftab; *sp; sp++) {
5887c478bd9Sstevel@tonic-gate 		bp = *wp;
5897c478bd9Sstevel@tonic-gate 		for (cp = *sp; *cp; cp++, bp++)
5907c478bd9Sstevel@tonic-gate 			if (Tolower(*bp) != *cp)
5917c478bd9Sstevel@tonic-gate 				goto next;
5927c478bd9Sstevel@tonic-gate 		for (cp = bp; cp < ep; cp++)
5937c478bd9Sstevel@tonic-gate 			if (vowel(*cp)) {
5947c478bd9Sstevel@tonic-gate 				*wp = bp;
5957c478bd9Sstevel@tonic-gate 				return (*sp);
5967c478bd9Sstevel@tonic-gate 			}
5977c478bd9Sstevel@tonic-gate next:;
5987c478bd9Sstevel@tonic-gate 	}
5997c478bd9Sstevel@tonic-gate 	return (0);
6007c478bd9Sstevel@tonic-gate }
6017c478bd9Sstevel@tonic-gate 
6027c478bd9Sstevel@tonic-gate /*
6037c478bd9Sstevel@tonic-gate  *	while word is not in dictionary try stripping
6047c478bd9Sstevel@tonic-gate  *	prefixes. Fail if no more prefixes.
6057c478bd9Sstevel@tonic-gate  */
6067c478bd9Sstevel@tonic-gate static int
6077c478bd9Sstevel@tonic-gate trypref(char *ep, char *a, int lev)
6087c478bd9Sstevel@tonic-gate {
609*0d8b5334Sceastha 	char *cp;
6107c478bd9Sstevel@tonic-gate 	char *bp;
611*0d8b5334Sceastha 	char *pp;
6127c478bd9Sstevel@tonic-gate 	int val = 0;
6137c478bd9Sstevel@tonic-gate 	char space[LINE_MAX * 2];
6147c478bd9Sstevel@tonic-gate 	deriv[lev] = a;
6157c478bd9Sstevel@tonic-gate 	if (tryword(word, ep, lev))
6167c478bd9Sstevel@tonic-gate 		return (1);
6177c478bd9Sstevel@tonic-gate 	bp = word;
6187c478bd9Sstevel@tonic-gate 	pp = space;
6197c478bd9Sstevel@tonic-gate 	deriv[lev+1] = pp;
6207c478bd9Sstevel@tonic-gate 	while (cp = lookuppref(&bp, ep)) {
6217c478bd9Sstevel@tonic-gate 		*pp++ = '+';
6227c478bd9Sstevel@tonic-gate 		while (*pp = *cp++)
6237c478bd9Sstevel@tonic-gate 			pp++;
6247c478bd9Sstevel@tonic-gate 		if (tryword(bp, ep, lev+1)) {
6257c478bd9Sstevel@tonic-gate 			val = 1;
6267c478bd9Sstevel@tonic-gate 			break;
6277c478bd9Sstevel@tonic-gate 		}
6287c478bd9Sstevel@tonic-gate 	}
6297c478bd9Sstevel@tonic-gate 	deriv[lev+1] = deriv[lev+2] = 0;
6307c478bd9Sstevel@tonic-gate 	return (val);
6317c478bd9Sstevel@tonic-gate }
6327c478bd9Sstevel@tonic-gate 
6337c478bd9Sstevel@tonic-gate static int
6347c478bd9Sstevel@tonic-gate tryword(char *bp, char *ep, int lev)
6357c478bd9Sstevel@tonic-gate {
636*0d8b5334Sceastha 	int i, j;
6377c478bd9Sstevel@tonic-gate 	char duple[3];
6387c478bd9Sstevel@tonic-gate 	if (ep-bp <= 1)
6397c478bd9Sstevel@tonic-gate 		return (0);
6407c478bd9Sstevel@tonic-gate 	if (vowel(*ep)) {
6417c478bd9Sstevel@tonic-gate 		if (monosyl(bp, ep))
6427c478bd9Sstevel@tonic-gate 			return (0);
6437c478bd9Sstevel@tonic-gate 	}
6447c478bd9Sstevel@tonic-gate 	i = dict(bp, ep);
6457c478bd9Sstevel@tonic-gate 	if (i == 0 && vowel(*ep) && ep[-1] == ep[-2] && monosyl(bp, ep-1)) {
6467c478bd9Sstevel@tonic-gate 		ep--;
6477c478bd9Sstevel@tonic-gate 		deriv[++lev] = duple;
6487c478bd9Sstevel@tonic-gate 		duple[0] = '+';
6497c478bd9Sstevel@tonic-gate 		duple[1] = *ep;
6507c478bd9Sstevel@tonic-gate 		duple[2] = 0;
6517c478bd9Sstevel@tonic-gate 		i = dict(bp, ep);
6527c478bd9Sstevel@tonic-gate 	}
6537c478bd9Sstevel@tonic-gate 	if (vflag == 0 || i == 0)
6547c478bd9Sstevel@tonic-gate 		return (i);
6557c478bd9Sstevel@tonic-gate 	/*
6567c478bd9Sstevel@tonic-gate 	 *	when derivations are wanted, collect them
6577c478bd9Sstevel@tonic-gate 	 *	for printing
6587c478bd9Sstevel@tonic-gate 	 */
6597c478bd9Sstevel@tonic-gate 	j = lev;
6607c478bd9Sstevel@tonic-gate 	do {
6617c478bd9Sstevel@tonic-gate 		if (deriv[j])
6627c478bd9Sstevel@tonic-gate 			(void) strcat(affix, deriv[j]);
6637c478bd9Sstevel@tonic-gate 	} while (--j > 0);
6647c478bd9Sstevel@tonic-gate 	return (i);
6657c478bd9Sstevel@tonic-gate }
6667c478bd9Sstevel@tonic-gate 
6677c478bd9Sstevel@tonic-gate 
6687c478bd9Sstevel@tonic-gate static int
6697c478bd9Sstevel@tonic-gate monosyl(char *bp, char *ep)
6707c478bd9Sstevel@tonic-gate {
6717c478bd9Sstevel@tonic-gate 	if (ep < bp+2)
6727c478bd9Sstevel@tonic-gate 		return (0);
6737c478bd9Sstevel@tonic-gate 	if (vowel(*--ep) || !vowel(*--ep) || ep[1] == 'x' || ep[1] == 'w')
6747c478bd9Sstevel@tonic-gate 		return (0);
6757c478bd9Sstevel@tonic-gate 	while (--ep >= bp)
6767c478bd9Sstevel@tonic-gate 		if (vowel(*ep))
6777c478bd9Sstevel@tonic-gate 			return (0);
6787c478bd9Sstevel@tonic-gate 	return (1);
6797c478bd9Sstevel@tonic-gate }
6807c478bd9Sstevel@tonic-gate 
6817c478bd9Sstevel@tonic-gate static char *
6827c478bd9Sstevel@tonic-gate skipv(char *s)
6837c478bd9Sstevel@tonic-gate {
6847c478bd9Sstevel@tonic-gate 	if (s >= word&&vowel(*s))
6857c478bd9Sstevel@tonic-gate 		s--;
6867c478bd9Sstevel@tonic-gate 	while (s >= word && !vowel(*s))
6877c478bd9Sstevel@tonic-gate 		s--;
6887c478bd9Sstevel@tonic-gate 	return (s);
6897c478bd9Sstevel@tonic-gate }
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate static int
6927c478bd9Sstevel@tonic-gate vowel(int c)
6937c478bd9Sstevel@tonic-gate {
6947c478bd9Sstevel@tonic-gate 	switch (Tolower(c)) {
6957c478bd9Sstevel@tonic-gate 	case 'a':
6967c478bd9Sstevel@tonic-gate 	case 'e':
6977c478bd9Sstevel@tonic-gate 	case 'i':
6987c478bd9Sstevel@tonic-gate 	case 'o':
6997c478bd9Sstevel@tonic-gate 	case 'u':
7007c478bd9Sstevel@tonic-gate 	case 'y':
7017c478bd9Sstevel@tonic-gate 		return (1);
7027c478bd9Sstevel@tonic-gate 	}
7037c478bd9Sstevel@tonic-gate 	return (0);
7047c478bd9Sstevel@tonic-gate }
7057c478bd9Sstevel@tonic-gate 
7067c478bd9Sstevel@tonic-gate /* crummy way to Britishise */
7077c478bd9Sstevel@tonic-gate static void
7087c478bd9Sstevel@tonic-gate ise(void)
7097c478bd9Sstevel@tonic-gate {
710*0d8b5334Sceastha 	struct suftab *p;
7117c478bd9Sstevel@tonic-gate 
7127c478bd9Sstevel@tonic-gate 	for (p = suftab; p->suf; p++) {
7137c478bd9Sstevel@tonic-gate 		ztos(p->suf);
7147c478bd9Sstevel@tonic-gate 		ztos(p->d1);
7157c478bd9Sstevel@tonic-gate 		ztos(p->a1);
7167c478bd9Sstevel@tonic-gate 	}
7177c478bd9Sstevel@tonic-gate }
7187c478bd9Sstevel@tonic-gate 
7197c478bd9Sstevel@tonic-gate static void
7207c478bd9Sstevel@tonic-gate ztos(char *s)
7217c478bd9Sstevel@tonic-gate {
7227c478bd9Sstevel@tonic-gate 	for (; *s; s++)
7237c478bd9Sstevel@tonic-gate 		if (*s == 'z')
7247c478bd9Sstevel@tonic-gate 			*s = 's';
7257c478bd9Sstevel@tonic-gate }
7267c478bd9Sstevel@tonic-gate 
7277c478bd9Sstevel@tonic-gate static int
7287c478bd9Sstevel@tonic-gate dict(char *bp, char *ep)
7297c478bd9Sstevel@tonic-gate {
730*0d8b5334Sceastha 	int temp, result;
7317c478bd9Sstevel@tonic-gate 	if (xflag)
7327c478bd9Sstevel@tonic-gate 		(void) fprintf(stdout, "=%.*s\n", ep-bp, bp);
7337c478bd9Sstevel@tonic-gate 	temp = *ep;
7347c478bd9Sstevel@tonic-gate 	*ep = 0;
7357c478bd9Sstevel@tonic-gate 	result = hashlook(bp);
7367c478bd9Sstevel@tonic-gate 	*ep = temp;
7377c478bd9Sstevel@tonic-gate 	return (result);
7387c478bd9Sstevel@tonic-gate }
739