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

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


#include "inv.h"

int newkeys(FILE *outf, FILE *inf, FILE *recf, int nhash, FILE *fd)
{
/* reads key lines from inf; hashes and writes on outf; writes orig
   key on recf, records pointer on outf too.
   format of outf is : hash code space record pointer
*/

	long	lp;
	long	ld = 0; 
	int	ll, lt = 0;
	char	bkeys[40];
	char	*p, *line;
	int	i, ndoc = 0;
	static Alist keyv;

	lp = ftell(recf);
	while ((line = getln(inf)) != 0) {
		if ((p = strchr(line, '\t')) != 0)
			*p++ = '\0';
		else
			err("wrong input format for inv");
		fputs(line, recf);
		if (fd) {
			sprintf(bkeys, ";%ld", ld);
			ll = strlen(p);
			lt = strlen(bkeys);
			fputs(bkeys, recf);
			sprintf(bkeys, ",%d", ll);
			lt += strlen(bkeys);
			fputs(bkeys, recf);
			ld += ll;
			fputs(p, fd);
		}
		putc('\n', recf);
		getargs(p, &keyv);
		for (i = 0; i < keyv.n; i++)
			fprintf(outf, "%.5d %.9ld\n", hash(keyv.lp[i]) % nhash, lp);
# if D1
		for (i = 0; i < keyv.n; i++)
			printf("key %s hash %d offs %ld\n", keyv.lp[i], hash(keyv.lp[i]) % nhash, lp);
# endif
		lp += (strlen(line) + lt + 1);
		ndoc++;
	}
	fclose(recf);
	return ndoc;
}

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].