Research V7 development
[unix-history] / usr / src / cmd / refer / what3.c
CommitLineData
52960f2f
ML
1# include "what..c"
2
3doclook(argc, argv, colevel)
4 char *argv[];
5{
6 int fpa[2], fpb[2], fpc[2], pid1, pid2, st;
7 int iarg;
8 char *s;
9 FILE *ansf;
10 struct filans *af;
11 struct stat statbuf;
12# define RD 0
13# define WR 1
14# define fmv(x,y) close(y); dup(x); close(x);
15/* we want to run chkbib and then lhunt and pipe in & out */
16pipe (fpa); /* from this program to chkbib */
17pipe (fpb); /* from chkbib to lhunt */
18pipe (fpc); /* from lhunt to us */
19if ( (pid1 = fork()) ==0)
20 {
21 fmv(fpa[RD], 0);
22 fmv(fpb[WR], 1);
23 close(fpa[WR]); close(fpb[RD]); close(fpc[RD]); close(fpc[WR]);
24 execl("/usr/lib/refer/mkey", "mkey", "-s", 0);
25 _assert(0);
26 }
27if ( (pid2 = fork()) == 0)
28 {
29 char coarg[20];
30 sprintf(coarg, "-C%d", colevel);
31 fmv(fpb[RD], 0);
32 fmv(fpc[WR], 1);
33 close(fpa[RD]); close(fpa[WR]); close(fpb[WR]); close(fpc[RD]);
34 execl("/usr/lib/refer/hunt", "hunt",
35 /* "-P", */
36 coarg, "-Ty", "-Fn", "/usr/dict/lookall/All", 0);
37 _assert(0);
38 }
39_assert (pid1 != -1); _assert(pid2 != -1);
40close(fpb[RD]); close(fpb[WR]); close(fpa[RD]); close(fpc[WR]);
41ansf = fopen("/dev/null", "r");
42fmv (fpc[RD], ansf->_file);
43for(iarg=1; iarg<argc; iarg++)
44 prod(fpa[WR], argv[iarg]);
45close(fpa[WR]);
46s=fnames;
47af=files;
48while (af < files+NFILES)
49 {
50 if (fgets(af->nm=s, NAMES, ansf)==0)
51 break;
52 trimnl(s);
53 if (*s==0) continue;
54 while (*s++);
55 _assert(s<fnames+NAMES);
56 st = stat(af->nm, &statbuf);
57 if (st<0) continue;
58 af->uid = statbuf.st_uid;
59 af->fdate = statbuf.st_mtime;
60 af->size = statbuf.st_size;
61 af++;
62 }
63fclose(ansf);
64return(af-files);
65}
66prod(f,s)
67 char *s;
68{
69write (f, s, strlen(s));
70write (f, "\n", 1);
71}