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

Defined functions

Defined variables

fgnames defined in line 10; used 9 times
fgnamp defined in line 10; used 10 times
fgp defined in line 8; used 6 times
fgspace defined in line 8; used 1 times
  • in line 83
keepold defined in line 6; used 2 times

Defined macros

FGCT defined in line 4; used 2 times
  • in line 9, 79
FGSIZE defined in line 5; used 2 times
  • in line 7, 83
SAME defined in line 2; used 1 times
  • in line 76
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 879
Valid CSS Valid XHTML 1.0 Strict