BSD 3 development
[unix-history] / usr / src / cmd / spell / spellin.c
CommitLineData
42d6e430
BJ
1#include "spell.h"
2/* add entries to hash table for use by spell
3 preexisting hash table is first argument
4 words to be added are standard input
5 if no hash table is given, create one from scratch
6*/
7
8main(argc,argv)
9char **argv;
10{
11 register i, j;
12 long h;
13 register long *lp;
14 char word[NW];
15 register char *wp;
16
17 if(!prime(argc,argv)) {
18 fprintf(stderr,
19 "spellin: cannot initialize hash table\n");
20 exit(1);
21 }
22 while (fgets(word, sizeof(word), stdin)) {
23 for (i=0; i<NP; i++) {
24 for (wp = word, h = 0, lp = pow2[i];
25 (j = *wp) != '\0'; ++wp, ++lp)
26 h += j * *lp;
27 h %= p[i];
28 set(h);
29 }
30 }
31#ifdef gcos
32 freopen((char *)NULL, "wi", stdout);
33#endif
34 if (fwrite((char *)tab, sizeof(*tab), TABSIZE, stdout) != TABSIZE) {
35 fprintf(stderr,
36 "spellin: trouble writing hash table\n");
37 exit(1);
38 }
39 return(0);
40}