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

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


# include "stdio.h"
# include "error.h"
#include "refer.h"

Builtin	builtins[] = {{0}};	/* no built-in commands to corout */

FILE	*fd = NULL;
int	colevel = 0;
int	soutlen = 1000;
int	reached = 0;
int	prfreqs = 0;
char	usedir[100];
char	*referlib = "/bin/refer";
char	gfile[50];
static int	full = 1000;
static int	tags = 0;
char	*sinput, *soutput, *tagout;
long	indexdate = 0;

#define MAXOUT 32767

void
main(int argc, char **argv)
{
	/* read query from stdin, expect name of indexes in argv[1] */
	static FILE *fa, *fb, *fc;
	char	nma[100], nmb[100], nmc[100], *qitem[NITEM], *rprog = 0;
	char	nmd[100];
	static char	oldname[DIRLEN] ;
	static int	was = 0;
	List	*drops;
	int	alldrops = 0, nitem;
	Index ind;

	/* special wart for refpart: default is tags only */

	progname = mkprogname(argv[0]);
	drops = 0;
	initindex(&ind);
	for (; argc > 1 && argv[1][0] == '-'; argc--, argv++) {
		switch (argv[1][1]) {
		case 'a': /* all output, incl. false drops */
			alldrops = 1; 
			break;
		case 'r':
			argc--; 
			argv++;
			rprog = argv[1];
			break;
		case 'F': /* put out full text */
			full = setfrom(argv[1][2]);
			break;
		case 'T': /* put out tags */
			tags = setfrom(argv[1][2]);
			break;
		case 'i': /* input in argument string */
			argc--; 
			argv++;
			sinput = argv[1];
			break;
		case 's': /*text output to string */
		case 'o':
			argc--; 
			argv++;
			soutput = argv[1];
			if ((int)argv[2] < 16000) {
				soutlen = (int)argv[2];
				argc--; 
				argv++;
			}
			break;
		case 't': /*tag output to string */
			argc--; 
			argv++;
			tagout = argv[1];
			break;
		case 'l': /* length of internal lists */
			argc--; 
			argv++;
			break;
		case 'g': /* suppress fgrep search on old files */
			break;
		case 'C': /* coordination level */
			colevel = atoi(argv[1] + 2);
# if D1
			fprintf(stderr, "colevel set to %d\n", colevel);
#endif
			break;
		case 'P': /* print term freqs */
			prfreqs = 1; 
			break;
		}
	}
	strcpy (nma, todir(argv[1]));
	if (was == 0 || strcmp (oldname, nma) != 0) {
		strcpy (oldname, nma);
		strcpy (nmb, nma); 
		strcpy (nmc, nmb); 
		strcpy(nmd, nma);
		strcat (nma, ".ia");
		strcat (nmb, ".ib");
		strcat (nmc, ".ic");
		strcat (nmd, ".id");
		if (was) {
			fclose(fa); 
			fclose(fb); 
			fclose(fc);
		}

		fa = fopen(nma, "r");
		if (fa == NULL)
			err("can't find index files %s.i[abc] - run pubindex", oldname);
		fb = fopen(nmb, "r");
		fc = fopen(nmc, "r");
		was = 1;
		if (fb == NULL || fc == NULL) {
			err("Index incomplete %s", nmb);
			exit(1);
		}
		indexdate = gdate(fb);
		fd = fopen(nmd, "r");
	}
	xseek(fa, 0, 0);
	getindex(&ind, fa);
	for (;;) {
		nitem = getq(qitem, NITEM);
		if (nitem == 0) 
			continue;
		if (nitem < 0) 
			break;
		if (tagout) 
			tagout[0] = 0;
		if (fb != NULL) {
			drops = doquery(&ind, fb, nitem, qitem);
# if D1
			fprintf(stderr, "after doquery nfound %d\n", nfound);
#endif
			if (!alldrops)
				dropout(drops, fc, nitem, qitem, rprog, full);
# if D1
			fprintf(stderr, "after dropout nfound %d\n", drops->n);
#endif
		}
		if (tags && drops)
			result(drops, tags, fc);
	}
	exit(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 webmaster@9p.io.