1*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 3*7c478bd9Sstevel@tonic-gate 4*7c478bd9Sstevel@tonic-gate 5*7c478bd9Sstevel@tonic-gate /* 6*7c478bd9Sstevel@tonic-gate * Copyright (c) 1980 Regents of the University of California. 7*7c478bd9Sstevel@tonic-gate * All rights reserved. The Berkeley software License Agreement 8*7c478bd9Sstevel@tonic-gate * specifies the terms and conditions for redistribution. 9*7c478bd9Sstevel@tonic-gate */ 10*7c478bd9Sstevel@tonic-gate 11*7c478bd9Sstevel@tonic-gate /* 12*7c478bd9Sstevel@tonic-gate * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. 13*7c478bd9Sstevel@tonic-gate * All Rights Reserved. 14*7c478bd9Sstevel@tonic-gate */ 15*7c478bd9Sstevel@tonic-gate 16*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 17*7c478bd9Sstevel@tonic-gate 18*7c478bd9Sstevel@tonic-gate 19*7c478bd9Sstevel@tonic-gate #include <stdio.h> 20*7c478bd9Sstevel@tonic-gate #include <ctype.h> 21*7c478bd9Sstevel@tonic-gate 22*7c478bd9Sstevel@tonic-gate extern char gfile[]; 23*7c478bd9Sstevel@tonic-gate 24*7c478bd9Sstevel@tonic-gate grepcall (in, out, arg) 25*7c478bd9Sstevel@tonic-gate char *in, *out, *arg; 26*7c478bd9Sstevel@tonic-gate { 27*7c478bd9Sstevel@tonic-gate char line[200], *s, argig[100], *cv[50]; 28*7c478bd9Sstevel@tonic-gate char *inp, inb[500]; 29*7c478bd9Sstevel@tonic-gate FILE *qf, *gf; 30*7c478bd9Sstevel@tonic-gate int c, oldc = 0, alph = 0, nv = 0; 31*7c478bd9Sstevel@tonic-gate int sv0, sv1; 32*7c478bd9Sstevel@tonic-gate strcpy (argig, arg); 33*7c478bd9Sstevel@tonic-gate strcat(argig, ".ig"); 34*7c478bd9Sstevel@tonic-gate strcpy (inp=inb, in); 35*7c478bd9Sstevel@tonic-gate if (gfile[0]==0) 36*7c478bd9Sstevel@tonic-gate sprintf(gfile, "/tmp/rj%dg", getpid()); 37*7c478bd9Sstevel@tonic-gate # if D1 38*7c478bd9Sstevel@tonic-gate fprintf(stderr, "in grepcall, gfile %s in %o out %o\n", gfile,in,out); 39*7c478bd9Sstevel@tonic-gate # endif 40*7c478bd9Sstevel@tonic-gate for(cv[nv++] = "fgrep"; c = *inp; inp++) 41*7c478bd9Sstevel@tonic-gate { 42*7c478bd9Sstevel@tonic-gate if (c== ' ') 43*7c478bd9Sstevel@tonic-gate c = *inp = 0; 44*7c478bd9Sstevel@tonic-gate else if (isupper(c)) 45*7c478bd9Sstevel@tonic-gate *inp = tolower(c); 46*7c478bd9Sstevel@tonic-gate alph = (c==0) ? 0 : alph+1; 47*7c478bd9Sstevel@tonic-gate if (alph == 1) 48*7c478bd9Sstevel@tonic-gate cv[nv++] = inp; 49*7c478bd9Sstevel@tonic-gate if (alph > 6) 50*7c478bd9Sstevel@tonic-gate *inp = 0; 51*7c478bd9Sstevel@tonic-gate oldc=c; 52*7c478bd9Sstevel@tonic-gate } 53*7c478bd9Sstevel@tonic-gate # if D1 54*7c478bd9Sstevel@tonic-gate fprintf(stderr, "%d args set up\n", nv); 55*7c478bd9Sstevel@tonic-gate # endif 56*7c478bd9Sstevel@tonic-gate { 57*7c478bd9Sstevel@tonic-gate sv0 = dup(0); 58*7c478bd9Sstevel@tonic-gate close(0); 59*7c478bd9Sstevel@tonic-gate if (open (argig, 0) != 0) 60*7c478bd9Sstevel@tonic-gate err("Can't read fgrep index %s", argig); 61*7c478bd9Sstevel@tonic-gate sv1 = dup(1); 62*7c478bd9Sstevel@tonic-gate close(1); 63*7c478bd9Sstevel@tonic-gate if (creat(gfile, 0666) != 1) 64*7c478bd9Sstevel@tonic-gate err("Can't write fgrep output %s", gfile); 65*7c478bd9Sstevel@tonic-gate fgrep(nv, cv); 66*7c478bd9Sstevel@tonic-gate # if D1 67*7c478bd9Sstevel@tonic-gate fprintf(stderr, "fgrep returned, output is..\n"); 68*7c478bd9Sstevel@tonic-gate # endif 69*7c478bd9Sstevel@tonic-gate close (0); 70*7c478bd9Sstevel@tonic-gate dup(sv0); 71*7c478bd9Sstevel@tonic-gate close(sv0); 72*7c478bd9Sstevel@tonic-gate close (1); 73*7c478bd9Sstevel@tonic-gate dup(sv1); 74*7c478bd9Sstevel@tonic-gate close(sv1); 75*7c478bd9Sstevel@tonic-gate } 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate # if D1 78*7c478bd9Sstevel@tonic-gate fprintf(stderr, "back from fgrep\n"); 79*7c478bd9Sstevel@tonic-gate # endif 80*7c478bd9Sstevel@tonic-gate gf = fopen(gfile, "r"); 81*7c478bd9Sstevel@tonic-gate if (gf==NULL) 82*7c478bd9Sstevel@tonic-gate err("can't read fgrep output %s", gfile); 83*7c478bd9Sstevel@tonic-gate while (fgets(line, 100, gf) == line) 84*7c478bd9Sstevel@tonic-gate { 85*7c478bd9Sstevel@tonic-gate line[100]=0; 86*7c478bd9Sstevel@tonic-gate # if D1 87*7c478bd9Sstevel@tonic-gate fprintf(stderr, "read line as //%s//\n",line); 88*7c478bd9Sstevel@tonic-gate # endif 89*7c478bd9Sstevel@tonic-gate for(s=line; *s && (*s != '\t'); s++); 90*7c478bd9Sstevel@tonic-gate if (*s == '\t') 91*7c478bd9Sstevel@tonic-gate { 92*7c478bd9Sstevel@tonic-gate *s++ = '\n'; 93*7c478bd9Sstevel@tonic-gate *s++ = 0; 94*7c478bd9Sstevel@tonic-gate } 95*7c478bd9Sstevel@tonic-gate if (line[0]) 96*7c478bd9Sstevel@tonic-gate strcat(out, line); 97*7c478bd9Sstevel@tonic-gate # if D1 98*7c478bd9Sstevel@tonic-gate fprintf(stderr, "out now /%s/\n",out); 99*7c478bd9Sstevel@tonic-gate # endif 100*7c478bd9Sstevel@tonic-gate while (*s) s++; 101*7c478bd9Sstevel@tonic-gate # if D1 102*7c478bd9Sstevel@tonic-gate fprintf(stderr, "line %o s %o s-1 %o\n",line,s,s[-1]); 103*7c478bd9Sstevel@tonic-gate # endif 104*7c478bd9Sstevel@tonic-gate if (s[-1]!= '\n') 105*7c478bd9Sstevel@tonic-gate while (!feof(gf) && getc(gf)!= '\n') ; 106*7c478bd9Sstevel@tonic-gate } 107*7c478bd9Sstevel@tonic-gate fclose(gf); 108*7c478bd9Sstevel@tonic-gate # if D1 109*7c478bd9Sstevel@tonic-gate fprintf(stderr, "back from reading %, out %s\n",out); 110*7c478bd9Sstevel@tonic-gate # else 111*7c478bd9Sstevel@tonic-gate unlink (gfile); 112*7c478bd9Sstevel@tonic-gate # endif 113*7c478bd9Sstevel@tonic-gate return(0); 114*7c478bd9Sstevel@tonic-gate } 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate clfgrep() 117*7c478bd9Sstevel@tonic-gate { 118*7c478bd9Sstevel@tonic-gate if (gfile[0]) 119*7c478bd9Sstevel@tonic-gate unlink(gfile); 120*7c478bd9Sstevel@tonic-gate } 121