1: # include "stdio.h"
   2: # include "assert.h"
   3: extern char refdir[];
   4: extern int keepold;
   5: extern char *fgnames[];
   6: extern char **fgnamp;
   7: FILE *fd 0;
   8: int lmaster 500;
   9: int *hfreq, hfrflg;
  10: int colevel 0;
  11: int soutlen 1000;
  12: int reached 0;
  13: int iflong 0;
  14: int prfreqs 0;
  15: char usedir[100];
  16: char gfile[50];
  17: static int full 1000;
  18: static int tags 0;
  19: char *sinput, *soutput, *tagout;
  20: long indexdate 0, gdate();
  21: 
  22: main(argc,argv)
  23:     char *argv[];
  24: {
  25: /* read query from stdin, expect name of indexes in argv[1] */
  26: static FILE *fa, *fb, *fc;
  27: char nma[100], nmb[100], nmc[100], *qitem[100], *rprog 0;
  28: char nmd[100], grepquery[256];
  29: static char oldname[30] ;
  30: static int was 0;
  31: /* these pointers are unions of pointer to int and pointer to long */
  32: long *hpt;
  33: unsigned *master 0;
  34: int falseflg, nhash, nitem, nfound, frtbl, kk;
  35: 
  36:     /* special wart for refpart: default is tags only */
  37: 
  38: while (argv[1][0] == '-')
  39:     {
  40:     switch(argv[1][1])
  41:         {
  42:         case 'a': /* all output, incl. false drops */
  43:             falseflg = 1; break;
  44:         case 'r':
  45:             argc--; argv++;
  46:             rprog = argv[1];
  47:             break;
  48:         case 'F': /* put out full text */
  49:             full = setfrom(argv[1][2]);
  50:             break;
  51:         case 'T': /* put out tags */
  52:             tags = setfrom(argv[1][2]);
  53:             break;
  54:         case 'i': /* input in argument string */
  55:             argc--; argv++;
  56:             sinput = argv[1];
  57:             break;
  58:         case 's': /*text output to string */
  59:         case 'o':
  60:             argc--; argv++;
  61:             soutput = argv[1];
  62:             if (argv[2]<16000)
  63:                 {
  64:                 soutlen = argv[2];
  65:                 argc--; argv++;
  66:                 }
  67:             break;
  68:         case 't': /*tag output to string */
  69:             argc--; argv++;
  70:             tagout = argv[1];
  71:             break;
  72:         case 'l': /* length of internal lists */
  73:             argc--; argv++;
  74:             lmaster = atoi(argv[1]);
  75:             break;
  76:         case 'g': /* suppress fgrep search on old files */
  77:             keepold = 0;
  78:             break;
  79:         case 'C': /* coordination level */
  80:             colevel = atoi(argv[1]+2);
  81: # if D1
  82: fprintf(stderr, "colevel set to %d\n",colevel);
  83: # endif
  84:             break;
  85:         case 'P': /* print term freqs */
  86:             prfreqs=1; break;
  87:         }
  88:     argc--; argv++;
  89:     }
  90: strcpy (nma, todir(argv[1]));
  91: if (was == 0 || strcmp (oldname, nma) !=0)
  92:     {
  93:     strcpy (oldname,nma);
  94:     strcpy (nmb, nma); strcpy (nmc, nmb); strcpy(nmd,nma);
  95:     strcat (nma, ".ia");
  96:     strcat (nmb, ".ib");
  97:     strcat (nmc, ".ic");
  98:     strcat (nmd, ".id");
  99:     if (was)
 100:         {fclose(fa); fclose(fb); fclose(fc);}
 101: 
 102:     fa = fopen(nma, "r");
 103:     if (fa==NULL)
 104:         {
 105:         err("No files %s",nma);
 106:         exit(1);
 107:         }
 108:     fb = fopen(nmb, "r");
 109:     fc = fopen(nmc, "r");
 110:     was =1;
 111:     if (fb== NULL || fc ==NULL)
 112:         {
 113:         err("Index incomplete %s", nmb);
 114:         exit(1);
 115:         }
 116:     indexdate = gdate(fb);
 117:     fd = fopen(nmd, "r");
 118:     }
 119: fseek (fa, 0L, 0);
 120: fread (&nhash, sizeof(nhash), 1, fa);
 121: fread (&iflong, sizeof(iflong), 1, fa);
 122: if(master==0)
 123: master = calloc (lmaster, iflong? 4: 2);
 124: hpt = calloc(nhash, sizeof(*hpt));
 125: kk=fread( hpt, sizeof(*hpt), nhash, fa);
 126: # if D1
 127: fprintf(stderr,"read %d hashes, iflong %d, nhash %d\n", kk, iflong, nhash);
 128: # endif
 129: _assert (kk==nhash);
 130: hfreq = calloc(nhash, sizeof(*hfreq));
 131: _assert (hfreq != NULL);
 132: frtbl = fread(hfreq, sizeof(*hfreq), nhash, fa);
 133: hfrflg = (frtbl == nhash);
 134: # if D1
 135: fprintf(stderr, "read freqs %d\n", frtbl);
 136: # endif
 137: 
 138: while (1)
 139:     {
 140:     nitem = getq(qitem);
 141:     if (nitem==0) continue;
 142:     if (nitem < 0) break;
 143:     nfound = doquery(hpt, nhash, fb, nitem, qitem, master);
 144: # if D1
 145:     fprintf(stderr,"after doquery nfound %d\n", nfound);
 146: # endif
 147:     fgnamp=fgnames;
 148:     if (falseflg == 0)
 149:         nfound = baddrop(master, nfound, fc, nitem, qitem, rprog, full);
 150: # if D1
 151:     fprintf(stderr,"after baddrop nfound %d\n", nfound);
 152: # endif
 153:     if (fgnamp>fgnames)
 154:         {
 155:         char **fgp, tgbuff[100];
 156:         int k;
 157: # if D1
 158:         fprintf(stderr, "were %d bad files\n", fgnamp-fgnames);
 159: # endif
 160:         grepquery[0]=0;
 161:         for(k=0; k<nitem; k++)
 162:             {
 163:             strcat(grepquery, " ");
 164:             strcat(grepquery, qitem[k]);
 165:             }
 166: # if D1
 167:         fprintf(stderr, "grepquery %s\n",grepquery);
 168: # endif
 169:         for(fgp=fgnames; fgp<fgnamp; fgp++)
 170:             {
 171: # if D1
 172:             fprintf(stderr, "Now on %s query /%s/\n", *fgp, grepquery);
 173: # endif
 174:             makefgrep(*fgp);
 175: # if D1
 176:             fprintf(stderr, "grepmade\n");
 177: # endif
 178:             if (tagout==0)
 179:                 tagout=tgbuff;
 180:             grepcall(grepquery, tagout, *fgp);
 181: # if D1
 182:             fprintf(stderr, "tagout now /%s/\n", tagout);
 183: # endif
 184:             if (full)
 185:                 {
 186:                 char bout[1000];
 187:                 findline(tagout, bout, 1000);
 188:                 fputs(bout,stdout);
 189:                 }
 190:             }
 191:         }
 192:     if (tags)
 193:         result (master, nfound >tags ? tags: nfound, fc);
 194:     }
 195: }
 196: 
 197: todir(t)
 198:     char *t;
 199: {
 200:     char *s;
 201:     s=t;
 202:     while (*s) s++;
 203:     while (s>=t && *s != '/') s--;
 204:     if (s<t) return(t);
 205: *s++ = 0;
 206: t = (*t ? t : "/");
 207: chdir (t);
 208: strcpy (usedir,t);
 209: return(s);
 210: }
 211: setfrom(c)
 212: {
 213: switch(c)
 214:     {
 215:     case 'y': case '\0':
 216:     default:
 217:         return(1000);
 218:     case '1':
 219:     case '2': case '3': case '4': case '5':
 220:     case '6': case '7': case '8': case '9':
 221:         return(c-'0');
 222:     case 'n': case '0':
 223:         return(0);
 224:     }
 225: }

Defined functions

main defined in line 22; never used
setfrom defined in line 211; used 2 times
todir defined in line 197; used 1 times
  • in line 90

Defined variables

colevel defined in line 10; used 2 times
full defined in line 17; used 3 times
gfile defined in line 16; never used
hfreq defined in line 9; used 5 times
hfrflg defined in line 9; used 1 times
iflong defined in line 13; used 4 times
indexdate defined in line 20; used 1 times
lmaster defined in line 8; used 2 times
prfreqs defined in line 14; used 1 times
  • in line 86
reached defined in line 12; never used
sinput defined in line 19; used 1 times
  • in line 56
soutlen defined in line 11; used 1 times
  • in line 64
soutput defined in line 19; used 1 times
  • in line 61
tagout defined in line 19; used 6 times
tags defined in line 18; used 4 times
usedir defined in line 15; used 1 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 938
Valid CSS Valid XHTML 1.0 Strict