1: # include "stdio.h"
   2: # define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}}
   3: extern char refdir[];
   4: int lmaster 1000;
   5: int reached 0;
   6: FILE *fd 0;
   7: int *hfreq, hfrflg;
   8: int colevel 0;
   9: static union {unsigned *a; long *b;} master NULL;
  10: int iflong;
  11: extern char *fgnames[], **fgnamp;
  12: int prfreqs 0;
  13: int typeindex 0;
  14: char usedir[100];
  15: static int full 1000;
  16: static int tags 0;
  17: char *sinput, *soutput, *tagout;
  18: long indexdate 0, gdate();
  19: int soutlen 1000;
  20: int taglen 1000;
  21: 
  22: huntmain(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 indexname[100], *qitem[100], *rprog 0;
  28: char grepquery[200];
  29: static char oldname[30] ;
  30: static int nhash 0;
  31: static int maxhash 0;
  32: int falseflg 0, nitem, nfound, frtbl;
  33: static long *hpt 0;
  34: # if D1
  35: fprintf(stderr, "in glue1 argc %d argv %o %o\n", argc, argv[0],argv[1]);
  36: # endif
  37: savedir();
  38: while (argv[1][0] == '-')
  39:     {
  40: # if D1
  41: fprintf(stderr, "argv.1 is %s\n",argv[1]);
  42: # endif
  43:     switch(argv[1][1])
  44:         {
  45:         case 'a': /* all output, incl. false drops */
  46:             falseflg = 1; break;
  47:         case 'r':
  48:             argc--; argv++;
  49:             rprog = argv[1];
  50:             break;
  51:         case 'F': /* put out full text */
  52:             full = setfrom(argv[1][2]);
  53:             break;
  54:         case 'T': /* put out tags */
  55:             tags = setfrom(argv[1][2]);
  56:             break;
  57:         case 'i': /* input in argument string */
  58:             argc--; argv++;
  59:             sinput = argv[1];
  60:             break;
  61:         case 's': /*text output to string */
  62:         case 'o':
  63:             argc--; argv++;
  64:             soutput = argv[1];
  65:             if (argv[2]<16000)
  66:                 {
  67:                 soutlen = argv[2];
  68:                 argc--; argv++;
  69:                 }
  70:             break;
  71:         case 't': /*tag output to string */
  72:             argc--; argv++;
  73:             tagout = argv[1];
  74:             if (argv[2]<16000)
  75:                 {
  76:                 taglen = argv[2];
  77:                 argc--; argv++;
  78:                 }
  79:             break;
  80:         case 'l': /* specify length of lists */
  81:             argc--; argv++;
  82:             lmaster = atoi(argv[1]);
  83: # if D1
  84:             fprintf(stderr, "lmaster now %d\n",lmaster);
  85: # endif
  86:             break;
  87:         case 'C':
  88:             argc--; argv++;
  89:             colevel = atoi(argv[1]);
  90:             break;
  91:         }
  92:     argc--; argv++;
  93:     }
  94: strcpy (indexname, todir(argv[1]));
  95: # if D1
  96: fprintf(stderr, "in huntmain indexname %s typeindex %d\n", indexname, typeindex);
  97: # endif
  98: if (typeindex == 0 || strcmp (oldname, indexname) !=0)
  99:     {
 100:     strcpy (oldname, indexname);
 101:     unopen(fa); unopen(fb); unopen(fc);
 102: 
 103:     if (ckexist(indexname, ".ib"))
 104:         {
 105: # if D1
 106:         fprintf(stderr, "found old index\n");
 107: # endif
 108:         fa = iopen(indexname, ".ia");
 109:         fb = iopen(indexname, ".ib");
 110:         fc = iopen(indexname, ".ic");
 111:         typeindex =1;
 112: # if D1
 113:         fprintf(stderr, "opened f's as %o %o %o\n",fa,fb,fc);
 114: # endif
 115:         indexdate = gdate(fb);
 116:         fread (&nhash, sizeof(nhash), 1, fa);
 117:         fread (&iflong, sizeof(iflong), 1, fa);
 118:         if (nhash > maxhash)
 119:             {
 120:             if (hpt)
 121:                 free (hpt, maxhash, sizeof(*hpt));
 122:             hpt=0;
 123:             if (hfreq)
 124:                 free(hfreq, maxhash, sizeof(*hfreq));
 125:             hfreq=0;
 126:             maxhash=nhash;
 127: # if D1
 128:             fprintf(stderr, "Freed if needed maxhash %d\n",maxhash);
 129: # endif
 130:             }
 131:         if (hpt==0)
 132:         hpt = zalloc(nhash, sizeof(*hpt));
 133: # if D1
 134:         fprintf(stderr, "hpt now %o\n",hpt);
 135: # endif
 136:         if (hpt == NULL)
 137:             err ("No space for hash list (%d)", nhash);
 138:         fread( hpt, sizeof(*hpt), nhash, fa);
 139:         if (hfreq==0)
 140:         hfreq=zalloc(nhash, sizeof(*hfreq));
 141:         if (hfreq==NULL)
 142:             err ("No space for hash frequencies (%d)", nhash);
 143:         frtbl = fread(hfreq, sizeof(*hfreq), nhash, fa);
 144:         hfrflg = (frtbl == nhash);
 145: # if D1
 146:         fprintf(stderr,"Read pointer files\n");
 147: # endif
 148:         if (master.a == NULL)
 149:             if (iflong)
 150:                 master.b = zalloc(lmaster, sizeof(long));
 151:             else
 152:                 master.a = zalloc(lmaster, sizeof(int));
 153:         if (master.a == NULL)
 154:             err ("no space for answer list",0);
 155:         }
 156:     else
 157:     if (makefgrep(indexname))
 158:         typeindex=2;
 159:     else
 160:         {
 161:         err ("No files %s\n",indexname);
 162:         exit(1);
 163:         }
 164:     }
 165: 
 166: # if D1
 167: fprintf(stderr, "typeindex now %d\n",typeindex);
 168: # endif
 169: tagout[0]=0;
 170: if (typeindex==2)
 171:     {
 172:     grepcall(sinput, tagout, indexname);
 173: # if D1
 174:     fprintf(stderr, " back from grepcall\n");
 175: # endif
 176:     restodir();
 177:     return;
 178:     }
 179: nitem = getq(qitem);
 180: # if D1
 181: fprintf(stderr, "approaching doquery fb %o\n", fb);
 182: # endif
 183: nfound = doquery(hpt, nhash, fb, nitem, qitem, master);
 184: # ifdef D1
 185:     fprintf(stderr, "return from doquery with nfound %d\n", nfound);
 186: # endif
 187: if (falseflg == 0)
 188:     nfound = baddrop(master, nfound, fc, nitem, qitem, rprog, full);
 189: # ifdef D1
 190:     fprintf(stderr, "after baddrop with nfound %d\n",nfound);
 191:     fprintf(stderr, "tagout is /%s/, sout /%s/\n",tagout, soutput);
 192: # endif
 193: if (tags)
 194:     result (master, nfound >tags ? tags : nfound, fc);
 195: # if D1
 196: fprintf(stderr, "done with huntmain\n");
 197: fprintf(stderr, "tagout is /%s/\n", tagout);
 198: fprintf(stderr, "string out is /%s/\n", soutput);
 199: # endif
 200: if (fgnamp>fgnames)
 201:     {
 202:     char **fgp;
 203:     int k;
 204: # if D1
 205:     fprintf(stderr, "were %d bad files\n", fgnamp-fgnames);
 206: # endif
 207:     grepquery[0]=0;
 208:     for(k=0; k<nitem; k++)
 209:         {
 210:         strcat(grepquery, " ");
 211:         strcat(grepquery, qitem[k]);
 212:         }
 213:     for(fgp=fgnames; fgp<fgnamp; fgp++)
 214:         {
 215: # if D1
 216:         fprintf(stderr, "Now on %s query /%s/\n", *fgp, grepquery);
 217: # endif
 218:         makefgrep(*fgp);
 219:         grepcall(grepquery, tagout, *fgp);
 220: # if D1
 221:         fprintf(stderr, "tagout now /%s/\n", tagout);
 222: # endif
 223:         }
 224:     }
 225: restodir();
 226: }
 227: 
 228: todir(t)
 229:     char *t;
 230: {
 231:     char *s;
 232:     s=t;
 233:     while (*s) s++;
 234:     while (s>=t && *s != '/') s--;
 235:     if (s<t) return(t);
 236: *s++ = 0;
 237: t = (*t ? t : "/");
 238: chdir (t);
 239: strcpy (usedir,t);
 240: return(s);
 241: }
 242: setfrom(c)
 243: {
 244: switch(c)
 245:     {
 246:     case 'y': case '\0':
 247:     default:
 248:         return(1000);
 249:     case '1':
 250:     case '2': case '3': case '4': case '5':
 251:     case '6': case '7': case '8': case '9':
 252:         return(c-'0');
 253:     case 'n': case '0':
 254:         return(0);
 255:     }
 256: }

Defined functions

huntmain defined in line 22; used 1 times
setfrom defined in line 242; used 2 times
todir defined in line 228; used 1 times
  • in line 94

Defined variables

colevel defined in line 8; used 1 times
  • in line 89
full defined in line 15; used 2 times
hfreq defined in line 7; used 19 times
hfrflg defined in line 7; used 2 times
iflong defined in line 10; used 7 times
indexdate defined in line 18; used 4 times
lmaster defined in line 4; used 4 times
prfreqs defined in line 12; used 1 times
reached defined in line 5; never used
sinput defined in line 17; used 2 times
soutlen defined in line 19; used 1 times
  • in line 67
soutput defined in line 17; used 5 times
taglen defined in line 20; used 1 times
  • in line 76
tagout defined in line 17; used 12 times
tags defined in line 16; used 4 times
typeindex defined in line 13; used 6 times
usedir defined in line 14; used 5 times

Defined macros

unopen defined in line 2; used 3 times
  • in line 101(3)
Last modified: 1981-11-12
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1245
Valid CSS Valid XHTML 1.0 Strict