2 * Copyright (c) 1990, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Hugh Smith at The University of Guelph.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * $FreeBSD: src/usr.bin/ar/ar.c,v 1.8.2.1 2001/08/02 00:51:00 obrien Exp $
37 * $DragonFly: src/usr.bin/ar/Attic/ar.c,v 1.4 2003/11/03 19:31:28 eirikn Exp $
39 * @(#) Copyright (c) 1990, 1993, 1994 The Regents of the University of California. All rights reserved.
40 * @(#)ar.c 8.3 (Berkeley) 4/2/94
43 #include <sys/param.h>
61 char *archive, *envtmp, *posarg, *posname;
62 static void badoptions(char *);
63 static void usage(void);
67 * main basically uses getopt to parse options and calls the appropriate
68 * functions. Some hacks that let us be backward compatible with 4.3 ar
69 * option parsing and sanity checking.
72 main(int argc, char **argv)
76 int (*fcall)(char **) = NULL;
78 (void) setlocale(LC_TIME, "");;
84 * Historic versions didn't require a '-' in front of the options.
85 * Fix it, if necessary.
87 if (*argv[1] != '-') {
88 if (!(p = malloc((u_int)(strlen(argv[1]) + 2))))
91 (void)strcpy(p + 1, argv[1]);
95 while ((c = getopt(argc, argv, "abcdilmopqrTtuvx")) != -1) {
111 case 'l': /* not documented, compatibility only */
158 /* One of -dmpqrtx required. */
159 if (!(options & (AR_D|AR_M|AR_P|AR_Q|AR_R|AR_T|AR_X))) {
160 warnx("one of options -dmpqrtx is required");
163 /* Only one of -a and -bi allowed. */
164 if (options & AR_A && options & AR_B) {
165 warnx("only one of -a and -[bi] options allowed");
168 /* -ab require a position argument. */
169 if (options & (AR_A|AR_B)) {
170 if (!(posarg = *argv++)) {
171 warnx("no position operand specified");
174 posname = basename(posarg);
176 /* -d only valid with -Tv. */
177 if (options & AR_D && options & ~(AR_D|AR_TR|AR_V))
179 /* -m only valid with -abiTv. */
180 if (options & AR_M && options & ~(AR_A|AR_B|AR_M|AR_TR|AR_V))
182 /* -p only valid with -Tv. */
183 if (options & AR_P && options & ~(AR_P|AR_TR|AR_V))
185 /* -q only valid with -cTv. */
186 if (options & AR_Q && options & ~(AR_C|AR_Q|AR_TR|AR_V))
188 /* -r only valid with -abcuTv. */
189 if (options & AR_R && options & ~(AR_A|AR_B|AR_C|AR_R|AR_U|AR_TR|AR_V))
191 /* -t only valid with -Tv. */
192 if (options & AR_T && options & ~(AR_T|AR_TR|AR_V))
194 /* -x only valid with -ouTv. */
195 if (options & AR_X && options & ~(AR_O|AR_U|AR_TR|AR_V|AR_X))
198 if (!(archive = *argv++)) {
199 warnx("no archive specified");
203 /* -dmr require a list of archive elements. */
204 if (options & (AR_D|AR_M|AR_R) && !*argv) {
205 warnx("no archive members specified");
209 exit((*fcall)(argv));
213 badoptions(char *arg)
216 warnx("illegal option combination for %s", arg);
224 (void)fprintf(stderr, "%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n",
225 "usage: ar -d [-Tv] archive file ...",
226 " ar -m [-Tv] archive file ...",
227 " ar -m [-abiTv] position archive file ...",
228 " ar -p [-Tv] archive [file ...]",
229 " ar -q [-cTv] archive file ...",
230 " ar -r [-cuTv] archive file ...",
231 " ar -r [-abciuTv] position archive file ...",
232 " ar -t [-Tv] archive [file ...]",
233 " ar -x [-ouTv] archive [file ...]");