112309Stut #ifndef lint
2*37895Sbostic static char *sccsid = "@(#)what3.c	4.2 (Berkeley) 05/11/89";
312309Stut #endif
412309Stut 
512309Stut #include "what..c"
6*37895Sbostic #include "pathnames.h"
712309Stut 
812309Stut doclook(argc, argv, colevel)
912309Stut char *argv[];
1012309Stut {
1112309Stut 	int fpa[2], fpb[2], fpc[2], pid1, pid2, st;
1212309Stut 	int iarg;
1312309Stut 	char *s;
1412309Stut 	FILE *ansf;
1512309Stut 	struct filans *af;
1612309Stut 	struct stat statbuf;
1712309Stut # define RD 0
1812309Stut # define WR 1
1912309Stut # define fmv(x,y) close(y); dup(x); close(x);
2012309Stut 	/* we want to run chkbib and then lhunt and pipe in & out */
2112309Stut 	pipe (fpa); /* from this program to chkbib */
2212309Stut 	pipe (fpb); /* from chkbib to lhunt */
2312309Stut 	pipe (fpc); /* from lhunt to us */
2412309Stut 	if (  (pid1 = fork())  ==0)
2512309Stut 	{
2612309Stut 		fmv(fpa[RD], 0);
2712309Stut 		fmv(fpb[WR], 1);
2812309Stut 		close(fpa[WR]);
2912309Stut 		close(fpb[RD]);
3012309Stut 		close(fpc[RD]);
3112309Stut 		close(fpc[WR]);
32*37895Sbostic 		execl(_PATH_MKEY, "mkey", "-s", 0);
3312309Stut 		_assert(0);
3412309Stut 	}
3512309Stut 	if (  (pid2 = fork()) == 0)
3612309Stut 	{
3712309Stut 		char coarg[20];
3812309Stut 		sprintf(coarg, "-C%d", colevel);
3912309Stut 		fmv(fpb[RD], 0);
4012309Stut 		fmv(fpc[WR], 1);
4112309Stut 		close(fpa[RD]);
4212309Stut 		close(fpa[WR]);
4312309Stut 		close(fpb[WR]);
4412309Stut 		close(fpc[RD]);
45*37895Sbostic 		execl(_PATH_HUNT, "hunt",
4612309Stut 		/* "-P", */
47*37895Sbostic 		coarg, "-Ty", "-Fn", _PATH_ALL, 0);
4812309Stut 		_assert(0);
4912309Stut 	}
5012309Stut 	_assert (pid1 != -1);
5112309Stut 	_assert(pid2 != -1);
5212309Stut 	close(fpb[RD]);
5312309Stut 	close(fpb[WR]);
5412309Stut 	close(fpa[RD]);
5512309Stut 	close(fpc[WR]);
56*37895Sbostic 	ansf = fopen(_PATH_DEVNULL, "r");
5712309Stut 	fmv (fpc[RD], ansf->_file);
5812309Stut 	for(iarg=1; iarg<argc; iarg++)
5912309Stut 		prod(fpa[WR], argv[iarg]);
6012309Stut 	close(fpa[WR]);
6112309Stut 	s=fnames;
6212309Stut 	af=files;
6312309Stut 	while (af < files+NFILES)
6412309Stut 	{
6512309Stut 		if (fgets(af->nm=s, NAMES, ansf)==0)
6612309Stut 			break;
6712309Stut 		trimnl(s);
6812309Stut 		if (*s==0) continue;
6912309Stut 		while (*s++);
7012309Stut 		_assert(s<fnames+NAMES);
7112309Stut 		st = stat(af->nm, &statbuf);
7212309Stut 		if (st<0) continue;
7312309Stut 		af->uid = statbuf.st_uid;
7412309Stut 		af->fdate = statbuf.st_mtime;
7512309Stut 		af->size = statbuf.st_size;
7612309Stut 		af++;
7712309Stut 	}
7812309Stut 	fclose(ansf);
7912309Stut 	return(af-files);
8012309Stut }
8112309Stut 
8212309Stut prod(f,s)
8312309Stut char *s;
8412309Stut {
8512309Stut 	write (f, s, strlen(s));
8612309Stut 	write (f, "\n", 1);
8712309Stut }
88