1: #ifndef lint
   2: static char *sccsid = "@(#)hunt7.c	4.1 (Berkeley) 5/6/83";
   3: #endif
   4: 
   5: #include <stdio.h>
   6: #include <assert.h>
   7: #define SAME 0
   8: #define FGCT 10
   9: #define FGSIZE 150
  10: 
  11: int keepold = 1;    /* keep old things for fgrep search */
  12: char fgspace[FGSIZE];
  13: char *fgp = fgspace;
  14: char *fgnames[FGCT];
  15: char **fgnamp = fgnames;
  16: 
  17: findline(in, out, outlen, indexdate)
  18: long indexdate;
  19: char *in, *out;
  20: {
  21:     static char name[100] = "";
  22:     char *p, **ftp;
  23:     extern long gdate();
  24:     static FILE *fa = NULL;
  25:     long lp, llen;
  26:     int len, k, nofil;
  27: 
  28: # if D1
  29:     fprintf(stderr, "findline: %s\n", in);
  30: # endif
  31:     if (mindex(in, '!'))
  32:         return(remote(in, out));
  33:     nofil = in[0]==0;
  34:     for(p=in; *p && *p != ':' && *p != ';'; p++)
  35:         ;
  36:     if (*p) *p++=0;
  37:     else p=in;
  38:     k = sscanf(p, "%ld,%ld", &lp, &llen);
  39: # ifdef D1
  40:     fprintf(stderr, "p %s k %d lp %ld llen %ld\n",p,k,lp,llen);
  41: # endif
  42:     if (k<2)
  43:     {
  44:         lp = 0;
  45:         llen=outlen;
  46:     }
  47: # ifdef D1
  48:     fprintf(stderr, "lp %ld llen %ld\n",lp, llen);
  49: # endif
  50: # ifdef D1
  51:     fprintf(stderr, "fa now %o, p %o in %o %s\n",fa, p,in,in);
  52: # endif
  53:     if (nofil)
  54:     {
  55: # if D1
  56:         fprintf(stderr, "set fa to stdin\n");
  57: # endif
  58:         fa = stdin;
  59:     }
  60:     else
  61:         if (strcmp (name, in) != 0 || 1)
  62:         {
  63: # if D1
  64:             fprintf(stderr, "old: %s new %s not equal\n",name,in);
  65: # endif
  66:             if (fa != NULL)
  67:                 fa = freopen(in, "r", fa);
  68:             else
  69:                 fa = fopen(in, "r");
  70: # if D1
  71:             if (fa==NULL)
  72:                 fprintf(stderr, "failed to (re)open *%s*\n",in);
  73: # endif
  74:             if (fa == NULL)
  75:                 return(0);
  76:             /* err("Can't open %s", in); */
  77:             strcpy(name, in);
  78:             if (gdate(fa) > indexdate && indexdate != 0)
  79:             {
  80:                 if (keepold)
  81:                 {
  82:                     for(ftp=fgnames; ftp<fgnamp; ftp++)
  83:                         if (strcmp(*ftp, name)==SAME)
  84:                             return(0);
  85:                     strcpy (*fgnamp++ = fgp, name);
  86:                     assert(fgnamp<fgnames+FGCT);
  87:                     while (*fgp && *fgp!=':')
  88:                         fgp++;
  89:                     *fgp++ = 0;
  90:                     assert (fgp<fgspace+FGSIZE);
  91:                     return(0);
  92:                 }
  93:                 fprintf(stderr, "Warning: index predates file '%s'\n", name);
  94:             }
  95:         }
  96: # if D1
  97:         else
  98:             fprintf(stderr, "old %s new %s same fa %o\n", name,in,fa);
  99: # endif
 100:     if (fa != NULL)
 101:     {
 102:         fseek (fa, lp, 0);
 103:         len = (llen >= outlen) ? outlen-1 : llen;
 104:         len = fread (out, 1, len, fa);
 105:         out[len] = 0;
 106: # ifdef D1
 107:         fprintf(stderr, "length as read is %d\n",len);
 108: # endif
 109:     }
 110:     return(len);
 111: }

Defined functions

Defined variables

fgnames defined in line 14; used 10 times
fgnamp defined in line 15; used 11 times
fgp defined in line 13; used 6 times
fgspace defined in line 12; used 2 times
keepold defined in line 11; used 3 times
sccsid defined in line 2; never used

Defined macros

FGCT defined in line 8; used 2 times
FGSIZE defined in line 9; used 2 times
SAME defined in line 7; used 1 times
  • in line 83
Last modified: 1987-02-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2757
Valid CSS Valid XHTML 1.0 Strict