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