| 1/* 2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. 4 */ 5
|
1/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2/* All Rights Reserved */ 3
| 6/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 7/* All Rights Reserved */ 8
|
4
| |
5/* 6 * Copyright (c) 1980 Regents of the University of California. 7 * All rights reserved. The Berkeley software License Agreement 8 * specifies the terms and conditions for redistribution. 9 */ 10
| 9/* 10 * Copyright (c) 1980 Regents of the University of California. 11 * All rights reserved. The Berkeley software License Agreement 12 * specifies the terms and conditions for redistribution. 13 */ 14
|
11/* 12 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 13 * Use is subject to license terms. 14 */ 15
| |
16#pragma ident "%Z%%M% %I% %E% SMI" 17 18 19#include "refer..c" 20#include <string.h>
| 15#pragma ident "%Z%%M% %I% %E% SMI" 16 17 18#include "refer..c" 19#include <string.h>
|
21#define move(x, y) close(y); dup(x); close(x);
| 20#define move(x, y) close(y); dup(x); close(x);
|
22
| 21
|
23corout(in, out, rprog, arg, outlen) 24char *in, *out, *rprog;
| 22extern void err(); 23extern long findline(); 24extern void huntmain(); 25extern void restodir(); 26 27static int callhunt(char *, char *, char *, int); 28static int dodeliv(char *, char *, char *, int); 29 30int 31corout(char *in, char *out, char *rprog, char *arg, int outlen)
|
25{ 26 int pipev[2], fr1, fr2, fw1, fw2, n; 27
| 32{ 33 int pipev[2], fr1, fr2, fw1, fw2, n; 34
|
28# if D1 29 fprintf(stderr, "in corout, rprog /%s/ in /%s/\n", 30 rprog ? rprog : "", strlen(in) ? in : ""); 31# endif
| 35#if D1 36 fprintf(stderr, "in corout, rprog /%s/ in /%s/\n", 37 rprog ? rprog : "", strlen(in) ? in : ""); 38#endif
|
32
| 39
|
33 if (strcmp (rprog, "hunt") ==0) 34 return(callhunt(in, out, arg, outlen)); 35 if (strcmp (rprog, "deliv")==0) 36 return(dodeliv(in, out, arg, outlen)); 37 pipe (pipev); 38 fr1= pipev[0];
| 40 if (strcmp(rprog, "hunt") == 0) 41 return (callhunt(in, out, arg, outlen)); 42 if (strcmp(rprog, "deliv") == 0) 43 return (dodeliv(in, out, arg, outlen)); 44 pipe(pipev); 45 fr1 = pipev[0];
|
39 fw1 = pipev[1];
| 46 fw1 = pipev[1];
|
40 pipe (pipev); 41 fr2= pipev[0];
| 47 pipe(pipev); 48 fr2 = pipev[0];
|
42 fw2 = pipev[1];
| 49 fw2 = pipev[1];
|
43 if (fork()==0) 44 { 45 close (fw1); 46 close (fr2); 47 move (fr1, 0); 48 move (fw2, 1); 49 if (rprog[0]!= '/')
| 50 if (fork() == 0) { 51 close(fw1); 52 close(fr2); 53 move(fr1, 0); 54 move(fw2, 1); 55 if (rprog[0] != '/')
|
50 chdir("/usr/lib/refer"); 51 execl(rprog, "deliv", arg, 0); 52 err(gettext("Can't run %s"), rprog); 53 }
| 56 chdir("/usr/lib/refer"); 57 execl(rprog, "deliv", arg, 0); 58 err(gettext("Can't run %s"), rprog); 59 }
|
54 close(fw2);
| 60 close(fw2);
|
55 close(fr1); 56 if (strlen(in) > 0)
| 61 close(fr1); 62 if (strlen(in) > 0)
|
57 write (fw1, in , strlen(in));
| 63 write(fw1, in, strlen(in));
|
58 close(fw1); 59 wait(0);
| 64 close(fw1); 65 wait(0);
|
60 n = read (fr2, out, outlen); 61 out[n]=0;
| 66 n = read(fr2, out, outlen); 67 out[n] = 0;
|
62 close(fr2);
| 68 close(fr2);
|
| 69 return (0);
|
63} 64
| 70} 71
|
65# define ALEN 50
| 72#define ALEN 50
|
66
| 73
|
67callhunt(in, out, arg, outlen) 68char *in, *out, *arg;
| 74static int 75callhunt(char *in, char *out, char *arg, int outlen)
|
69{ 70 char *argv[20], abuff[ALEN]; 71 extern int typeindex; 72 int argc; 73 extern char one[]; 74 extern int onelen; 75 argv[0] = "hunt"; 76 argv[1] = "-i"; 77 argv[2] = in; 78 argv[3] = "-t"; 79 argv[4] = out; 80 argv[5] = (char *)outlen; 81 argv[6] = "-T"; 82 argv[7] = "-F1"; 83 argv[8] = "-o"; 84 argv[9] = one; 85 argv[10] = (char *)onelen;
| 76{ 77 char *argv[20], abuff[ALEN]; 78 extern int typeindex; 79 int argc; 80 extern char one[]; 81 extern int onelen; 82 argv[0] = "hunt"; 83 argv[1] = "-i"; 84 argv[2] = in; 85 argv[3] = "-t"; 86 argv[4] = out; 87 argv[5] = (char *)outlen; 88 argv[6] = "-T"; 89 argv[7] = "-F1"; 90 argv[8] = "-o"; 91 argv[9] = one; 92 argv[10] = (char *)onelen;
|
86 argv[11] = abuff; 87 strcpy (abuff,arg);
| 93 argv[11] = abuff; 94 strcpy(abuff, arg);
|
88 if (strlen(abuff) > ALEN) 89 err("abuff not big enough %d", strlen(abuff)); 90 argc = 6;
| 95 if (strlen(abuff) > ALEN) 96 err("abuff not big enough %d", strlen(abuff)); 97 argc = 6;
|
91 huntmain (argc,argv); 92 return(0);
| 98 huntmain(argc, argv); 99 return (0);
|
93} 94
| 100} 101
|
95dodeliv(in, out, arg, outlen) 96char *in, *out, *arg;
| 102static int 103dodeliv(char *in, char *out, char *arg, int outlen)
|
97{ 98 char *mout; 99 int mlen;
| 104{ 105 char *mout; 106 int mlen;
|
100# if D1
| 107#if D1
|
101 fprintf(stderr, "in dodeliv, arg /%s/\n", arg?arg:"");
| 108 fprintf(stderr, "in dodeliv, arg /%s/\n", arg?arg:"");
|
102# endif
| 109#endif
|
103 if (arg && arg[0]) 104 chdir(arg); 105
| 110 if (arg && arg[0]) 111 chdir(arg); 112
|
106 mlen = findline(in, &mout, outlen,0L);
| 113 mlen = findline(in, &mout, outlen, 0L);
|
107
| 114
|
108 if (mlen>0) 109 {
| 115 if (mlen > 0) {
|
110 strncpy(out, mout, outlen);
| 116 strncpy(out, mout, outlen);
|
111 free (mout);
| 117 free(mout);
|
112 } 113 restodir();
| 118 } 119 restodir();
|
| 120 return (0);
|
114}
| 121}
|