1 /*-
2 * %sccs.include.proprietary.c%
3 */
4
5 #ifndef lint
6 static char sccsid[] = "@(#)glue3.c 4.4 (Berkeley) 04/18/91";
7 #endif /* not lint */
8
9 #include "refer..c"
10 #include "pathnames.h"
11
12 #define move(x, y) close(y); dup(x); close(x);
13
corout(in,out,rprog,arg,outlen)14 corout(in, out, rprog, arg, outlen)
15 char *in, *out, *rprog;
16 {
17 int pipev[2], fr1, fr2, fw1, fw2, n;
18
19 if (strcmp (rprog, "hunt") ==0)
20 return(callhunt(in, out, arg, outlen));
21 if (strcmp (rprog, "deliv")==0)
22 return(dodeliv(in, out, arg, outlen));
23 pipe (pipev);
24 fr1= pipev[0];
25 fw1 = pipev[1];
26 pipe (pipev);
27 fr2= pipev[0];
28 fw2 = pipev[1];
29 if (fork()==0)
30 {
31 close (fw1);
32 close (fr2);
33 move (fr1, 0);
34 move (fw2, 1);
35 if (rprog[0]!= '/')
36 chdir(_PATH_LIB);
37 execl(rprog, "deliv", arg, 0);
38 err ("Can't run %s", rprog);
39 }
40 close(fw2);
41 close(fr1);
42 write (fw1, in , strlen(in));
43 close(fw1);
44 wait(0);
45 n = read (fr2, out, outlen);
46 out[n]=0;
47 close(fr2);
48 }
49
50 # define ALEN 50
51
callhunt(in,out,arg,outlen)52 callhunt(in, out, arg, outlen)
53 char *in, *out, *arg;
54 {
55 char *argv[20], abuff[ALEN];
56 extern int typeindex;
57 int argc;
58 extern char one[];
59 extern int onelen;
60 argv[0] = "hunt";
61 argv[1] = "-i";
62 argv[2] = in;
63 argv[3] = "-t";
64 argv[4] = out;
65 argv[5] = (char *)outlen; /* Horrid kludge, see option parsing
66 in huntmain() in glue1.c. */
67 argv[6] = "-T";
68 argv[7] = "-F1";
69 argv[8] = "-o";
70 argv[9] = one;
71 argv[10] = (char *)onelen; /* Horrid kludge again */
72 argv[11] = abuff;
73 strcpy (abuff,arg);
74 if (strlen(abuff) > ALEN)
75 err("abuff not big enough %d", strlen(abuff));
76 argc = 6;
77 huntmain (argc,argv);
78 return(0);
79 }
80
dodeliv(in,out,arg,outlen)81 dodeliv(in, out, arg, outlen)
82 char *in, *out, *arg;
83 {
84 # if D1
85 fprintf(stderr, "in dodeliv, arg /%s/\n", arg?arg:"");
86 # endif
87 if (arg && arg[0])
88 chdir(arg);
89 findline(in, out, outlen, 0L);
90 restodir();
91 }
92