Commit | Line | Data |
---|---|---|
3ddf501b TL |
1 | # include "what..c" |
2 | ||
3 | doclook(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 */ | |
16 | pipe (fpa); /* from this program to chkbib */ | |
17 | pipe (fpb); /* from chkbib to lhunt */ | |
18 | pipe (fpc); /* from lhunt to us */ | |
19 | if ( (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 | } | |
27 | if ( (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); | |
40 | close(fpb[RD]); close(fpb[WR]); close(fpa[RD]); close(fpc[WR]); | |
41 | ansf = fopen("/dev/null", "r"); | |
42 | fmv (fpc[RD], ansf->_file); | |
43 | for(iarg=1; iarg<argc; iarg++) | |
44 | prod(fpa[WR], argv[iarg]); | |
45 | close(fpa[WR]); | |
46 | s=fnames; | |
47 | af=files; | |
48 | while (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 | } | |
63 | fclose(ansf); | |
64 | return(af-files); | |
65 | } | |
66 | prod(f,s) | |
67 | char *s; | |
68 | { | |
69 | write (f, s, strlen(s)); | |
70 | write (f, "\n", 1); | |
71 | } |