xref: /illumos-gate/usr/src/cmd/refer/hunt5.c (revision 2a8bcb4e)
1*11a8fa6cSceastha /*
2*11a8fa6cSceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*11a8fa6cSceastha  * Use is subject to license terms.
4*11a8fa6cSceastha  */
5*11a8fa6cSceastha 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
77c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980 Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
127c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
137c478bd9Sstevel@tonic-gate  */
147c478bd9Sstevel@tonic-gate 
157c478bd9Sstevel@tonic-gate #include <stdio.h>
167c478bd9Sstevel@tonic-gate #include <sys/types.h>
177c478bd9Sstevel@tonic-gate #include <sys/stat.h>
187c478bd9Sstevel@tonic-gate 
197c478bd9Sstevel@tonic-gate extern char *soutput, *tagout, usedir[];
207c478bd9Sstevel@tonic-gate union ptr {
21*11a8fa6cSceastha 	unsigned *a;
227c478bd9Sstevel@tonic-gate 	long *b;
237c478bd9Sstevel@tonic-gate };
247c478bd9Sstevel@tonic-gate 
25*11a8fa6cSceastha void
result(unsigned * mptr,int nf,FILE * fc)26*11a8fa6cSceastha result(unsigned *mptr, int nf, FILE *fc)
277c478bd9Sstevel@tonic-gate {
287c478bd9Sstevel@tonic-gate 	int i, c;
297c478bd9Sstevel@tonic-gate 	char *s;
307c478bd9Sstevel@tonic-gate 	long lp;
317c478bd9Sstevel@tonic-gate 	extern int iflong;
327c478bd9Sstevel@tonic-gate 	char res[100];
337c478bd9Sstevel@tonic-gate 	union ptr master;
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate 	if (iflong) {
36*11a8fa6cSceastha 		master.b = (long *)mptr;
37*11a8fa6cSceastha 	} else {
387c478bd9Sstevel@tonic-gate 		master.a = mptr;
397c478bd9Sstevel@tonic-gate 	}
407c478bd9Sstevel@tonic-gate 
41*11a8fa6cSceastha 	for (i = 0; i < nf; i++) {
427c478bd9Sstevel@tonic-gate 		lp = iflong ? master.b[i] : master.a[i];
43*11a8fa6cSceastha 		fseek(fc, lp, 0);
447c478bd9Sstevel@tonic-gate 		fgets(res, 100, fc);
45*11a8fa6cSceastha 		for (s = res; c = *s; s++)
46*11a8fa6cSceastha 			if (c == ';') {
47*11a8fa6cSceastha 				*s = 0;
487c478bd9Sstevel@tonic-gate 				break;
497c478bd9Sstevel@tonic-gate 			}
50*11a8fa6cSceastha 		if (tagout != 0) {
51*11a8fa6cSceastha 			if (res[0] == '/' || usedir[0] == 0)
527c478bd9Sstevel@tonic-gate 				sprintf(tagout, "%s", res);
537c478bd9Sstevel@tonic-gate 			else
547c478bd9Sstevel@tonic-gate 				sprintf(tagout, "%s/%s", usedir, res);
557c478bd9Sstevel@tonic-gate 			while (*tagout) tagout++;
56*11a8fa6cSceastha 		} else {
57*11a8fa6cSceastha 			if (res[0] != '/' || usedir[0] == 0)
587c478bd9Sstevel@tonic-gate 				printf("%s/", usedir);
597c478bd9Sstevel@tonic-gate 			printf("%s\n", res);
607c478bd9Sstevel@tonic-gate 		}
617c478bd9Sstevel@tonic-gate 	}
627c478bd9Sstevel@tonic-gate }
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate long
gdate(f)657c478bd9Sstevel@tonic-gate gdate(f)
667c478bd9Sstevel@tonic-gate FILE *f;
677c478bd9Sstevel@tonic-gate {
687c478bd9Sstevel@tonic-gate 	struct stat sb;
69*11a8fa6cSceastha 	fstat(fileno(f), &sb);
70*11a8fa6cSceastha 	return (sb . st_mtime);
717c478bd9Sstevel@tonic-gate }
72