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