Annotation of 43BSDTahoe/usr.bin/refer/glue1.c, revision 1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.