Annotation of 43BSDReno/usr.bin/refer/hunt/hunt8.c, revision 1.1.1.1

1.1       root        1: #ifndef lint
                      2: static char *sccsid = "@(#)hunt8.c     4.4 (Berkeley) 5/11/89";
                      3: #endif
                      4: 
                      5: #include <stdio.h>
                      6: #include <assert.h>
                      7: #include "pathnames.h"
                      8: #define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}}
                      9: 
                     10: extern long indexdate, gdate();
                     11: extern FILE *iopen();
                     12: runbib (s)
                     13: char *s;
                     14: {
                     15:        /* make a file suitable for fgrep */
                     16:        char tmp[200];
                     17:        sprintf(tmp, "%s '%s' > '%s.ig'", _PATH_MKEY,s,s);
                     18:        system(tmp);
                     19: }
                     20: 
                     21: makefgrep(indexname)
                     22: char *indexname;
                     23: {
                     24:        FILE *fa, *fb;
                     25:        if (ckexist(indexname, ".ig"))
                     26:        {
                     27:                /* existing gfrep -type index */
                     28: # if D1
                     29:                fprintf(stderr, "found fgrep\n");
                     30: # endif
                     31:                fa = iopen(indexname, ".ig");
                     32:                fb = iopen(indexname, "");
                     33:                if (gdate(fb)>gdate(fa))
                     34:                {
                     35:                        if (fa!=NULL)
                     36:                                fclose(fa);
                     37:                        runbib(indexname);
                     38:                        fa= iopen(indexname, ".ig");
                     39:                }
                     40:                indexdate = gdate(fa);
                     41:                unopen(fa); 
                     42:                unopen(fb);
                     43:        }
                     44:        else
                     45:                if (ckexist(indexname, ""))
                     46:                {
                     47:                        /* make fgrep */
                     48: # if D1
                     49:                        fprintf(stderr, "make fgrep\n");
                     50: # endif
                     51:                        runbib(indexname);
                     52:                        time(&indexdate);
                     53:                }
                     54:                else /* failure */
                     55:                return(0);
                     56:        return(1); /* success */
                     57: }
                     58: 
                     59: ckexist(s, t)
                     60: char *s, *t;
                     61: {
                     62:        char fnam[100];
                     63:        strcpy (fnam, s);
                     64:        strcat (fnam, t);
                     65:        return (access(fnam, 04) != -1);
                     66: }
                     67: 
                     68: FILE *
                     69: iopen(s, t)
                     70: char *s, *t;
                     71: {
                     72:        char fnam[100];
                     73:        FILE *f;
                     74:        strcpy (fnam, s);
                     75:        strcat (fnam, t);
                     76:        f = fopen (fnam, "r");
                     77:        if (f == NULL)
                     78:        {
                     79:                err("Missing expected file %s", fnam);
                     80:                exit(1);
                     81:        }
                     82:        return(f);
                     83: }

unix.superglobalmegacorp.com

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