make ORPHANS a function; files() bug fix
[unix-history] / usr / src / usr.bin / ar / print.c
CommitLineData
5681c8bf
KB
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * 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
af52bb8a 12static char sccsid[] = "@(#)print.c 5.4 (Berkeley) %G%";
5681c8bf
KB
13#endif /* not lint */
14
15#include <sys/param.h>
16#include <fcntl.h>
17#include <unistd.h>
18#include <dirent.h>
19#include <stdio.h>
20#include "archive.h"
21
22extern CHDR chdr; /* converted header */
23extern char *archive; /* archive name */
24
25/*
26 * print --
27 * Prints archive members on stdout - if member names given only
28 * print those members, otherwise print all members.
29 */
30print(argv)
31 char **argv;
32{
33 CF cf;
34 register int afd, all;
35 int eval;
af52bb8a 36 char *file;
5681c8bf
KB
37
38 afd = open_archive(O_RDONLY);
39
35aab8af 40 /* Read from an archive, write to stdout; pad on read. */
5681c8bf
KB
41 SETCF(afd, archive, STDOUT_FILENO, "stdout", RPAD);
42 for (all = !*argv; get_header(afd);) {
af52bb8a
KB
43 if (all)
44 file = chdr.name;
45 else {
46 file = *argv;
47 if (!files(argv)) {
48 skipobj(afd);
49 continue;
50 }
5681c8bf
KB
51 }
52 if (options & AR_V) {
af52bb8a 53 (void)printf("\n<%s>\n\n", file);
5681c8bf
KB
54 (void)fflush(stdout);
55 }
56 copyfile(&cf, chdr.size);
57 if (!all && !*argv)
58 break;
59 }
44c5e2d6 60 eval = 0;
5681c8bf
KB
61 ORPHANS;
62 close_archive(afd);
63 return(eval);
64}