date and time created 83/05/06 23:47:24 by tut
authorBill Tuthill <tut@ucbvax.Berkeley.EDU>
Sat, 7 May 1983 14:47:24 +0000 (06:47 -0800)
committerBill Tuthill <tut@ucbvax.Berkeley.EDU>
Sat, 7 May 1983 14:47:24 +0000 (06:47 -0800)
SCCS-vsn: old/refer/hunt/hunt8.c 4.1

usr/src/old/refer/hunt/hunt8.c [new file with mode: 0644]

diff --git a/usr/src/old/refer/hunt/hunt8.c b/usr/src/old/refer/hunt/hunt8.c
new file mode 100644 (file)
index 0000000..31fb947
--- /dev/null
@@ -0,0 +1,83 @@
+#ifndef lint
+static char *sccsid = "@(#)hunt8.c     4.1 (Berkeley) %G%";
+#endif
+
+#include <stdio.h>
+#include <assert.h>
+#define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}}
+
+extern long indexdate, gdate();
+extern FILE *iopen();
+runbib (s)
+char *s;
+{
+       /* make a file suitable for fgrep */
+       char tmp[200];
+       sprintf(tmp, "/usr/lib/refer/mkey %s >%s.ig", s,s);
+       system(tmp);
+}
+
+makefgrep(indexname)
+char *indexname;
+{
+       FILE *fa, *fb;
+       if (ckexist(indexname, ".ig"))
+       {
+               /* existing gfrep -type index */
+# if D1
+               fprintf(stderr, "found fgrep\n");
+# endif
+               fa = iopen(indexname, ".ig");
+               fb = iopen(indexname, "");
+               if (gdate(fb)>gdate(fa))
+               {
+                       if (fa!=NULL)
+                               fclose(fa);
+                       runbib(indexname);
+                       fa= iopen(indexname, ".ig");
+               }
+               indexdate = gdate(fa);
+               unopen(fa); 
+               unopen(fb);
+       }
+       else
+               if (ckexist(indexname, ""))
+               {
+                       /* make fgrep */
+# if D1
+                       fprintf(stderr, "make fgrep\n");
+# endif
+                       runbib(indexname);
+                       time(&indexdate);
+                       unopen(fb);
+               }
+               else /* failure */
+               return(0);
+       return(1); /* success */
+}
+
+ckexist(s, t)
+char *s, *t;
+{
+       char fnam[100];
+       strcpy (fnam, s);
+       strcat (fnam, t);
+       return (access(fnam, 04) != -1);
+}
+
+FILE *
+iopen(s, t)
+char *s, *t;
+{
+       char fnam[100];
+       FILE *f;
+       strcpy (fnam, s);
+       strcat (fnam, t);
+       f = fopen (fnam, "r");
+       if (f == NULL)
+       {
+               err("Missing expected file %s", fnam);
+               exit(1);
+       }
+       return(f);
+}