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 #include <stdio.h> 19*7c478bd9Sstevel@tonic-gate #include <assert.h> 20*7c478bd9Sstevel@tonic-gate #include <string.h> 21*7c478bd9Sstevel@tonic-gate #define TXTLEN 1000 22*7c478bd9Sstevel@tonic-gate 23*7c478bd9Sstevel@tonic-gate char *outbuf = 0; 24*7c478bd9Sstevel@tonic-gate extern char *soutput; 25*7c478bd9Sstevel@tonic-gate extern int soutlen, iflong; 26*7c478bd9Sstevel@tonic-gate extern long indexdate; 27*7c478bd9Sstevel@tonic-gate union ptr { 28*7c478bd9Sstevel@tonic-gate unsigned *a; 29*7c478bd9Sstevel@tonic-gate long *b; 30*7c478bd9Sstevel@tonic-gate }; 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate baddrop(mptr, nf, fc, nitem, qitem, rprog, full) 33*7c478bd9Sstevel@tonic-gate unsigned *mptr; 34*7c478bd9Sstevel@tonic-gate FILE *fc; 35*7c478bd9Sstevel@tonic-gate char *qitem[], *rprog; 36*7c478bd9Sstevel@tonic-gate { 37*7c478bd9Sstevel@tonic-gate /* checks list of drops for real bad drops; finds items with "deliv" */ 38*7c478bd9Sstevel@tonic-gate int i, g, j, need, got, na, len; 39*7c478bd9Sstevel@tonic-gate long lp; 40*7c478bd9Sstevel@tonic-gate char res[100], *ar[50], output[TXTLEN], *mput; 41*7c478bd9Sstevel@tonic-gate union ptr master; 42*7c478bd9Sstevel@tonic-gate extern int colevel, reached; 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate if (iflong) { 45*7c478bd9Sstevel@tonic-gate master.b = (long *) mptr; 46*7c478bd9Sstevel@tonic-gate } 47*7c478bd9Sstevel@tonic-gate else { 48*7c478bd9Sstevel@tonic-gate master.a = mptr; 49*7c478bd9Sstevel@tonic-gate } 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate # if D1 52*7c478bd9Sstevel@tonic-gate if (iflong) 53*7c478bd9Sstevel@tonic-gate fprintf(stderr,"in baddrop, nf %d master %ld %ld %ld\n", 54*7c478bd9Sstevel@tonic-gate nf, master.b[0], master.b[1], master.b[2]); 55*7c478bd9Sstevel@tonic-gate else 56*7c478bd9Sstevel@tonic-gate fprintf(stderr,"in baddrop, nf %d master %d %d %d\n", 57*7c478bd9Sstevel@tonic-gate nf, master.a[0], master.a[1], master.a[2]); 58*7c478bd9Sstevel@tonic-gate # endif 59*7c478bd9Sstevel@tonic-gate for (i=g=0; i<nf; i++) 60*7c478bd9Sstevel@tonic-gate { 61*7c478bd9Sstevel@tonic-gate lp = iflong ? master.b[i] : master.a[i]; 62*7c478bd9Sstevel@tonic-gate # if D1 63*7c478bd9Sstevel@tonic-gate if (iflong) 64*7c478bd9Sstevel@tonic-gate fprintf(stderr, "i %d master %lo lp %lo\n", 65*7c478bd9Sstevel@tonic-gate i, master.b[i], lp); 66*7c478bd9Sstevel@tonic-gate else 67*7c478bd9Sstevel@tonic-gate fprintf(stderr, "i %d master %o lp %lo\n", 68*7c478bd9Sstevel@tonic-gate i, master.a[i], lp); 69*7c478bd9Sstevel@tonic-gate # endif 70*7c478bd9Sstevel@tonic-gate fseek (fc, lp, 0); 71*7c478bd9Sstevel@tonic-gate fgets( res, 100, fc); 72*7c478bd9Sstevel@tonic-gate # if D1 73*7c478bd9Sstevel@tonic-gate fprintf(stderr, "tag %s", res); 74*7c478bd9Sstevel@tonic-gate # endif 75*7c478bd9Sstevel@tonic-gate if (!auxil(res,output)) 76*7c478bd9Sstevel@tonic-gate { 77*7c478bd9Sstevel@tonic-gate char *s; 78*7c478bd9Sstevel@tonic-gate int c; 79*7c478bd9Sstevel@tonic-gate # if D1 80*7c478bd9Sstevel@tonic-gate fprintf(stderr, "not auxil try rprog %c\n", 81*7c478bd9Sstevel@tonic-gate rprog? 'y': 'n'); 82*7c478bd9Sstevel@tonic-gate # endif 83*7c478bd9Sstevel@tonic-gate for(s=res; c= *s; s++) 84*7c478bd9Sstevel@tonic-gate if (c == ';' || c == '\n') 85*7c478bd9Sstevel@tonic-gate { 86*7c478bd9Sstevel@tonic-gate *s=0; 87*7c478bd9Sstevel@tonic-gate break; 88*7c478bd9Sstevel@tonic-gate } 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate if (rprog) 91*7c478bd9Sstevel@tonic-gate len = corout(res, output, rprog, 0, TXTLEN); 92*7c478bd9Sstevel@tonic-gate else 93*7c478bd9Sstevel@tonic-gate { 94*7c478bd9Sstevel@tonic-gate len = findline(res, &mput, TXTLEN, indexdate); 95*7c478bd9Sstevel@tonic-gate if (len > 0) /* copy and free */ 96*7c478bd9Sstevel@tonic-gate { 97*7c478bd9Sstevel@tonic-gate strncpy(output, mput, TXTLEN); 98*7c478bd9Sstevel@tonic-gate free(mput); 99*7c478bd9Sstevel@tonic-gate } 100*7c478bd9Sstevel@tonic-gate else /* insufficient memory or other... */ 101*7c478bd9Sstevel@tonic-gate len = 0; 102*7c478bd9Sstevel@tonic-gate } 103*7c478bd9Sstevel@tonic-gate } 104*7c478bd9Sstevel@tonic-gate # if D1 105*7c478bd9Sstevel@tonic-gate assert (len <TXTLEN); 106*7c478bd9Sstevel@tonic-gate fprintf(stderr,"item %d of %d, tag %s len %d output\n%s\n..\n", 107*7c478bd9Sstevel@tonic-gate i, nf, res, len, output); 108*7c478bd9Sstevel@tonic-gate # endif 109*7c478bd9Sstevel@tonic-gate if (len==0) 110*7c478bd9Sstevel@tonic-gate continue; 111*7c478bd9Sstevel@tonic-gate need = colevel ? reached : nitem; 112*7c478bd9Sstevel@tonic-gate na=0; 113*7c478bd9Sstevel@tonic-gate ar[na++] = "fgrep"; 114*7c478bd9Sstevel@tonic-gate ar[na++] = "-r"; 115*7c478bd9Sstevel@tonic-gate ar[na++] = "-n"; 116*7c478bd9Sstevel@tonic-gate ar[na++] = (char *) need; 117*7c478bd9Sstevel@tonic-gate ar[na++] = "-i"; 118*7c478bd9Sstevel@tonic-gate ar[na++] = output; 119*7c478bd9Sstevel@tonic-gate ar[na++] = (char *) len; 120*7c478bd9Sstevel@tonic-gate for(j=0; j<nitem; j++) 121*7c478bd9Sstevel@tonic-gate ar[na++] = qitem[j]; 122*7c478bd9Sstevel@tonic-gate # ifdef D1 123*7c478bd9Sstevel@tonic-gate fprintf(stderr, "calling fgrep len %d ar[4] %s %o %d \n", 124*7c478bd9Sstevel@tonic-gate len,ar[4],ar[5],ar[6]); 125*7c478bd9Sstevel@tonic-gate # endif 126*7c478bd9Sstevel@tonic-gate if (fgrep(na, ar)==0) 127*7c478bd9Sstevel@tonic-gate { 128*7c478bd9Sstevel@tonic-gate # ifdef D1 129*7c478bd9Sstevel@tonic-gate fprintf(stderr, "fgrep found it\n"); 130*7c478bd9Sstevel@tonic-gate # endif 131*7c478bd9Sstevel@tonic-gate if (iflong) 132*7c478bd9Sstevel@tonic-gate master.b[g++] = master.b[i]; 133*7c478bd9Sstevel@tonic-gate else 134*7c478bd9Sstevel@tonic-gate master.a[g++] = master.a[i]; 135*7c478bd9Sstevel@tonic-gate if (full >= g) 136*7c478bd9Sstevel@tonic-gate if (soutput==0) 137*7c478bd9Sstevel@tonic-gate fputs(output, stdout); 138*7c478bd9Sstevel@tonic-gate else 139*7c478bd9Sstevel@tonic-gate strcpy (soutput, output); 140*7c478bd9Sstevel@tonic-gate } 141*7c478bd9Sstevel@tonic-gate # ifdef D1 142*7c478bd9Sstevel@tonic-gate fprintf(stderr, "after fgrep\n"); 143*7c478bd9Sstevel@tonic-gate # endif 144*7c478bd9Sstevel@tonic-gate } 145*7c478bd9Sstevel@tonic-gate return(g); 146*7c478bd9Sstevel@tonic-gate } 147*7c478bd9Sstevel@tonic-gate 148*7c478bd9Sstevel@tonic-gate auxil( res, output) 149*7c478bd9Sstevel@tonic-gate char *res, *output; 150*7c478bd9Sstevel@tonic-gate { 151*7c478bd9Sstevel@tonic-gate extern FILE *fd; 152*7c478bd9Sstevel@tonic-gate long lp, c; 153*7c478bd9Sstevel@tonic-gate int len; 154*7c478bd9Sstevel@tonic-gate if (fd==0)return(0); 155*7c478bd9Sstevel@tonic-gate while (c = *res++) 156*7c478bd9Sstevel@tonic-gate { 157*7c478bd9Sstevel@tonic-gate if (c == ';') 158*7c478bd9Sstevel@tonic-gate { 159*7c478bd9Sstevel@tonic-gate sscanf(res, "%ld,%d", &lp, &len); 160*7c478bd9Sstevel@tonic-gate fseek (fd, lp, 0); 161*7c478bd9Sstevel@tonic-gate fgets(output, len, fd); 162*7c478bd9Sstevel@tonic-gate return(1); 163*7c478bd9Sstevel@tonic-gate } 164*7c478bd9Sstevel@tonic-gate } 165*7c478bd9Sstevel@tonic-gate return(0); 166*7c478bd9Sstevel@tonic-gate } 167