Print this page
3727 british people can't spell

Split Close
Expand all
Collapse all
          --- old/usr/src/cmd/spell/spellprog.c
          +++ new/usr/src/cmd/spell/spellprog.c
↓ open down ↓ 12 lines elided ↑ open up ↑
  13   13   *
  14   14   * When distributing Covered Code, include this CDDL HEADER in each
  15   15   * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  16   16   * If applicable, add the following below this CDDL HEADER, with the
  17   17   * fields enclosed by brackets "[]" replaced with your own identifying
  18   18   * information: Portions Copyright [yyyy] [name of copyright owner]
  19   19   *
  20   20   * CDDL HEADER END
  21   21   */
  22   22  /*
       23 + * Copyright 2015 Gary Mills
  23   24   * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
  24   25   * Use is subject to license terms.
  25   26   */
  26   27  
  27   28  /*      Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
  28   29  /*        All Rights Reserved   */
  29   30  
  30      -#pragma ident   "%Z%%M% %I%     %E% SMI"
  31      -
  32   31  #include <stdlib.h>
  33   32  #include <unistd.h>
  34   33  #include <limits.h>
  35   34  #include <string.h>
  36   35  #include <stdio.h>
  37   36  #include <ctype.h>
  38   37  #include <locale.h>
  39   38  #include "hash.h"
  40   39  
  41   40  #define Tolower(c) (isupper(c)?tolower(c):c)
↓ open down ↓ 9 lines elided ↑ open up ↑
  51   50  static int      nop(void);
  52   51  static int      bility(char *, char *, char *, int);
  53   52  static int      i_to_y(char *, char *, char *, int);
  54   53  static int      CCe(char *, char *, char *, int);
  55   54  static int      y_to_e(char *, char *, char *, int);
  56   55  static int      strip(char *, char *, char *, int);
  57   56  static int      ize(char *, char *, char *, int);
  58   57  static int      tion(char *, char *, char *, int);
  59   58  static int      an(char *, char *, char *, int);
  60   59  int             prime(char *);
  61      -static void     ise(void);
  62   60  static int      tryword(char *, char *, int);
  63   61  static int      trypref(char *, char *, int);
  64   62  static int      trysuff(char *, int);
  65   63  static int      vowel(int);
  66   64  static int      dict(char *, char *);
  67   65  static int      monosyl(char *, char *);
  68   66  static int      VCe(char *, char *, char *, int);
  69   67  static char     *skipv(char *);
  70      -static void     ztos(char *);
  71   68  
  72      -static struct suftab {
       69 +struct suftab {
  73   70          char *suf;
  74   71          int (*p1)();
  75   72          int n1;
  76   73          char *d1;
  77   74          char *a1;
  78   75          int (*p2)();
  79   76          int n2;
  80   77          char *d2;
  81   78          char *a2;
  82      -} suftab[] = {
       79 +};
       80 +
       81 +static struct suftab sufa[] = {
  83   82          {"ssen", ily, 4, "-y+iness", "+ness" },
  84   83          {"ssel", ily, 4, "-y+i+less", "+less" },
  85   84          {"se", s, 1, "", "+s",  es, 2, "-y+ies", "+es" },
  86   85          {"s'", s, 2, "", "+'s"},
  87   86          {"s", s, 1, "", "+s"},
  88   87          {"ecn", subst, 1, "-t+ce", ""},
  89   88          {"ycn", subst, 1, "-t+cy", ""},
  90   89          {"ytilb", nop, 0, "", ""},
  91   90          {"ytilib", bility, 5, "-le+ility", ""},
  92   91          {"elbaif", i_to_y, 4, "-y+iable", ""},
↓ open down ↓ 29 lines elided ↑ open up ↑
 122  121          {"na", an, 1, "", "+n"},
 123  122          {"evi", subst, 0, "-ion+ive", ""},
 124  123          {"ezi", CCe, 3, "-e+ize", "+ize"},
 125  124          {"pihs", strip, 4, "", "+ship"},
 126  125          {"dooh", ily, 4, "-y+ihood", "+hood"},
 127  126          {"luf", ily, 3, "-y+iful", "+ful"},
 128  127          {"ekil", strip, 4, "", "+like"},
 129  128          0
 130  129  };
 131  130  
      131 +static struct suftab sufb[] = {
      132 +        {"ssen", ily, 4, "-y+iness", "+ness" },
      133 +        {"ssel", ily, 4, "-y+i+less", "+less" },
      134 +        {"se", s, 1, "", "+s",  es, 2, "-y+ies", "+es" },
      135 +        {"s'", s, 2, "", "+'s"},
      136 +        {"s", s, 1, "", "+s"},
      137 +        {"ecn", subst, 1, "-t+ce", ""},
      138 +        {"ycn", subst, 1, "-t+cy", ""},
      139 +        {"ytilb", nop, 0, "", ""},
      140 +        {"ytilib", bility, 5, "-le+ility", ""},
      141 +        {"elbaif", i_to_y, 4, "-y+iable", ""},
      142 +        {"elba", CCe, 4, "-e+able", "+able"},
      143 +        {"yti", CCe, 3, "-e+ity", "+ity"},
      144 +        {"ylb", y_to_e, 1, "-e+y", ""},
      145 +        {"yl", ily, 2, "-y+ily", "+ly"},
      146 +        {"laci", strip, 2, "", "+al"},
      147 +        {"latnem", strip, 2, "", "+al"},
      148 +        {"lanoi", strip, 2, "", "+al"},
      149 +        {"tnem", strip, 4, "", "+ment"},
      150 +        {"gni", CCe, 3, "-e+ing", "+ing"},
      151 +        {"reta", nop, 0, "", ""},
      152 +        {"retc", nop, 0, "", ""},
      153 +        {"re", strip, 1, "", "+r", i_to_y, 2, "-y+ier", "+er"},
      154 +        {"de", strip, 1, "", "+d", i_to_y, 2, "-y+ied", "+ed"},
      155 +        {"citsi", strip, 2, "", "+ic"},
      156 +        {"citi", ize, 1, "-ic+e", ""},
      157 +        {"cihparg", i_to_y, 1, "-y+ic", ""},
      158 +        {"tse", strip, 2, "", "+st",    i_to_y, 3, "-y+iest", "+est"},
      159 +        {"cirtem", i_to_y, 1, "-y+ic", ""},
      160 +        {"yrtem", subst, 0, "-er+ry", ""},
      161 +        {"cigol", i_to_y, 1, "-y+ic", ""},
      162 +        {"tsigol", i_to_y, 2, "-y+ist", ""},
      163 +        {"tsi", CCe, 3, "-e+ist", "+ist"},
      164 +        {"msi", CCe, 3, "-e+ism", "+ist"},
      165 +        {"noitacifi", i_to_y, 6, "-y+ication", ""},
      166 +        {"noitasi", ize, 4, "-e+ation", ""},
      167 +        {"rota", tion, 2, "-e+or", ""},
      168 +        {"rotc", tion, 2, "", "+or"},
      169 +        {"noit", tion, 3, "-e+ion", "+ion"},
      170 +        {"naino", an, 3, "", "+ian"},
      171 +        {"na", an, 1, "", "+n"},
      172 +        {"evi", subst, 0, "-ion+ive", ""},
      173 +        {"esi", CCe, 3, "-e+ise", "+ise"},
      174 +        {"pihs", strip, 4, "", "+ship"},
      175 +        {"dooh", ily, 4, "-y+ihood", "+hood"},
      176 +        {"luf", ily, 3, "-y+iful", "+ful"},
      177 +        {"ekil", strip, 4, "", "+like"},
      178 +        0
      179 +};
      180 +
 132  181  static char *preftab[] = {
 133  182          "anti",
 134  183          "auto",
 135  184          "bio",
 136  185          "counter",
 137  186          "dis",
 138  187          "electro",
 139  188          "en",
 140  189          "fore",
 141  190          "geo",
↓ open down ↓ 24 lines elided ↑ open up ↑
 166  215          "sub",
 167  216          "super",
 168  217          "tele",
 169  218          "thermo",
 170  219          "ultra",
 171  220          "under",        /* must precede un */
 172  221          "un",
 173  222          0
 174  223  };
 175  224  
      225 +static int bflag;
 176  226  static int vflag;
 177  227  static int xflag;
      228 +static struct suftab *suftab;
 178  229  static char *prog;
 179  230  static char word[LINE_MAX];
 180  231  static char original[LINE_MAX];
 181  232  static char *deriv[LINE_MAX];
 182  233  static char affix[LINE_MAX];
 183  234  static FILE *file, *found;
 184  235  /*
 185  236   *      deriv is stack of pointers to notes like +micro +ed
 186  237   *      affix is concatenated string of notes
 187  238   *      the buffer size 141 stems from the sizes of original and affix.
↓ open down ↓ 58 lines elided ↑ open up ↑
 246  297  #if !defined(TEXT_DOMAIN)       /* Should be defined by cc -D */
 247  298  #define TEXT_DOMAIN "SYS_TEST"  /* Use this only if it wasn't */
 248  299  #endif
 249  300          (void) textdomain(TEXT_DOMAIN);
 250  301  
 251  302  
 252  303          prog = argv[0];
 253  304          while ((c = getopt(argc, argv, "bvx")) != EOF) {
 254  305                  switch (c) {
 255  306                  case 'b':
 256      -                        ise();
      307 +                        bflag++;
 257  308                          break;
 258  309                  case 'v':
 259  310                          vflag++;
 260  311                          break;
 261  312                  case 'x':
 262  313                          xflag++;
 263  314                          break;
 264  315                  }
 265  316          }
 266  317  
↓ open down ↓ 1 lines elided ↑ open up ↑
 268  319          argv = &argv[optind];
 269  320  
 270  321          if ((argc < 2) || !prime(*argv)) {
 271  322                  (void) fprintf(stderr,
 272  323                      gettext("%s: cannot initialize hash table\n"), prog);
 273  324                  exit(1);
 274  325          }
 275  326          argc--;
 276  327          argv++;
 277  328  
      329 +        /* Select the correct suffix table */
      330 +        suftab = (bflag == 0) ? sufa : sufb;
      331 +
 278  332  /*
 279  333   *      if pass is not 1, it is assumed to be a filename.
 280  334   *      found words are written to this file.
 281  335   */
 282  336          pass = **argv;
 283  337          if (pass != '1')
 284  338                  found = fopen(*argv, "w");
 285  339  
 286  340          for (;;) {
 287  341                  affix[0] = 0;
↓ open down ↓ 60 lines elided ↑ open up ↑
 348  402   */
 349  403  
 350  404  static int
 351  405  trysuff(char *ep, int lev)
 352  406  {
 353  407          struct suftab   *t;
 354  408          char *cp, *sp;
 355  409  
 356  410          lev += DLEV;
 357  411          deriv[lev] = deriv[lev-1] = 0;
 358      -        for (t = &suftab[0]; (sp = t->suf) != 0; t++) {
      412 +        for (t = &suftab[0]; (t != 0 && (sp = t->suf) != 0); t++) {
 359  413                  cp = ep;
 360  414                  while (*sp)
 361  415                          if (*--cp != *sp++)
 362  416                                  goto next;
 363      -                for (sp = cp; --sp >= word && !vowel(*sp); );
      417 +                for (sp = cp; --sp >= word && !vowel(*sp); )
      418 +                        ;
 364  419                  if (sp < word)
 365  420                          return (0);
 366  421                  if ((*t->p1)(ep-t->n1, t->d1, t->a1, lev+1))
 367  422                          return (1);
 368  423                  if (t->p2 != 0) {
 369  424                          deriv[lev] = deriv[lev+1] = 0;
 370  425                          return ((*t->p2)(ep-t->n2, t->d2, t->a2, lev));
 371  426                  }
 372  427                  return (0);
 373  428  next:;
↓ open down ↓ 322 lines elided ↑ open up ↑
 696  751          case 'e':
 697  752          case 'i':
 698  753          case 'o':
 699  754          case 'u':
 700  755          case 'y':
 701  756                  return (1);
 702  757          }
 703  758          return (0);
 704  759  }
 705  760  
 706      -/* crummy way to Britishise */
 707      -static void
 708      -ise(void)
 709      -{
 710      -        struct suftab *p;
 711      -
 712      -        for (p = suftab; p->suf; p++) {
 713      -                ztos(p->suf);
 714      -                ztos(p->d1);
 715      -                ztos(p->a1);
 716      -        }
 717      -}
 718      -
 719      -static void
 720      -ztos(char *s)
 721      -{
 722      -        for (; *s; s++)
 723      -                if (*s == 'z')
 724      -                        *s = 's';
 725      -}
 726      -
 727  761  static int
 728  762  dict(char *bp, char *ep)
 729  763  {
 730  764          int temp, result;
 731  765          if (xflag)
 732  766                  (void) fprintf(stdout, "=%.*s\n", ep-bp, bp);
 733  767          temp = *ep;
 734  768          *ep = 0;
 735  769          result = hashlook(bp);
 736  770          *ep = temp;
 737  771          return (result);
 738  772  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX