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 #pragma ident "%Z%%M% %I% %E% SMI" 16 17 #include <stdio.h> 18 #define COMNUM 500 19 #define COMTSIZE 997 20 21 char *comname = "/usr/lib/refer/eign"; 22 static int cgate = 0; 23 extern char *comname; 24 int comcount = 100; 25 static char cbuf[COMNUM*9]; 26 static char *cwds[COMTSIZE]; 27 static char *cbp; 28 29 extern int hash(); 30 extern char *trimnl(); 31 32 static void cominit(void); 33 static int c_look(char *, int); 34 35 int 36 common(char *s) 37 { 38 if (cgate == 0) cominit(); 39 return (c_look(s, 1)); 40 } 41 42 static void 43 cominit(void) 44 { 45 int i; 46 FILE *f; 47 cgate = 1; 48 f = fopen(comname, "r"); 49 if (f == NULL) 50 return; 51 cbp = cbuf; 52 for (i = 0; i < comcount; i++) { 53 if (fgets(cbp, 15, f) == NULL) 54 break; 55 trimnl(cbp); 56 c_look(cbp, 0); 57 while (*cbp++) 58 ; 59 } 60 fclose(f); 61 } 62 63 static int 64 c_look(char *s, int fl) 65 { 66 int h; 67 h = hash(s) % (COMTSIZE); 68 while (cwds[h] != 0) { 69 if (strcmp(s, cwds[h]) == 0) 70 return (1); 71 h = (h+1) % (COMTSIZE); 72 } 73 if (fl == 0) 74 cwds[h] = s; 75 return (0); 76 } 77