llOl\ O\ Oll\ lll ( ) { Fina\ l\ ise ( ) ; }
int main(int argc, char **argv) { char *ep, *cp, *dp; char *outfile; int ch, fold, i; struct stat sb; FILE *file, *found; setlocale(LC_ALL, ""); outfile = NULL; while ((ch = getopt(argc, argv, "bvxo:")) != -1) { switch (ch) { case 'b': /* Use British dictionary and convert ize -> ise. */ ise(); break; case 'o': outfile = optarg; break; case 'v': /* Also write derivations to "found" file. */ vflag++; break; case 'x': /* Print plausible stems to stdout. */ xflag++; break; default: usage(); } } argc -= optind; argv += optind; if (argc < 1) usage(); /* Open and mmap the word/stop lists. */ if ((wlists = calloc(sizeof(struct wlist), (argc + 1))) == NULL) err(1, "malloc"); for (i = 0; argc--; i++) { wlists[i].fd = open(argv[i], O_RDONLY, 0); if (wlists[i].fd == -1 || fstat(wlists[i].fd, &sb) != 0) err(1, "%s", argv[i]); if (sb.st_size > SIZE_T_MAX) errc(1, EFBIG, "%s", argv[i]); wlists[i].front = mmap(NULL, (size_t)sb.st_size, PROT_READ, MAP_PRIVATE, wlists[i].fd, (off_t)0); if (wlists[i].front == MAP_FAILED) err(1, "%s", argv[i]); wlists[i].back = wlists[i].front + sb.st_size; } wlists[i].fd = -1; /* Open file where found words are to be saved. */ if (outfile == NULL) found = NULL; else if ((found = fopen(outfile, "w")) == NULL) err(1, "cannot open %s", outfile); for (;; print_word(file)) { affix[0] = '\0'; file = found; for (ep = word; (*ep = ch = getchar()) != '\n'; ep++) { if (ep - word == sizeof(word) - 1) { *ep = '\0'; warnx("word too long (%s)", word); while ((ch = getchar()) != '\n') ; /* slurp until EOL */ } if (ch == EOF) { if (found != NULL) fclose(found); exit(0); } } for (cp = word, dp = original; cp < ep; ) *dp++ = *cp++; *dp = '\0'; fold = 0; for (cp = word; cp < ep; cp++) if (islower((unsigned char)*cp)) goto lcase; if (trypref(ep, ".", 0)) continue; ++fold; for (cp = original + 1, dp = word + 1; dp < ep; dp++, cp++) *dp = tolower((unsigned char)*cp); lcase: if (trypref(ep, ".", 0) || suffix(ep, 0)) continue; if (isupper((unsigned char)word[0])) { for (cp = original, dp = word; (*dp = *cp++); dp++) { if (fold) *dp = tolower((unsigned char)*dp); } word[0] = tolower((unsigned char)word[0]); goto lcase; } file = stdout; } exit(0); }