1 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2 /* All Rights Reserved */ 3 4 5 /* 6 * Copyright (c) 1980 Regents of the University of California. 7 * All rights reserved. The Berkeley software License Agreement 8 * specifies the terms and conditions for redistribution. 9 */ 10 11 /* 12 * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc. 13 * All Rights Reserved. 14 */ 15 16 #pragma ident "%Z%%M% %I% %E% SMI" 17 18 #include <locale.h> 19 #include <stdio.h> 20 #include <assert.h> 21 #define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}} 22 23 extern long indexdate, gdate(); 24 extern FILE *iopen(); 25 runbib (s) 26 char *s; 27 { 28 /* make a file suitable for fgrep */ 29 char tmp[200]; 30 sprintf(tmp, "/usr/lib/refer/mkey '%s' > '%s.ig'", s,s); 31 system(tmp); 32 } 33 34 makefgrep(indexname) 35 char *indexname; 36 { 37 FILE *fa, *fb; 38 if (ckexist(indexname, ".ig")) 39 { 40 /* existing gfrep -type index */ 41 # if D1 42 fprintf(stderr, "found fgrep\n"); 43 # endif 44 fa = iopen(indexname, ".ig"); 45 fb = iopen(indexname, ""); 46 if (gdate(fb)>gdate(fa)) 47 { 48 if (fa!=NULL) 49 fclose(fa); 50 runbib(indexname); 51 fa= iopen(indexname, ".ig"); 52 } 53 indexdate = gdate(fa); 54 unopen(fa); 55 unopen(fb); 56 } 57 else 58 if (ckexist(indexname, "")) 59 { 60 /* make fgrep */ 61 # if D1 62 fprintf(stderr, "make fgrep\n"); 63 # endif 64 runbib(indexname); 65 time(&indexdate); 66 } 67 else /* failure */ 68 return(0); 69 return(1); /* success */ 70 } 71 72 ckexist(s, t) 73 char *s, *t; 74 { 75 char fnam[100]; 76 strcpy (fnam, s); 77 strcat (fnam, t); 78 return (access(fnam, 04) != -1); 79 } 80 81 FILE * 82 iopen(s, t) 83 char *s, *t; 84 { 85 char fnam[100]; 86 FILE *f; 87 strcpy (fnam, s); 88 strcat (fnam, t); 89 f = fopen (fnam, "r"); 90 if (f == NULL) 91 { 92 err(gettext("Missing expected file %s"), fnam); 93 exit(1); 94 } 95 return(f); 96 } 97