BSD 3 development
[unix-history] / usr / src / cmd / refer / glue3.c
CommitLineData
42d6e430
BJ
1# include "refer..c"
2corout(in, out, rprog, arg, outlen)
3 char *in, *out, *rprog;
4{
5# define move(x, y) close(y); dup(x); close(x);
6int pipev[2], fr1, fr2, fw1, fw2, n;
7
8if (strcmp (rprog, "hunt") ==0)
9 return(callhunt(in, out, arg, outlen));
10if (strcmp (rprog, "deliv")==0)
11 return(dodeliv(in, out, arg, outlen));
12pipe (pipev); fr1= pipev[0]; fw1 = pipev[1];
13pipe (pipev); fr2= pipev[0]; fw2 = pipev[1];
14if (fork()==0)
15 {
16 close (fw1); close (fr2);
17 move (fr1, 0);
18 move (fw2, 1);
19 if (rprog[0]!= '/')
20 chdir("/usr/lib/refer");
21 execl(rprog, "deliv", arg, 0);
22 err ("Can't run %s", rprog);
23 }
24close(fw2); close(fr1);
25write (fw1, in , strlen(in));
26close(fw1);
27wait(0);
28n = read (fr2, out, outlen);
29out[n]=0;
30close(fr2);
31}
32callhunt(in, out, arg, outlen)
33 char *in, *out, *arg;
34{
35# define ALEN 50
36char *argv[20], abuff[ALEN];
37extern int typeindex;
38int argc;
39extern char one[];
40extern int onelen;
41argv[0] = "hunt";
42argv[1] = "-i";
43argv[2] = in;
44argv[3] = "-t";
45argv[4] = out;
46argv[5] = outlen;
47argv[6] = "-T";
48argv[7] = "-F1";
49argv[8] = "-o";
50argv[9] = one;
51argv[10] = onelen;
52argv[11] = abuff; strcpy (abuff,arg);
53if (strlen(abuff) > ALEN)
54 err("abuff not big enough %d", strlen(abuff));
55argc = 6;
56huntmain (argc,argv);
57return(0);
58}
59dodeliv(in, out, arg, outlen)
60 char *in, *out, *arg;
61{
62# if D1
63fprintf(stderr, "in dodeliv, arg /%s/\n", arg?arg:"");
64# endif
65if (arg && arg[0])
66 chdir(arg);
67findline(in, out, outlen, 0L);
68restodir();
69}