xref: /original-bsd/usr.bin/spell/spellout.c (revision c3e32dec)
1 /*-
2  * Copyright (c) 1991, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.proprietary.c%
6  */
7 
8 #ifndef lint
9 static char copyright[] =
10 "@(#) Copyright (c) 1991, 1993\n\
11 	The Regents of the University of California.  All rights reserved.\n";
12 #endif /* not lint */
13 
14 #ifndef lint
15 static char sccsid[] = "@(#)spellout.c	8.1 (Berkeley) 06/06/93";
16 #endif /* not lint */
17 
18 #include "spell.h"
19 
20 main(argc, argv)
21 int argc;
22 char **argv;
23 {
24 	register i, j;
25 	long h;
26 	register long *lp;
27 	char word[NW];
28 	int dflag = 0;
29 	int indict;
30 	register char *wp;
31 
32 	if (argc>1 && argv[1][0]=='-' && argv[1][1]=='d') {
33 		dflag = 1;
34 		argc--;
35 		argv++;
36 	}
37 	if(argc<=1) {
38 		fprintf(stderr,"spellout: arg count\n");
39 		exit(1);
40 	}
41 	if(!prime(argc,argv)) {
42 		fprintf(stderr,
43 		    "spellout: cannot initialize hash table\n");
44 		exit(1);
45 	}
46 	while (fgets(word, sizeof(word), stdin)) {
47 		indict = 1;
48 		for (i=0; i<NP; i++) {
49 			for (wp = word, h = 0, lp = pow2[i];
50 				(j = *wp) != '\0'; ++wp, ++lp)
51 				h += j * *lp;
52 			h %= p[i];
53 			if (get(h)==0) {
54 				indict = 0;
55 				break;
56 			}
57 		}
58 		if (dflag == indict)
59 			fputs(word, stdout);
60 	}
61 }
62