1 /* $MirOS: src/usr.bin/oldroff/refer/glue3.c,v 1.2 2008/11/08 23:04:44 tg Exp $ */
2 /*-
3  * Copyright (c) 1979, 1980, 1981, 1986, 1988, 1990, 1991, 1992
4  *     The Regents of the University of California.
5  * Copyright (C) Caldera International Inc.  2001-2002.
6  * Copyright (c) 2003, 2004
7  *	Thorsten "mirabilos" Glaser <tg@mirbsd.org>
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms,
11  * with or without modification, are permitted provided
12  * that the following conditions are met:
13  *
14  * Redistributions of source code and documentation must retain
15  * the above copyright notice, this list of conditions and the
16  * following disclaimer.  Redistributions in binary form must
17  * reproduce the above copyright notice, this list of conditions
18  * and the following disclaimer in the documentation and/or other
19  * materials provided with the distribution.
20  *
21  * All advertising materials mentioning features or use of this
22  * software must display the following acknowledgement:
23  *   This product includes software developed or owned by
24  *   Caldera International, Inc.
25  *
26  * Neither the name of Caldera International, Inc. nor the names
27  * of other contributors may be used to endorse or promote products
28  * derived from this software without specific prior written permission.
29  *
30  * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
31  * INTERNATIONAL, INC. AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
32  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
33  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
34  * ARE DISCLAIMED.  IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE
35  * LIABLE FOR ANY DIRECT, INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR
36  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
37  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
38  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
40  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
41  * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42  */
43 
44 #include <sys/cdefs.h>
45 __SCCSID("@(#)glue3.c	4.4 (Berkeley) 4/18/91");
46 __RCSID("$MirOS: src/usr.bin/oldroff/refer/glue3.c,v 1.2 2008/11/08 23:04:44 tg Exp $");
47 
48 #include "refer..c"
49 #include "pathnames.h"
50 
51 #define move(x, y) close(y); dup(x); close(x);
52 
corout(in,out,rprog,arg,outlen)53 corout(in, out, rprog, arg, outlen)
54 char *in, *out, *rprog;
55 {
56 	int pipev[2], fr1, fr2, fw1, fw2, n;
57 
58 	if (strcmp (rprog, "hunt") ==0)
59 		return(callhunt(in, out, arg, outlen));
60 	if (strcmp (rprog, "deliv")==0)
61 		return(dodeliv(in, out, arg, outlen));
62 	pipe (pipev);
63 	fr1= pipev[0];
64 	fw1 = pipev[1];
65 	pipe (pipev);
66 	fr2= pipev[0];
67 	fw2 = pipev[1];
68 	if (fork()==0)
69 	{
70 		close (fw1);
71 		close (fr2);
72 		move (fr1, 0);
73 		move (fw2, 1);
74 		if (rprog[0]!= '/')
75 			chdir(_PATH_LIB);
76 		execl(rprog, rprog, arg, NULL);
77 		err ("Can't run %s", rprog);
78 	}
79 	close(fw2);
80 	close(fr1);
81 	write (fw1, in , strlen(in));
82 	close(fw1);
83 	wait(0);
84 	n = read (fr2, out, outlen);
85 	out[n]=0;
86 	close(fr2);
87 }
88 
89 # define ALEN 50
90 
callhunt(in,out,arg,outlen)91 callhunt(in, out, arg, outlen)
92 char *in, *out, *arg;
93 {
94 	char *argv[20], abuff[ALEN];
95 	extern int typeindex;
96 	int argc;
97 	extern char one[];
98 	extern int onelen;
99 	argv[0] = "hunt";
100 	argv[1] = "-i";
101 	argv[2] = in;
102 	argv[3] = "-t";
103 	argv[4] = out;
104 	argv[5] = (char *)outlen;	/* Horrid kludge, see option parsing
105 					   in huntmain() in glue1.c. */
106 	argv[6] = "-T";
107 	argv[7] = "-F1";
108 	argv[8] = "-o";
109 	argv[9] = one;
110 	argv[10] = (char *)onelen;		/* Horrid kludge again */
111 	argv[11] = abuff;
112 	strcpy (abuff,arg);
113 	if (strlen(abuff) > ALEN)
114 		err("abuff not big enough %d", strlen(abuff));
115 	argc = 6;
116 	huntmain (argc,argv);
117 	return(0);
118 }
119 
dodeliv(in,out,arg,outlen)120 dodeliv(in, out, arg, outlen)
121 char *in, *out, *arg;
122 {
123 # if D1
124 	fprintf(stderr, "in dodeliv, arg /%s/\n", arg?arg:"");
125 # endif
126 	if (arg && arg[0])
127 		chdir(arg);
128 	findline(in, out, outlen, 0L);
129 	restodir();
130 }
131