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