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

Defined functions

huntmain defined in line 33; used 1 times
setfrom defined in line 272; used 2 times
todir defined in line 254; used 2 times

Defined variables

colevel defined in line 13; used 1 times
full defined in line 25; used 2 times
hfreq defined in line 12; used 19 times
hfrflg defined in line 12; used 2 times
iflong defined in line 18; used 7 times
indexdate defined in line 29; used 4 times
lmaster defined in line 9; used 4 times
master defined in line 17; used 7 times
prfreqs defined in line 22; used 1 times
reached defined in line 10; never used
sccsid defined in line 2; never used
sinput defined in line 27; used 2 times
soutlen defined in line 30; used 1 times
  • in line 82
soutput defined in line 27; used 5 times
taglen defined in line 31; used 1 times
  • in line 93
tagout defined in line 27; used 12 times
tags defined in line 26; used 4 times
typeindex defined in line 23; used 6 times
usedir defined in line 24; used 6 times

Defined union's

firetruck defined in line 14; never used

Defined macros

unopen defined in line 6; used 3 times
Last modified: 1988-12-26
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3241
Valid CSS Valid XHTML 1.0 Strict