home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / cmd / refer / hunt8.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-01-10  |  1.2 KB  |  73 lines

  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. runbib (s)
  6.     char *s;
  7. {
  8. /* make a file suitable for fgrep */
  9. char tmp[200];
  10. sprintf(tmp, "/usr/lib/refer/mkey %s >%s.ig", s,s);
  11. system(tmp);
  12. }
  13. makefgrep(indexname)
  14.     char *indexname;
  15. {
  16.     FILE *fa =NULL, *fb =NULL;
  17.     if (ckexist(indexname, ".ig"))
  18.         {
  19.         /* existing gfrep -type index */
  20. # if D1
  21.         fprintf(stderr, "found fgrep\n");
  22. # endif
  23.         fa = iopen(indexname, ".ig");
  24.         fb = iopen(indexname, "");
  25.         if (gdate(fb)>gdate(fa))
  26.             {
  27.             if (fa!=NULL)
  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. iopen (s, t)
  59.     char *s, *t;
  60. {
  61. char fnam[100];
  62. FILE *f;
  63. strcpy (fnam, s);
  64. strcat (fnam, t);
  65. f = fopen (fnam, "r");
  66. if (f == NULL)
  67.     {
  68.     err("Missing expected file %s", fnam);
  69.     exit(1);
  70.     }
  71. return(f);
  72. }
  73.