xref: /csrg-svn/old/refer/hunt/hunt8.c (revision 37895)
112289Stut #ifndef lint
2*37895Sbostic static char *sccsid = "@(#)hunt8.c	4.4 (Berkeley) 05/11/89";
312289Stut #endif
412289Stut 
512289Stut #include <stdio.h>
612289Stut #include <assert.h>
7*37895Sbostic #include "pathnames.h"
812289Stut #define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}}
912289Stut 
1012289Stut extern long indexdate, gdate();
1112289Stut extern FILE *iopen();
1212289Stut runbib (s)
1312289Stut char *s;
1412289Stut {
1512289Stut 	/* make a file suitable for fgrep */
1612289Stut 	char tmp[200];
17*37895Sbostic 	sprintf(tmp, "%s '%s' > '%s.ig'", _PATH_MKEY,s,s);
1812289Stut 	system(tmp);
1912289Stut }
2012289Stut 
2112289Stut makefgrep(indexname)
2212289Stut char *indexname;
2312289Stut {
2412289Stut 	FILE *fa, *fb;
2512289Stut 	if (ckexist(indexname, ".ig"))
2612289Stut 	{
2712289Stut 		/* existing gfrep -type index */
2812289Stut # if D1
2912289Stut 		fprintf(stderr, "found fgrep\n");
3012289Stut # endif
3112289Stut 		fa = iopen(indexname, ".ig");
3212289Stut 		fb = iopen(indexname, "");
3312289Stut 		if (gdate(fb)>gdate(fa))
3412289Stut 		{
3512289Stut 			if (fa!=NULL)
3612289Stut 				fclose(fa);
3712289Stut 			runbib(indexname);
3812289Stut 			fa= iopen(indexname, ".ig");
3912289Stut 		}
4012289Stut 		indexdate = gdate(fa);
4112289Stut 		unopen(fa);
4212289Stut 		unopen(fb);
4312289Stut 	}
4412289Stut 	else
4512289Stut 		if (ckexist(indexname, ""))
4612289Stut 		{
4712289Stut 			/* make fgrep */
4812289Stut # if D1
4912289Stut 			fprintf(stderr, "make fgrep\n");
5012289Stut # endif
5112289Stut 			runbib(indexname);
5212289Stut 			time(&indexdate);
5312289Stut 		}
5412289Stut 		else /* failure */
5512289Stut 		return(0);
5612289Stut 	return(1); /* success */
5712289Stut }
5812289Stut 
5912289Stut ckexist(s, t)
6012289Stut char *s, *t;
6112289Stut {
6212289Stut 	char fnam[100];
6312289Stut 	strcpy (fnam, s);
6412289Stut 	strcat (fnam, t);
6512289Stut 	return (access(fnam, 04) != -1);
6612289Stut }
6712289Stut 
6812289Stut FILE *
6912289Stut iopen(s, t)
7012289Stut char *s, *t;
7112289Stut {
7212289Stut 	char fnam[100];
7312289Stut 	FILE *f;
7412289Stut 	strcpy (fnam, s);
7512289Stut 	strcat (fnam, t);
7612289Stut 	f = fopen (fnam, "r");
7712289Stut 	if (f == NULL)
7812289Stut 	{
7912289Stut 		err("Missing expected file %s", fnam);
8012289Stut 		exit(1);
8112289Stut 	}
8212289Stut 	return(f);
8312289Stut }
84