xref: /original-bsd/usr.bin/ar/print.c (revision 7e5c8007)
1 /*-
2  * Copyright (c) 1990, 1993, 1994
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Hugh Smith at The University of Guelph.
7  *
8  * %sccs.include.redist.c%
9  */
10 
11 #ifndef lint
12 static char sccsid[] = "@(#)print.c	8.3 (Berkeley) 04/02/94";
13 #endif /* not lint */
14 
15 #include <sys/param.h>
16 
17 #include <dirent.h>
18 #include <fcntl.h>
19 #include <stdio.h>
20 #include <unistd.h>
21 
22 #include "archive.h"
23 #include "extern.h"
24 
25 /*
26  * print --
27  *	Prints archive members on stdout - if member names given only
28  *	print those members, otherwise print all members.
29  */
30 int
31 print(argv)
32 	char **argv;
33 {
34 	CF cf;
35 	int afd, all;
36 	char *file;
37 
38 	afd = open_archive(O_RDONLY);
39 
40 	/* Read from an archive, write to stdout; pad on read. */
41 	SETCF(afd, archive, STDOUT_FILENO, "stdout", RPAD);
42 	for (all = !*argv; get_arobj(afd);) {
43 		if (all)
44 			file = chdr.name;
45 		else if (!(file = files(argv))) {
46 			skip_arobj(afd);
47 			continue;
48 		}
49 		if (options & AR_V) {
50 			(void)printf("\n<%s>\n\n", file);
51 			(void)fflush(stdout);
52 		}
53 		copy_ar(&cf, chdr.size);
54 		if (!all && !*argv)
55 			break;
56 	}
57 	close_archive(afd);
58 
59 	if (*argv) {
60 		orphans(argv);
61 		return (1);
62 	}
63 	return (0);
64 }
65