X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/e804469b5b0975de34bae1e66c3e6371249d3ee7..0f4556f12c8f75078501c9d1338ae7648a97f975:/usr/src/usr.bin/refer/hunt1.c diff --git a/usr/src/usr.bin/refer/hunt1.c b/usr/src/usr.bin/refer/hunt1.c index 5f0c75ea19..6db3ba80f6 100644 --- a/usr/src/usr.bin/refer/hunt1.c +++ b/usr/src/usr.bin/refer/hunt1.c @@ -1,5 +1,9 @@ -# include "stdio.h" -# include "assert.h" +#ifndef lint +static char *sccsid = "@(#)hunt1.c 4.2 (Berkeley) 6/21/83"; +#endif + +# include +# include extern char refdir[]; extern int keepold; extern char *fgnames[]; @@ -14,7 +18,8 @@ int reached =0; int iflong =0; int prfreqs =0; char usedir[100]; -char * calloc(); char * todir(); +char * calloc(); +char * todir(); char gfile[50]; static int full =1000; static int tags =0; @@ -22,29 +27,31 @@ char *sinput, *soutput, *tagout; long indexdate =0, gdate(); main(argc,argv) - char *argv[]; +char *argv[]; { -/* read query from stdin, expect name of indexes in argv[1] */ -static FILE *fa, *fb, *fc; -char nma[100], nmb[100], nmc[100], *qitem[100], *rprog = NULL; -char nmd[100], grepquery[256]; -static char oldname[30] ; -static int was =0; -/* these pointers are unions of pointer to int and pointer to long */ -long *hpt; -unsigned *master =0; -int falseflg, nhash, nitem, nfound, frtbl, kk; + /* read query from stdin, expect name of indexes in argv[1] */ + static FILE *fa, *fb, *fc; + char nma[100], nmb[100], nmc[100], *qitem[100], *rprog = NULL; + char nmd[100], grepquery[256]; + static char oldname[30] ; + static int was =0; + /* these pointers are unions of pointer to int and pointer to long */ + long *hpt; + unsigned *master =0; + int falseflg, nhash, nitem, nfound, frtbl, kk; /* special wart for refpart: default is tags only */ -while (argv[1][0] == '-') + while (argv[1][0] == '-') { - switch(argv[1][1]) + switch(argv[1][1]) { case 'a': /* all output, incl. false drops */ - falseflg = 1; break; + falseflg = 1; + break; case 'r': - argc--; argv++; + argc--; + argv++; rprog = argv[1]; break; case 'F': /* put out full text */ @@ -54,25 +61,30 @@ while (argv[1][0] == '-') tags = setfrom(argv[1][2]); break; case 'i': /* input in argument string */ - argc--; argv++; + argc--; + argv++; sinput = argv[1]; break; case 's': /*text output to string */ case 'o': - argc--; argv++; + argc--; + argv++; soutput = argv[1]; if (argv[2]<16000) - { + { soutlen = (int)argv[2]; - argc--; argv++; - } + argc--; + argv++; + } break; case 't': /*tag output to string */ - argc--; argv++; + argc--; + argv++; tagout = argv[1]; break; case 'l': /* length of internal lists */ - argc--; argv++; + argc--; + argv++; lmaster = atoi(argv[1]); break; case 'g': /* suppress fgrep search on old files */ @@ -81,158 +93,185 @@ while (argv[1][0] == '-') case 'C': /* coordination level */ colevel = atoi(argv[1]+2); # if D1 -fprintf(stderr, "colevel set to %d\n",colevel); + fprintf(stderr, "colevel set to %d\n",colevel); # endif break; case 'P': /* print term freqs */ - prfreqs=1; break; + prfreqs=1; + break; case 'm': - measure=1; break; + measure=1; + break; } - argc--; argv++; + argc--; + argv++; } -strcpy (nma, todir(argv[1])); -if (was == 0 || strcmp (oldname, nma) !=0) + strcpy (nma, todir(argv[1])); + if (was == 0 || strcmp (oldname, nma) !=0) { - strcpy (oldname,nma); - strcpy (nmb, nma); strcpy (nmc, nmb); strcpy(nmd,nma); - strcat (nma, ".ia"); - strcat (nmb, ".ib"); - strcat (nmc, ".ic"); - strcat (nmd, ".id"); - if (was) - {fclose(fa); fclose(fb); fclose(fc);} + strcpy (oldname,nma); + strcpy (nmb, nma); + strcpy (nmc, nmb); + strcpy(nmd,nma); + strcat (nma, ".ia"); + strcat (nmb, ".ib"); + strcat (nmc, ".ic"); + strcat (nmd, ".id"); + if (was) + { + fclose(fa); + fclose(fb); + fclose(fc); + } - fa = fopen(nma, "r"); - if (fa==NULL) + fa = fopen(nma, "r"); + if (fa==NULL) { - strcpy(*fgnamp++ = calloc(strlen(oldname)+2,1), oldname); - fb=NULL; - goto search; + strcpy(*fgnamp++ = calloc(strlen(oldname)+2,1), oldname); + fb=NULL; + goto search; } - fb = fopen(nmb, "r"); - fc = fopen(nmc, "r"); - was =1; - if (fb== NULL || fc ==NULL) + fb = fopen(nmb, "r"); + fc = fopen(nmc, "r"); + was =1; + if (fb== NULL || fc ==NULL) { - err("Index incomplete %s", nmb); - exit(1); + err("Index incomplete %s", nmb); + exit(1); } - indexdate = gdate(fb); - fd = fopen(nmd, "r"); + indexdate = gdate(fb); + fd = fopen(nmd, "r"); } -fseek (fa, 0L, 0); -fread (&nhash, sizeof(nhash), 1, fa); -fread (&iflong, sizeof(iflong), 1, fa); -if(master==0) -master = calloc (lmaster, iflong? 4: 2); -hpt = calloc(nhash, sizeof(*hpt)); -kk=fread( hpt, sizeof(*hpt), nhash, fa); + fseek (fa, 0L, 0); + fread (&nhash, sizeof(nhash), 1, fa); + fread (&iflong, sizeof(iflong), 1, fa); + if(master==0) + master = calloc (lmaster, iflong? 4: 2); + hpt = calloc(nhash, sizeof(*hpt)); + kk=fread( hpt, sizeof(*hpt), nhash, fa); # if D1 -fprintf(stderr,"read %d hashes, iflong %d, nhash %d\n", kk, iflong, nhash); + fprintf(stderr,"read %d hashes, iflong %d, nhash %d\n", kk, iflong, nhash); # endif -_assert (kk==nhash); -hfreq = calloc(nhash, sizeof(*hfreq)); -_assert (hfreq != NULL); -frtbl = fread(hfreq, sizeof(*hfreq), nhash, fa); -hfrflg = (frtbl == nhash); + _assert (kk==nhash); + hfreq = calloc(nhash, sizeof(*hfreq)); + _assert (hfreq != NULL); + frtbl = fread(hfreq, sizeof(*hfreq), nhash, fa); + hfrflg = (frtbl == nhash); # if D1 -fprintf(stderr, "read freqs %d\n", frtbl); + fprintf(stderr, "read freqs %d\n", frtbl); # endif search: -while (1) - { - nitem = getq(qitem); - if (measure) tick(); - if (nitem==0) continue; - if (nitem < 0) break; - if (tagout) tagout[0]=0; - if (fb!=NULL) + while (1) { - nfound = doquery(hpt, nhash, fb, nitem, qitem, master); + nitem = getq(qitem); + if (measure) tick(); + if (nitem==0) continue; + if (nitem < 0) break; + if (tagout) tagout[0]=0; + if (fb!=NULL) + { + nfound = doquery(hpt, nhash, fb, nitem, qitem, master); # if D1 - fprintf(stderr,"after doquery nfound %d\n", nfound); + fprintf(stderr,"after doquery nfound %d\n", nfound); # endif - fgnamp=fgnames; - if (falseflg == 0) - nfound = baddrop(master, nfound, fc, nitem, qitem, rprog, full); + fgnamp=fgnames; + if (falseflg == 0) + nfound = baddrop(master, nfound, fc, nitem, qitem, rprog, full); # if D1 - fprintf(stderr,"after baddrop nfound %d\n", nfound); + fprintf(stderr,"after baddrop nfound %d\n", nfound); # endif - } - if (fgnamp>fgnames) + } + if (fgnamp>fgnames) { - char **fgp, tgbuff[100]; - int k; + char **fgp, tgbuff[100]; + int k; # if D1 - fprintf(stderr, "were %d bad files\n", fgnamp-fgnames); + fprintf(stderr, "were %d bad files\n", fgnamp-fgnames); # endif - grepquery[0]=0; - for(k=0; ktags ? tags: nfound, fc); - if (measure) tock(); + if (tags) + result (master, nfound >tags ? tags: nfound, fc); + if (measure) tock(); } } char * todir(t) - char *t; +char *t; { char *s; s=t; while (*s) s++; while (s>=t && *s != '/') s--; if (s