1 #ifndef lint 2 static char *sccsid = "@(#)hunt8.c 4.1 (Berkeley) 05/06/83"; 3 #endif 4 5 #include <stdio.h> 6 #include <assert.h> 7 #define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}} 8 9 extern long indexdate, gdate(); 10 extern FILE *iopen(); 11 runbib (s) 12 char *s; 13 { 14 /* make a file suitable for fgrep */ 15 char tmp[200]; 16 sprintf(tmp, "/usr/lib/refer/mkey %s >%s.ig", s,s); 17 system(tmp); 18 } 19 20 makefgrep(indexname) 21 char *indexname; 22 { 23 FILE *fa, *fb; 24 if (ckexist(indexname, ".ig")) 25 { 26 /* existing gfrep -type index */ 27 # if D1 28 fprintf(stderr, "found fgrep\n"); 29 # endif 30 fa = iopen(indexname, ".ig"); 31 fb = iopen(indexname, ""); 32 if (gdate(fb)>gdate(fa)) 33 { 34 if (fa!=NULL) 35 fclose(fa); 36 runbib(indexname); 37 fa= iopen(indexname, ".ig"); 38 } 39 indexdate = gdate(fa); 40 unopen(fa); 41 unopen(fb); 42 } 43 else 44 if (ckexist(indexname, "")) 45 { 46 /* make fgrep */ 47 # if D1 48 fprintf(stderr, "make fgrep\n"); 49 # endif 50 runbib(indexname); 51 time(&indexdate); 52 unopen(fb); 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 } 84