xref: /titanic_52/usr/src/cmd/refer/mkey3.c (revision 1a7c1b724419d3cb5fa6eea75123c6b2060ba31b)
1 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
2 /*	  All Rights Reserved  	*/
3 
4 
5 /*
6  * Copyright (c) 1980 Regents of the University of California.
7  * All rights reserved. The Berkeley software License Agreement
8  * specifies the terms and conditions for redistribution.
9  */
10 
11 /*
12  * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13  * All Rights Reserved.
14  */
15 
16 #pragma ident	"%Z%%M%	%I%	%E% SMI"
17 
18 #include <stdio.h>
19 #define COMNUM 500
20 #define COMTSIZE 997
21 
22 char *comname = "/usr/lib/refer/eign";
23 static int cgate = 0;
24 extern char *comname;
25 int comcount = 100;
26 static char cbuf[COMNUM*9];
27 static char *cwds[COMTSIZE];
28 static char *cbp;
29 
30 common (s)
31 char *s;
32 {
33 	if (cgate==0) cominit();
34 	return (c_look(s, 1));
35 }
36 
37 cominit()
38 {
39 	int i;
40 	FILE *f;
41 	cgate=1;
42 	f = fopen(comname, "r");
43 	if (f==NULL) return;
44 	cbp=cbuf;
45 	for(i=0; i<comcount; i++)
46 	{
47 		if (fgets(cbp, 15, f)==NULL)
48 			break;
49 		trimnl(cbp);
50 		c_look (cbp, 0);
51 		while (*cbp++);
52 	}
53 	fclose(f);
54 }
55 
56 c_look (s, fl)
57 char *s;
58 {
59 	int h;
60 	h = hash(s) % (COMTSIZE);
61 	while (cwds[h] != 0)
62 	{
63 		if (strcmp(s, cwds[h])==0)
64 			return(1);
65 		h = (h+1) % (COMTSIZE);
66 	}
67 	if (fl==0)
68 		cwds[h] = s;
69 	return(0);
70 }
71