xref: /titanic_50/usr/src/cmd/refer/mkey3.c (revision 11a8fa6cb17403e630122ac19b39a323c6e64142)
1*11a8fa6cSceastha /*
2*11a8fa6cSceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*11a8fa6cSceastha  * Use is subject to license terms.
4*11a8fa6cSceastha  */
5*11a8fa6cSceastha 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
167c478bd9Sstevel@tonic-gate 
177c478bd9Sstevel@tonic-gate #include <stdio.h>
187c478bd9Sstevel@tonic-gate #define	COMNUM 500
197c478bd9Sstevel@tonic-gate #define	COMTSIZE 997
207c478bd9Sstevel@tonic-gate 
217c478bd9Sstevel@tonic-gate char *comname = "/usr/lib/refer/eign";
227c478bd9Sstevel@tonic-gate static int cgate = 0;
237c478bd9Sstevel@tonic-gate extern char *comname;
247c478bd9Sstevel@tonic-gate int comcount = 100;
257c478bd9Sstevel@tonic-gate static char cbuf[COMNUM*9];
267c478bd9Sstevel@tonic-gate static char *cwds[COMTSIZE];
277c478bd9Sstevel@tonic-gate static char *cbp;
287c478bd9Sstevel@tonic-gate 
29*11a8fa6cSceastha extern int hash();
30*11a8fa6cSceastha extern char *trimnl();
31*11a8fa6cSceastha 
32*11a8fa6cSceastha static void cominit(void);
33*11a8fa6cSceastha static int c_look(char *, int);
34*11a8fa6cSceastha 
35*11a8fa6cSceastha int
common(char * s)36*11a8fa6cSceastha common(char *s)
377c478bd9Sstevel@tonic-gate {
387c478bd9Sstevel@tonic-gate 	if (cgate == 0) cominit();
397c478bd9Sstevel@tonic-gate 	return (c_look(s, 1));
407c478bd9Sstevel@tonic-gate }
417c478bd9Sstevel@tonic-gate 
42*11a8fa6cSceastha static void
cominit(void)43*11a8fa6cSceastha cominit(void)
447c478bd9Sstevel@tonic-gate {
457c478bd9Sstevel@tonic-gate 	int i;
467c478bd9Sstevel@tonic-gate 	FILE *f;
477c478bd9Sstevel@tonic-gate 	cgate = 1;
487c478bd9Sstevel@tonic-gate 	f = fopen(comname, "r");
49*11a8fa6cSceastha 	if (f == NULL)
50*11a8fa6cSceastha 		return;
517c478bd9Sstevel@tonic-gate 	cbp = cbuf;
52*11a8fa6cSceastha 	for (i = 0; i < comcount; i++) {
537c478bd9Sstevel@tonic-gate 		if (fgets(cbp, 15, f) == NULL)
547c478bd9Sstevel@tonic-gate 			break;
557c478bd9Sstevel@tonic-gate 		trimnl(cbp);
567c478bd9Sstevel@tonic-gate 		c_look(cbp, 0);
57*11a8fa6cSceastha 		while (*cbp++)
58*11a8fa6cSceastha 			;
597c478bd9Sstevel@tonic-gate 	}
607c478bd9Sstevel@tonic-gate 	fclose(f);
617c478bd9Sstevel@tonic-gate }
627c478bd9Sstevel@tonic-gate 
63*11a8fa6cSceastha static int
c_look(char * s,int fl)64*11a8fa6cSceastha c_look(char *s, int fl)
657c478bd9Sstevel@tonic-gate {
667c478bd9Sstevel@tonic-gate 	int h;
677c478bd9Sstevel@tonic-gate 	h = hash(s) % (COMTSIZE);
68*11a8fa6cSceastha 	while (cwds[h] != 0) {
697c478bd9Sstevel@tonic-gate 		if (strcmp(s, cwds[h]) == 0)
707c478bd9Sstevel@tonic-gate 			return (1);
717c478bd9Sstevel@tonic-gate 		h = (h+1) % (COMTSIZE);
727c478bd9Sstevel@tonic-gate 	}
737c478bd9Sstevel@tonic-gate 	if (fl == 0)
747c478bd9Sstevel@tonic-gate 		cwds[h] = s;
757c478bd9Sstevel@tonic-gate 	return (0);
767c478bd9Sstevel@tonic-gate }
77