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