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