xref: /original-bsd/old/refer/mkey/mkey3.c (revision ca3b5b26)
1 #ifndef lint
2 static char *sccsid = "@(#)mkey3.c	4.2 (Berkeley) 05/11/89";
3 #endif
4 
5 #include <stdio.h>
6 #include "pathnames.h"
7 
8 #define COMNUM 500
9 #define COMTSIZE 997
10 
11 char *comname = _PATH_EIGN;
12 static int cgate = 0;
13 extern char *comname;
14 int comcount = 100;
15 static char cbuf[COMNUM*9];
16 static char *cwds[COMTSIZE];
17 static char *cbp;
18 
19 common (s)
20 char *s;
21 {
22 	if (cgate==0) cominit();
23 	return (c_look(s, 1));
24 }
25 
26 cominit()
27 {
28 	int i;
29 	FILE *f;
30 	cgate=1;
31 	f = fopen(comname, "r");
32 	if (f==NULL) return;
33 	cbp=cbuf;
34 	for(i=0; i<comcount; i++)
35 	{
36 		if (fgets(cbp, 15, f)==NULL)
37 			break;
38 		trimnl(cbp);
39 		c_look (cbp, 0);
40 		while (*cbp++);
41 	}
42 	fclose(f);
43 }
44 
45 c_look (s, fl)
46 char *s;
47 {
48 	int h;
49 	h = hash(s) % (COMTSIZE);
50 	while (cwds[h] != 0)
51 	{
52 		if (strcmp(s, cwds[h])==0)
53 			return(1);
54 		h = (h+1) % (COMTSIZE);
55 	}
56 	if (fl==0)
57 		cwds[h] = s;
58 	return(0);
59 }
60