8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / refer / hunt8.c
blobf33a5bc026a0a22047feaf13339647705f120023
1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
6 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
7 /* All Rights Reserved */
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.
15 #pragma ident "%Z%%M% %I% %E% SMI"
17 #include <locale.h>
18 #include <stdio.h>
19 #include <assert.h>
20 #define unopen(fil) {if (fil != NULL) {fclose(fil); fil = NULL; }}
22 extern void err();
23 extern long indexdate, gdate();
24 extern FILE *iopen();
26 int ckexist(char *, char *);
28 static void
29 runbib(char *s)
31 /* make a file suitable for fgrep */
32 char tmp[200];
33 sprintf(tmp, "/usr/lib/refer/mkey '%s' > '%s.ig'", s, s);
34 system(tmp);
37 int
38 makefgrep(char *indexname)
40 FILE *fa, *fb;
41 if (ckexist(indexname, ".ig")) {
42 /* existing gfrep -type index */
43 #if D1
44 fprintf(stderr, "found fgrep\n");
45 #endif
46 fa = iopen(indexname, ".ig");
47 fb = iopen(indexname, "");
48 if (gdate(fb) > gdate(fa)) {
49 if (fa != NULL)
50 fclose(fa);
51 runbib(indexname);
52 fa = iopen(indexname, ".ig");
54 indexdate = gdate(fa);
55 unopen(fa);
56 unopen(fb);
57 } else
58 if (ckexist(indexname, "")) {
59 /* make fgrep */
60 #if D1
61 fprintf(stderr, "make fgrep\n");
62 #endif
63 runbib(indexname);
64 time(&indexdate);
65 } else /* failure */
66 return (0);
67 return (1); /* success */
70 int
71 ckexist(char *s, char *t)
73 char fnam[100];
74 strcpy(fnam, s);
75 strcat(fnam, t);
76 return (access(fnam, 04) != -1);
79 FILE *
80 iopen(char *s, char *t)
82 char fnam[100];
83 FILE *f;
84 strcpy(fnam, s);
85 strcat(fnam, t);
86 f = fopen(fnam, "r");
87 if (f == NULL) {
88 err(gettext("Missing expected file %s"), fnam);
89 exit(1);
91 return (f);