1 /*- 2 * %sccs.include.proprietary.c% 3 */ 4 5 #ifndef lint 6 static char sccsid[] = "@(#)what3.c 4.3 (Berkeley) 04/18/91"; 7 #endif /* not lint */ 8 9 #include "what..c" 10 #include "pathnames.h" 11 12 doclook(argc, argv, colevel) 13 char *argv[]; 14 { 15 int fpa[2], fpb[2], fpc[2], pid1, pid2, st; 16 int iarg; 17 char *s; 18 FILE *ansf; 19 struct filans *af; 20 struct stat statbuf; 21 # define RD 0 22 # define WR 1 23 # define fmv(x,y) close(y); dup(x); close(x); 24 /* we want to run chkbib and then lhunt and pipe in & out */ 25 pipe (fpa); /* from this program to chkbib */ 26 pipe (fpb); /* from chkbib to lhunt */ 27 pipe (fpc); /* from lhunt to us */ 28 if ( (pid1 = fork()) ==0) 29 { 30 fmv(fpa[RD], 0); 31 fmv(fpb[WR], 1); 32 close(fpa[WR]); 33 close(fpb[RD]); 34 close(fpc[RD]); 35 close(fpc[WR]); 36 execl(_PATH_MKEY, "mkey", "-s", 0); 37 _assert(0); 38 } 39 if ( (pid2 = fork()) == 0) 40 { 41 char coarg[20]; 42 sprintf(coarg, "-C%d", colevel); 43 fmv(fpb[RD], 0); 44 fmv(fpc[WR], 1); 45 close(fpa[RD]); 46 close(fpa[WR]); 47 close(fpb[WR]); 48 close(fpc[RD]); 49 execl(_PATH_HUNT, "hunt", 50 /* "-P", */ 51 coarg, "-Ty", "-Fn", _PATH_ALL, 0); 52 _assert(0); 53 } 54 _assert (pid1 != -1); 55 _assert(pid2 != -1); 56 close(fpb[RD]); 57 close(fpb[WR]); 58 close(fpa[RD]); 59 close(fpc[WR]); 60 ansf = fopen(_PATH_DEVNULL, "r"); 61 fmv (fpc[RD], ansf->_file); 62 for(iarg=1; iarg<argc; iarg++) 63 prod(fpa[WR], argv[iarg]); 64 close(fpa[WR]); 65 s=fnames; 66 af=files; 67 while (af < files+NFILES) 68 { 69 if (fgets(af->nm=s, NAMES, ansf)==0) 70 break; 71 trimnl(s); 72 if (*s==0) continue; 73 while (*s++); 74 _assert(s<fnames+NAMES); 75 st = stat(af->nm, &statbuf); 76 if (st<0) continue; 77 af->uid = statbuf.st_uid; 78 af->fdate = statbuf.st_mtime; 79 af->size = statbuf.st_size; 80 af++; 81 } 82 fclose(ansf); 83 return(af-files); 84 } 85 86 prod(f,s) 87 char *s; 88 { 89 write (f, s, strlen(s)); 90 write (f, "\n", 1); 91 } 92