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