hunt8.c (0:68f95e015346) hunt8.c (719:6c26331bc6b8)
1/*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
5
1/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
2/* All Rights Reserved */
3
6/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7/* All Rights Reserved */
8
4
5/*
6 * Copyright (c) 1980 Regents of the University of California.
7 * All rights reserved. The Berkeley software License Agreement
8 * specifies the terms and conditions for redistribution.
9 */
10
9/*
10 * Copyright (c) 1980 Regents of the University of California.
11 * All rights reserved. The Berkeley software License Agreement
12 * specifies the terms and conditions for redistribution.
13 */
14
11/*
12 * Copyright (c) 1983, 1984 1985, 1986, 1987, 1988, Sun Microsystems, Inc.
13 * All Rights Reserved.
14 */
15#pragma ident "%Z%%M% %I% %E% SMI"
15
16
16#pragma ident "%Z%%M% %I% %E% SMI"
17
18#include <locale.h>
19#include <stdio.h>
20#include <assert.h>
17#include <locale.h>
18#include <stdio.h>
19#include <assert.h>
21#define unopen(fil) {if (fil!=NULL) {fclose(fil); fil=NULL;}}
20#define unopen(fil) {if (fil != NULL) {fclose(fil); fil = NULL; }}
22
21
22extern void err();
23extern long indexdate, gdate();
24extern FILE *iopen();
23extern long indexdate, gdate();
24extern FILE *iopen();
25runbib (s)
26char *s;
25
26int ckexist(char *, char *);
27
28static void
29runbib(char *s)
27{
28 /* make a file suitable for fgrep */
29 char tmp[200];
30{
31 /* make a file suitable for fgrep */
32 char tmp[200];
30 sprintf(tmp, "/usr/lib/refer/mkey '%s' > '%s.ig'", s,s);
33 sprintf(tmp, "/usr/lib/refer/mkey '%s' > '%s.ig'", s, s);
31 system(tmp);
32}
33
34 system(tmp);
35}
36
34makefgrep(indexname)
35char *indexname;
37int
38makefgrep(char *indexname)
36{
37 FILE *fa, *fb;
39{
40 FILE *fa, *fb;
38 if (ckexist(indexname, ".ig"))
39 {
41 if (ckexist(indexname, ".ig")) {
40 /* existing gfrep -type index */
42 /* existing gfrep -type index */
41# if D1
43#if D1
42 fprintf(stderr, "found fgrep\n");
44 fprintf(stderr, "found fgrep\n");
43# endif
45#endif
44 fa = iopen(indexname, ".ig");
45 fb = iopen(indexname, "");
46 fa = iopen(indexname, ".ig");
47 fb = iopen(indexname, "");
46 if (gdate(fb)>gdate(fa))
47 {
48 if (fa!=NULL)
48 if (gdate(fb) > gdate(fa)) {
49 if (fa != NULL)
49 fclose(fa);
50 runbib(indexname);
50 fclose(fa);
51 runbib(indexname);
51 fa= iopen(indexname, ".ig");
52 fa = iopen(indexname, ".ig");
52 }
53 indexdate = gdate(fa);
53 }
54 indexdate = gdate(fa);
54 unopen(fa);
55 unopen(fa);
55 unopen(fb);
56 unopen(fb);
56 }
57 else
58 if (ckexist(indexname, ""))
59 {
57 } else
58 if (ckexist(indexname, "")) {
60 /* make fgrep */
59 /* make fgrep */
61# if D1
60#if D1
62 fprintf(stderr, "make fgrep\n");
61 fprintf(stderr, "make fgrep\n");
63# endif
62#endif
64 runbib(indexname);
65 time(&indexdate);
63 runbib(indexname);
64 time(&indexdate);
66 }
67 else /* failure */
68 return(0);
69 return(1); /* success */
65 } else /* failure */
66 return (0);
67 return (1); /* success */
70}
71
68}
69
72ckexist(s, t)
73char *s, *t;
70int
71ckexist(char *s, char *t)
74{
75 char fnam[100];
72{
73 char fnam[100];
76 strcpy (fnam, s);
77 strcat (fnam, t);
74 strcpy(fnam, s);
75 strcat(fnam, t);
78 return (access(fnam, 04) != -1);
79}
80
81FILE *
76 return (access(fnam, 04) != -1);
77}
78
79FILE *
82iopen(s, t)
83char *s, *t;
80iopen(char *s, char *t)
84{
85 char fnam[100];
86 FILE *f;
81{
82 char fnam[100];
83 FILE *f;
87 strcpy (fnam, s);
88 strcat (fnam, t);
89 f = fopen (fnam, "r");
90 if (f == NULL)
91 {
84 strcpy(fnam, s);
85 strcat(fnam, t);
86 f = fopen(fnam, "r");
87 if (f == NULL) {
92 err(gettext("Missing expected file %s"), fnam);
93 exit(1);
94 }
88 err(gettext("Missing expected file %s"), fnam);
89 exit(1);
90 }
95 return(f);
91 return (f);
96}
92}