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