home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / cmd / refer / hunt6.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-01-10  |  2.4 KB  |  111 lines

  1. # include "stdio.h"
  2. # include "assert.h"
  3. # define TXTLEN 1000
  4. char *outbuf 0;
  5. extern char *soutput;
  6. extern int soutlen, iflong;
  7. extern long indexdate;
  8. baddrop(master, nf, fc, nitem, qitem, rprog, full)
  9.     union ptr {unsigned *a; long *b; } master;
  10.     FILE *fc;
  11.     char *qitem[], *rprog;
  12. {
  13. /* checks list of drops for real bad drops;
  14.    uses "deliv" to find items. */
  15. int i, g, j, need, got, na, len;
  16. long lp;
  17. char res[100], *ar[50], output[TXTLEN];
  18. extern int colevel, reached;
  19. # if D1
  20. if (iflong)
  21. fprintf(stderr,"in baddrop, nf %d master %ld %ld %ld\n", nf, master.b[0], master.b[1], master.b[2]);
  22. else
  23. fprintf(stderr,"in baddrop, nf %d master %d %d %d\n", nf, master.a[0], master.a[1], master.a[2]);
  24. # endif
  25. for (i=g=0; i<nf; i++)
  26.     {
  27.     lp = iflong ? master.b[i] : master.a[i];
  28. # if D1
  29.     if (iflong)
  30.     fprintf(stderr, "i %d master %lo lp %lo\n", i, master.b[i], lp);
  31.     else
  32.     fprintf(stderr, "i %d master %o lp %lo\n", i, master.a[i], lp);
  33. # endif
  34.     fseek (fc, lp, 0);
  35.     fgets( res, 100, fc);
  36. # if D1
  37.     fprintf(stderr, "tag %s", res);
  38. # endif
  39.     if (!auxil(res,output))
  40.         {
  41.         char *s; int c;
  42. # if D1
  43.         fprintf(stderr, "not auxil try rprog %c\n", rprog? 'y': 'n');
  44. # endif
  45.         for(s=res; c= *s; s++)
  46.             if (c == ';' || c == '\n')
  47.                 {*s=0; break;}
  48.         len = rprog ?
  49.             corout (res, output, rprog, 0, TXTLEN) :
  50.             findline (res, output, TXTLEN, indexdate);
  51.         }
  52. # if D1
  53.     _assert (len <TXTLEN);
  54.     fprintf(stderr,"item %d of %d, tag %s len %d output\n%s\n..\n",i,nf,res, len,output);
  55. # endif
  56.     if (len==0)
  57.         continue;
  58.     need = colevel ? reached : nitem;
  59.     na=0;
  60.     ar[na++] = "fgrep";
  61.     ar[na++] = "-r";
  62.     ar[na++] = "-n";
  63.     ar[na++] = need;
  64.     ar[na++] = "-i";
  65.     ar[na++] = output;
  66.     ar[na++] = len;
  67.     for(j=0; j<nitem; j++)
  68.         ar[na++] = qitem[j];
  69. # ifdef D1
  70.     fprintf(stderr, "calling fgrep len %d ar[4] %s %o %d \n",len,ar[4],ar[5],ar[6]);
  71. # endif
  72.     if (fgrep(na, ar)==0)
  73.         {
  74. # ifdef D1
  75.     fprintf(stderr, "fgrep found it\n");
  76. # endif
  77.         if (iflong)
  78.             master.b[g++] = master.b[i];
  79.         else
  80.             master.a[g++] = master.a[i];
  81.         if (full >= g)
  82.             if (soutput==0)
  83.                 fputs(output, stdout);
  84.             else
  85.                 strcpy (soutput, output);
  86.         }
  87. # ifdef D1
  88.     fprintf(stderr, "after fgrep\n");
  89. # endif
  90.     }
  91. return(g);
  92. }
  93. auxil( res, output)
  94.     char *res, *output;
  95. {
  96. extern FILE *fd;
  97. long lp, c; int len;
  98. if (fd==0)return(0);
  99. while (c = *res++) 
  100.     {
  101.     if (c == ';')
  102.         {
  103.         sscanf(res, "%ld,%d", &lp, &len);
  104.         fseek (fd, lp, 0);
  105.         fgets(output, len, fd);
  106.         return(1);
  107.         }
  108.     }
  109. return(0);
  110. }
  111.