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