Print this page
3727 british people can't spell

@@ -18,19 +18,18 @@
  * information: Portions Copyright [yyyy] [name of copyright owner]
  *
  * CDDL HEADER END
  */
 /*
+ * Copyright 2015 Gary Mills
  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
 
 /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
 /*        All Rights Reserved   */
 
-#pragma ident   "%Z%%M% %I%     %E% SMI"
-
 #include <stdlib.h>
 #include <unistd.h>
 #include <limits.h>
 #include <string.h>
 #include <stdio.h>

@@ -56,32 +55,32 @@
 static int      strip(char *, char *, char *, int);
 static int      ize(char *, char *, char *, int);
 static int      tion(char *, char *, char *, int);
 static int      an(char *, char *, char *, int);
 int             prime(char *);
-static void     ise(void);
 static int      tryword(char *, char *, int);
 static int      trypref(char *, char *, int);
 static int      trysuff(char *, int);
 static int      vowel(int);
 static int      dict(char *, char *);
 static int      monosyl(char *, char *);
 static int      VCe(char *, char *, char *, int);
 static char     *skipv(char *);
-static void     ztos(char *);
 
-static struct suftab {
+struct suftab {
         char *suf;
         int (*p1)();
         int n1;
         char *d1;
         char *a1;
         int (*p2)();
         int n2;
         char *d2;
         char *a2;
-} suftab[] = {
+};
+
+static struct suftab sufa[] = {
         {"ssen", ily, 4, "-y+iness", "+ness" },
         {"ssel", ily, 4, "-y+i+less", "+less" },
         {"se", s, 1, "", "+s",  es, 2, "-y+ies", "+es" },
         {"s'", s, 2, "", "+'s"},
         {"s", s, 1, "", "+s"},

@@ -127,10 +126,60 @@
         {"luf", ily, 3, "-y+iful", "+ful"},
         {"ekil", strip, 4, "", "+like"},
         0
 };
 
+static struct suftab sufb[] = {
+        {"ssen", ily, 4, "-y+iness", "+ness" },
+        {"ssel", ily, 4, "-y+i+less", "+less" },
+        {"se", s, 1, "", "+s",  es, 2, "-y+ies", "+es" },
+        {"s'", s, 2, "", "+'s"},
+        {"s", s, 1, "", "+s"},
+        {"ecn", subst, 1, "-t+ce", ""},
+        {"ycn", subst, 1, "-t+cy", ""},
+        {"ytilb", nop, 0, "", ""},
+        {"ytilib", bility, 5, "-le+ility", ""},
+        {"elbaif", i_to_y, 4, "-y+iable", ""},
+        {"elba", CCe, 4, "-e+able", "+able"},
+        {"yti", CCe, 3, "-e+ity", "+ity"},
+        {"ylb", y_to_e, 1, "-e+y", ""},
+        {"yl", ily, 2, "-y+ily", "+ly"},
+        {"laci", strip, 2, "", "+al"},
+        {"latnem", strip, 2, "", "+al"},
+        {"lanoi", strip, 2, "", "+al"},
+        {"tnem", strip, 4, "", "+ment"},
+        {"gni", CCe, 3, "-e+ing", "+ing"},
+        {"reta", nop, 0, "", ""},
+        {"retc", nop, 0, "", ""},
+        {"re", strip, 1, "", "+r", i_to_y, 2, "-y+ier", "+er"},
+        {"de", strip, 1, "", "+d", i_to_y, 2, "-y+ied", "+ed"},
+        {"citsi", strip, 2, "", "+ic"},
+        {"citi", ize, 1, "-ic+e", ""},
+        {"cihparg", i_to_y, 1, "-y+ic", ""},
+        {"tse", strip, 2, "", "+st",    i_to_y, 3, "-y+iest", "+est"},
+        {"cirtem", i_to_y, 1, "-y+ic", ""},
+        {"yrtem", subst, 0, "-er+ry", ""},
+        {"cigol", i_to_y, 1, "-y+ic", ""},
+        {"tsigol", i_to_y, 2, "-y+ist", ""},
+        {"tsi", CCe, 3, "-e+ist", "+ist"},
+        {"msi", CCe, 3, "-e+ism", "+ist"},
+        {"noitacifi", i_to_y, 6, "-y+ication", ""},
+        {"noitasi", ize, 4, "-e+ation", ""},
+        {"rota", tion, 2, "-e+or", ""},
+        {"rotc", tion, 2, "", "+or"},
+        {"noit", tion, 3, "-e+ion", "+ion"},
+        {"naino", an, 3, "", "+ian"},
+        {"na", an, 1, "", "+n"},
+        {"evi", subst, 0, "-ion+ive", ""},
+        {"esi", CCe, 3, "-e+ise", "+ise"},
+        {"pihs", strip, 4, "", "+ship"},
+        {"dooh", ily, 4, "-y+ihood", "+hood"},
+        {"luf", ily, 3, "-y+iful", "+ful"},
+        {"ekil", strip, 4, "", "+like"},
+        0
+};
+
 static char *preftab[] = {
         "anti",
         "auto",
         "bio",
         "counter",

@@ -171,12 +220,14 @@
         "under",        /* must precede un */
         "un",
         0
 };
 
+static int bflag;
 static int vflag;
 static int xflag;
+static struct suftab *suftab;
 static char *prog;
 static char word[LINE_MAX];
 static char original[LINE_MAX];
 static char *deriv[LINE_MAX];
 static char affix[LINE_MAX];

@@ -251,11 +302,11 @@
 
         prog = argv[0];
         while ((c = getopt(argc, argv, "bvx")) != EOF) {
                 switch (c) {
                 case 'b':
-                        ise();
+                        bflag++;
                         break;
                 case 'v':
                         vflag++;
                         break;
                 case 'x':

@@ -273,10 +324,13 @@
                 exit(1);
         }
         argc--;
         argv++;
 
+        /* Select the correct suffix table */
+        suftab = (bflag == 0) ? sufa : sufb;
+
 /*
  *      if pass is not 1, it is assumed to be a filename.
  *      found words are written to this file.
  */
         pass = **argv;

@@ -353,16 +407,17 @@
         struct suftab   *t;
         char *cp, *sp;
 
         lev += DLEV;
         deriv[lev] = deriv[lev-1] = 0;
-        for (t = &suftab[0]; (sp = t->suf) != 0; t++) {
+        for (t = &suftab[0]; (t != 0 && (sp = t->suf) != 0); t++) {
                 cp = ep;
                 while (*sp)
                         if (*--cp != *sp++)
                                 goto next;
-                for (sp = cp; --sp >= word && !vowel(*sp); );
+                for (sp = cp; --sp >= word && !vowel(*sp); )
+                        ;
                 if (sp < word)
                         return (0);
                 if ((*t->p1)(ep-t->n1, t->d1, t->a1, lev+1))
                         return (1);
                 if (t->p2 != 0) {

@@ -701,31 +756,10 @@
                 return (1);
         }
         return (0);
 }
 
-/* crummy way to Britishise */
-static void
-ise(void)
-{
-        struct suftab *p;
-
-        for (p = suftab; p->suf; p++) {
-                ztos(p->suf);
-                ztos(p->d1);
-                ztos(p->a1);
-        }
-}
-
-static void
-ztos(char *s)
-{
-        for (; *s; s++)
-                if (*s == 'z')
-                        *s = 's';
-}
-
 static int
 dict(char *bp, char *ep)
 {
         int temp, result;
         if (xflag)