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