xref: /illumos-gate/usr/src/cmd/refer/hunt5.c (revision 03100a6332bd4edc7a53091fcf7c9a7131bcdaa7)
1 /*
2  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
7 /*	  All Rights Reserved  	*/
8 
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 
15 #pragma ident	"%Z%%M%	%I%	%E% SMI"
16 
17 #include <stdio.h>
18 #include <sys/types.h>
19 #include <sys/stat.h>
20 
21 extern char *soutput, *tagout, usedir[];
22 union ptr {
23 	unsigned *a;
24 	long *b;
25 };
26 
27 void
28 result(unsigned *mptr, int nf, FILE *fc)
29 {
30 	int i, c;
31 	char *s;
32 	long lp;
33 	extern int iflong;
34 	char res[100];
35 	union ptr master;
36 
37 	if (iflong) {
38 		master.b = (long *)mptr;
39 	} else {
40 		master.a = mptr;
41 	}
42 
43 	for (i = 0; i < nf; i++) {
44 		lp = iflong ? master.b[i] : master.a[i];
45 		fseek(fc, lp, 0);
46 		fgets(res, 100, fc);
47 		for (s = res; c = *s; s++)
48 			if (c == ';') {
49 				*s = 0;
50 				break;
51 			}
52 		if (tagout != 0) {
53 			if (res[0] == '/' || usedir[0] == 0)
54 				sprintf(tagout, "%s", res);
55 			else
56 				sprintf(tagout, "%s/%s", usedir, res);
57 			while (*tagout) tagout++;
58 		} else {
59 			if (res[0] != '/' || usedir[0] == 0)
60 				printf("%s/", usedir);
61 			printf("%s\n", res);
62 		}
63 	}
64 }
65 
66 long
67 gdate(f)
68 FILE *f;
69 {
70 	struct stat sb;
71 	fstat(fileno(f), &sb);
72 	return (sb . st_mtime);
73 }
74