Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/root/sys/src/cmd/refer/mkey3.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


# include "mkey.h"
char	*comname = "/lib/eign";
static int	cgate = 0;
extern char	*comname;
# define COMNUM 500
# define COMTSIZE 997
int	comcount = 100;
static char	cbuf[COMNUM*9];
static char	*cwds[COMTSIZE];
static char	*cbp;
static void	cominit(void);
static int	c_look(char *, int);

int common(char *s)
{
	if (cgate == 0) 
		cominit();
	return c_look(s, 1);
}

static void cominit(void)
{
	int i;
	FILE *f;

	cgate = 1;
	f = fopen(comname, "r");
	if (f == NULL) {
		warn(0, "can't open %s", comname);
		return;
	}
	cbp = cbuf;
	for (i = 0; i < comcount; i++) {
		if (fgets(cbp, 15, f) == NULL)
			break;
		trimnl(cbp);
		c_look(cbp, 0);
		while (*cbp++)
			;
	}
	fclose(f);
}

static int c_look(char *s, int fl)
{
	int h;

	h = hash(s) % (COMTSIZE);
	while (cwds[h] != 0) {
		if (strcmp(s, cwds[h]) == 0)
			return 1;
		h = (h + 1) % (COMTSIZE);
	}
	if (fl == 0)
		cwds[h] = s;
	return 0;
}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].