Home | History | Annotate | Line # | Download | only in pax
options.c revision 1.25.2.2
      1  1.25.2.2  mycroft /*	$NetBSD: options.c,v 1.25.2.2 1999/11/07 15:57:32 mycroft Exp $	*/
      2  1.25.2.2  mycroft 
      3  1.25.2.2  mycroft /*-
      4  1.25.2.2  mycroft  * Copyright (c) 1992 Keith Muller.
      5  1.25.2.2  mycroft  * Copyright (c) 1992, 1993
      6  1.25.2.2  mycroft  *	The Regents of the University of California.  All rights reserved.
      7  1.25.2.2  mycroft  *
      8  1.25.2.2  mycroft  * This code is derived from software contributed to Berkeley by
      9  1.25.2.2  mycroft  * Keith Muller of the University of California, San Diego.
     10  1.25.2.2  mycroft  *
     11  1.25.2.2  mycroft  * Redistribution and use in source and binary forms, with or without
     12  1.25.2.2  mycroft  * modification, are permitted provided that the following conditions
     13  1.25.2.2  mycroft  * are met:
     14  1.25.2.2  mycroft  * 1. Redistributions of source code must retain the above copyright
     15  1.25.2.2  mycroft  *    notice, this list of conditions and the following disclaimer.
     16  1.25.2.2  mycroft  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.25.2.2  mycroft  *    notice, this list of conditions and the following disclaimer in the
     18  1.25.2.2  mycroft  *    documentation and/or other materials provided with the distribution.
     19  1.25.2.2  mycroft  * 3. All advertising materials mentioning features or use of this software
     20  1.25.2.2  mycroft  *    must display the following acknowledgement:
     21  1.25.2.2  mycroft  *	This product includes software developed by the University of
     22  1.25.2.2  mycroft  *	California, Berkeley and its contributors.
     23  1.25.2.2  mycroft  * 4. Neither the name of the University nor the names of its contributors
     24  1.25.2.2  mycroft  *    may be used to endorse or promote products derived from this software
     25  1.25.2.2  mycroft  *    without specific prior written permission.
     26  1.25.2.2  mycroft  *
     27  1.25.2.2  mycroft  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28  1.25.2.2  mycroft  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29  1.25.2.2  mycroft  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30  1.25.2.2  mycroft  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31  1.25.2.2  mycroft  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32  1.25.2.2  mycroft  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33  1.25.2.2  mycroft  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34  1.25.2.2  mycroft  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35  1.25.2.2  mycroft  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36  1.25.2.2  mycroft  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37  1.25.2.2  mycroft  * SUCH DAMAGE.
     38  1.25.2.2  mycroft  */
     39  1.25.2.2  mycroft 
     40  1.25.2.2  mycroft #include <sys/cdefs.h>
     41  1.25.2.2  mycroft #ifndef lint
     42  1.25.2.2  mycroft #if 0
     43  1.25.2.2  mycroft static char sccsid[] = "@(#)options.c	8.2 (Berkeley) 4/18/94";
     44  1.25.2.2  mycroft #else
     45  1.25.2.2  mycroft __RCSID("$NetBSD: options.c,v 1.25.2.2 1999/11/07 15:57:32 mycroft Exp $");
     46  1.25.2.2  mycroft #endif
     47  1.25.2.2  mycroft #endif /* not lint */
     48  1.25.2.2  mycroft 
     49  1.25.2.2  mycroft #include <sys/types.h>
     50  1.25.2.2  mycroft #include <sys/time.h>
     51  1.25.2.2  mycroft #include <sys/stat.h>
     52  1.25.2.2  mycroft #include <sys/mtio.h>
     53  1.25.2.2  mycroft #include <sys/param.h>
     54  1.25.2.2  mycroft #include <stdio.h>
     55  1.25.2.2  mycroft #include <ctype.h>
     56  1.25.2.2  mycroft #include <string.h>
     57  1.25.2.2  mycroft #include <unistd.h>
     58  1.25.2.2  mycroft #include <stdlib.h>
     59  1.25.2.2  mycroft #include <limits.h>
     60  1.25.2.2  mycroft #include "pax.h"
     61  1.25.2.2  mycroft #include "options.h"
     62  1.25.2.2  mycroft #include "cpio.h"
     63  1.25.2.2  mycroft #include "tar.h"
     64  1.25.2.2  mycroft #include "extern.h"
     65  1.25.2.2  mycroft 
     66  1.25.2.2  mycroft /*
     67  1.25.2.2  mycroft  * Routines which handle command line options
     68  1.25.2.2  mycroft  */
     69  1.25.2.2  mycroft 
     70  1.25.2.2  mycroft int cpio_mode;			/* set if we are in cpio mode */
     71  1.25.2.2  mycroft 
     72  1.25.2.2  mycroft static int nopids;		/* tar mode: suppress "pids" for -p option */
     73  1.25.2.2  mycroft static char *flgch = FLGCH;	/* list of all possible flags (pax) */
     74  1.25.2.2  mycroft static OPLIST *ophead = NULL;	/* head for format specific options -x */
     75  1.25.2.2  mycroft static OPLIST *optail = NULL;	/* option tail */
     76  1.25.2.2  mycroft static char *firstminusC;	/* first -C argument encountered. */
     77  1.25.2.2  mycroft 
     78  1.25.2.2  mycroft static int no_op __P((void));
     79  1.25.2.2  mycroft static void printflg __P((unsigned int));
     80  1.25.2.2  mycroft static int c_frmt __P((const void *, const void *));
     81  1.25.2.2  mycroft static off_t str_offt __P((char *));
     82  1.25.2.2  mycroft static void pax_options __P((int, char **));
     83  1.25.2.2  mycroft static void pax_usage __P((void));
     84  1.25.2.2  mycroft static void tar_options __P((int, char **));
     85  1.25.2.2  mycroft static void tar_usage __P((void));
     86  1.25.2.2  mycroft static void cpio_options __P((int, char **));
     87  1.25.2.2  mycroft static void cpio_usage __P((void));
     88  1.25.2.2  mycroft 
     89  1.25.2.2  mycroft static void checkpositionalminusC __P((char ***, int (*)(char *, int)));
     90  1.25.2.2  mycroft 
     91  1.25.2.2  mycroft #define GZIP_CMD	"gzip"		/* command to run as gzip */
     92  1.25.2.2  mycroft #define COMPRESS_CMD	"compress"	/* command to run as compress */
     93  1.25.2.2  mycroft 
     94  1.25.2.2  mycroft /*
     95  1.25.2.2  mycroft  *	Format specific routine table - MUST BE IN SORTED ORDER BY NAME
     96  1.25.2.2  mycroft  *	(see pax.h for description of each function)
     97  1.25.2.2  mycroft  *
     98  1.25.2.2  mycroft  * 	name, blksz, hdsz, udev, hlk, blkagn, inhead, id, st_read,
     99  1.25.2.2  mycroft  *	read, end_read, st_write, write, end_write, trail,
    100  1.25.2.2  mycroft  *	rd_data, wr_data, options
    101  1.25.2.2  mycroft  */
    102  1.25.2.2  mycroft 
    103  1.25.2.2  mycroft FSUB fsub[] = {
    104  1.25.2.2  mycroft /* 0: OLD BINARY CPIO */
    105  1.25.2.2  mycroft 	{ "bcpio", 5120, sizeof(HD_BCPIO), 1, 0, 0, 1, bcpio_id, cpio_strd,
    106  1.25.2.2  mycroft 	bcpio_rd, bcpio_endrd, cpio_stwr, bcpio_wr, cpio_endwr, NULL,
    107  1.25.2.2  mycroft 	cpio_subtrail, rd_wrfile, wr_rdfile, bad_opt },
    108  1.25.2.2  mycroft 
    109  1.25.2.2  mycroft /* 1: OLD OCTAL CHARACTER CPIO */
    110  1.25.2.2  mycroft 	{ "cpio", 5120, sizeof(HD_CPIO), 1, 0, 0, 1, cpio_id, cpio_strd,
    111  1.25.2.2  mycroft 	cpio_rd, cpio_endrd, cpio_stwr, cpio_wr, cpio_endwr, NULL,
    112  1.25.2.2  mycroft 	cpio_subtrail, rd_wrfile, wr_rdfile, bad_opt },
    113  1.25.2.2  mycroft 
    114  1.25.2.2  mycroft /* 2: SVR4 HEX CPIO */
    115  1.25.2.2  mycroft 	{ "sv4cpio", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, vcpio_id, cpio_strd,
    116  1.25.2.2  mycroft 	vcpio_rd, vcpio_endrd, cpio_stwr, vcpio_wr, cpio_endwr, NULL,
    117  1.25.2.2  mycroft 	cpio_subtrail, rd_wrfile, wr_rdfile, bad_opt },
    118  1.25.2.2  mycroft 
    119  1.25.2.2  mycroft /* 3: SVR4 HEX CPIO WITH CRC */
    120  1.25.2.2  mycroft 	{ "sv4crc", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, crc_id, crc_strd,
    121  1.25.2.2  mycroft 	vcpio_rd, vcpio_endrd, crc_stwr, vcpio_wr, cpio_endwr, NULL,
    122  1.25.2.2  mycroft 	cpio_subtrail, rd_wrfile, wr_rdfile, bad_opt },
    123  1.25.2.2  mycroft 
    124  1.25.2.2  mycroft /* 4: OLD TAR */
    125  1.25.2.2  mycroft 	{ "tar", 10240, BLKMULT, 0, 1, BLKMULT, 0, tar_id, no_op,
    126  1.25.2.2  mycroft 	tar_rd, tar_endrd, no_op, tar_wr, tar_endwr, tar_trail,
    127  1.25.2.2  mycroft 	NULL, rd_wrfile, wr_rdfile, tar_opt },
    128  1.25.2.2  mycroft 
    129  1.25.2.2  mycroft /* 5: POSIX USTAR */
    130  1.25.2.2  mycroft 	{ "ustar", 10240, BLKMULT, 0, 1, BLKMULT, 0, ustar_id, ustar_strd,
    131  1.25.2.2  mycroft 	ustar_rd, tar_endrd, ustar_stwr, ustar_wr, tar_endwr, tar_trail,
    132  1.25.2.2  mycroft 	NULL, rd_wrfile, wr_rdfile, bad_opt }
    133  1.25.2.2  mycroft };
    134  1.25.2.2  mycroft #define F_BCPIO		0	/* old binary cpio format */
    135  1.25.2.2  mycroft #define F_CPIO		1	/* old octal character cpio format */
    136  1.25.2.2  mycroft #define F_SV4CPIO	2	/* SVR4 hex cpio format */
    137  1.25.2.2  mycroft #define F_SV4CRC	3	/* SVR4 hex with crc cpio format */
    138  1.25.2.2  mycroft #define F_TAR		4	/* old V7 UNIX tar format */
    139  1.25.2.2  mycroft #define F_USTAR		5	/* ustar format */
    140  1.25.2.2  mycroft #define DEFLT		F_USTAR	/* default write format from list above */
    141  1.25.2.2  mycroft 
    142  1.25.2.2  mycroft /*
    143  1.25.2.2  mycroft  * ford is the archive search order used by get_arc() to determine what kind
    144  1.25.2.2  mycroft  * of archive we are dealing with. This helps to properly id  archive formats
    145  1.25.2.2  mycroft  * some formats may be subsets of others....
    146  1.25.2.2  mycroft  */
    147  1.25.2.2  mycroft int ford[] = {F_USTAR, F_TAR, F_SV4CRC, F_SV4CPIO, F_CPIO, F_BCPIO, -1};
    148  1.25.2.2  mycroft 
    149  1.25.2.2  mycroft /*
    150  1.25.2.2  mycroft  * options()
    151  1.25.2.2  mycroft  *	figure out if we are pax, tar or cpio. Call the appropriate options
    152  1.25.2.2  mycroft  *	parser
    153  1.25.2.2  mycroft  */
    154  1.25.2.2  mycroft 
    155  1.25.2.2  mycroft #if __STDC__
    156  1.25.2.2  mycroft void
    157  1.25.2.2  mycroft options(int argc, char **argv)
    158  1.25.2.2  mycroft #else
    159  1.25.2.2  mycroft void
    160  1.25.2.2  mycroft options(argc, argv)
    161  1.25.2.2  mycroft 	int argc;
    162  1.25.2.2  mycroft 	char **argv;
    163  1.25.2.2  mycroft #endif
    164  1.25.2.2  mycroft {
    165  1.25.2.2  mycroft 
    166  1.25.2.2  mycroft 	/*
    167  1.25.2.2  mycroft 	 * Are we acting like pax, tar or cpio (based on argv[0])
    168  1.25.2.2  mycroft 	 */
    169  1.25.2.2  mycroft 	if ((argv0 = strrchr(argv[0], '/')) != NULL)
    170  1.25.2.2  mycroft 		argv0++;
    171  1.25.2.2  mycroft 	else
    172  1.25.2.2  mycroft 		argv0 = argv[0];
    173  1.25.2.2  mycroft 
    174  1.25.2.2  mycroft 	if (strcmp(NM_TAR, argv0) == 0)
    175  1.25.2.2  mycroft 		tar_options(argc, argv);
    176  1.25.2.2  mycroft 	else if (strcmp(NM_CPIO, argv0) == 0)
    177  1.25.2.2  mycroft 		cpio_options(argc, argv);
    178  1.25.2.2  mycroft 	else {
    179  1.25.2.2  mycroft 		argv0 = NM_PAX;
    180  1.25.2.2  mycroft 		pax_options(argc, argv);
    181  1.25.2.2  mycroft 	}
    182  1.25.2.2  mycroft }
    183  1.25.2.2  mycroft 
    184  1.25.2.2  mycroft /*
    185  1.25.2.2  mycroft  * pax_options()
    186  1.25.2.2  mycroft  *	look at the user specified flags. set globals as required and check if
    187  1.25.2.2  mycroft  *	the user specified a legal set of flags. If not, complain and exit
    188  1.25.2.2  mycroft  */
    189  1.25.2.2  mycroft 
    190  1.25.2.2  mycroft #if __STDC__
    191  1.25.2.2  mycroft static void
    192  1.25.2.2  mycroft pax_options(int argc, char **argv)
    193  1.25.2.2  mycroft #else
    194  1.25.2.2  mycroft static void
    195  1.25.2.2  mycroft pax_options(argc, argv)
    196  1.25.2.2  mycroft 	int argc;
    197  1.25.2.2  mycroft 	char **argv;
    198  1.25.2.2  mycroft #endif
    199  1.25.2.2  mycroft {
    200  1.25.2.2  mycroft 	int c;
    201  1.25.2.2  mycroft 	int i;
    202  1.25.2.2  mycroft 	unsigned int flg = 0;
    203  1.25.2.2  mycroft 	unsigned int bflg = 0;
    204  1.25.2.2  mycroft 	char *pt;
    205  1.25.2.2  mycroft         FSUB tmp;
    206  1.25.2.2  mycroft 	extern char *optarg;
    207  1.25.2.2  mycroft 	extern int optind;
    208  1.25.2.2  mycroft 
    209  1.25.2.2  mycroft 	/*
    210  1.25.2.2  mycroft 	 * process option flags
    211  1.25.2.2  mycroft 	 */
    212  1.25.2.2  mycroft 	while ((c=getopt(argc,argv,"ab:cdf:iklno:p:rs:tuvwx:zAB:DE:G:HLPT:U:XYZ"))
    213  1.25.2.2  mycroft 	    != -1) {
    214  1.25.2.2  mycroft 		switch (c) {
    215  1.25.2.2  mycroft 		case 'a':
    216  1.25.2.2  mycroft 			/*
    217  1.25.2.2  mycroft 			 * append
    218  1.25.2.2  mycroft 			 */
    219  1.25.2.2  mycroft 			flg |= AF;
    220  1.25.2.2  mycroft 			break;
    221  1.25.2.2  mycroft 		case 'b':
    222  1.25.2.2  mycroft 			/*
    223  1.25.2.2  mycroft 			 * specify blocksize
    224  1.25.2.2  mycroft 			 */
    225  1.25.2.2  mycroft 			flg |= BF;
    226  1.25.2.2  mycroft 			if ((wrblksz = (int)str_offt(optarg)) <= 0) {
    227  1.25.2.2  mycroft 				tty_warn(1, "Invalid block size %s", optarg);
    228  1.25.2.2  mycroft 				pax_usage();
    229  1.25.2.2  mycroft 			}
    230  1.25.2.2  mycroft 			break;
    231  1.25.2.2  mycroft 		case 'c':
    232  1.25.2.2  mycroft 			/*
    233  1.25.2.2  mycroft 			 * inverse match on patterns
    234  1.25.2.2  mycroft 			 */
    235  1.25.2.2  mycroft 			cflag = 1;
    236  1.25.2.2  mycroft 			flg |= CF;
    237  1.25.2.2  mycroft 			break;
    238  1.25.2.2  mycroft 		case 'd':
    239  1.25.2.2  mycroft 			/*
    240  1.25.2.2  mycroft 			 * match only dir on extract, not the subtree at dir
    241  1.25.2.2  mycroft 			 */
    242  1.25.2.2  mycroft 			dflag = 1;
    243  1.25.2.2  mycroft 			flg |= DF;
    244  1.25.2.2  mycroft 			break;
    245  1.25.2.2  mycroft 		case 'f':
    246  1.25.2.2  mycroft 			/*
    247  1.25.2.2  mycroft 			 * filename where the archive is stored
    248  1.25.2.2  mycroft 			 */
    249  1.25.2.2  mycroft 			arcname = optarg;
    250  1.25.2.2  mycroft 			flg |= FF;
    251  1.25.2.2  mycroft 			break;
    252  1.25.2.2  mycroft 		case 'i':
    253  1.25.2.2  mycroft 			/*
    254  1.25.2.2  mycroft 			 * interactive file rename
    255  1.25.2.2  mycroft 			 */
    256  1.25.2.2  mycroft 			iflag = 1;
    257  1.25.2.2  mycroft 			flg |= IF;
    258  1.25.2.2  mycroft 			break;
    259  1.25.2.2  mycroft 		case 'k':
    260  1.25.2.2  mycroft 			/*
    261  1.25.2.2  mycroft 			 * do not clobber files that exist
    262  1.25.2.2  mycroft 			 */
    263  1.25.2.2  mycroft 			kflag = 1;
    264  1.25.2.2  mycroft 			flg |= KF;
    265  1.25.2.2  mycroft 			break;
    266  1.25.2.2  mycroft 		case 'l':
    267  1.25.2.2  mycroft 			/*
    268  1.25.2.2  mycroft 			 * try to link src to dest with copy (-rw)
    269  1.25.2.2  mycroft 			 */
    270  1.25.2.2  mycroft 			lflag = 1;
    271  1.25.2.2  mycroft 			flg |= LF;
    272  1.25.2.2  mycroft 			break;
    273  1.25.2.2  mycroft 		case 'n':
    274  1.25.2.2  mycroft 			/*
    275  1.25.2.2  mycroft 			 * select first match for a pattern only
    276  1.25.2.2  mycroft 			 */
    277  1.25.2.2  mycroft 			nflag = 1;
    278  1.25.2.2  mycroft 			flg |= NF;
    279  1.25.2.2  mycroft 			break;
    280  1.25.2.2  mycroft 		case 'o':
    281  1.25.2.2  mycroft 			/*
    282  1.25.2.2  mycroft 			 * pass format specific options
    283  1.25.2.2  mycroft 			 */
    284  1.25.2.2  mycroft 			flg |= OF;
    285  1.25.2.2  mycroft 			if (opt_add(optarg) < 0)
    286  1.25.2.2  mycroft 				pax_usage();
    287  1.25.2.2  mycroft 			break;
    288  1.25.2.2  mycroft 		case 'p':
    289  1.25.2.2  mycroft 			/*
    290  1.25.2.2  mycroft 			 * specify file characteristic options
    291  1.25.2.2  mycroft 			 */
    292  1.25.2.2  mycroft 			for (pt = optarg; *pt != '\0'; ++pt) {
    293  1.25.2.2  mycroft 				switch(*pt) {
    294  1.25.2.2  mycroft 				case 'a':
    295  1.25.2.2  mycroft 					/*
    296  1.25.2.2  mycroft 					 * do not preserve access time
    297  1.25.2.2  mycroft 					 */
    298  1.25.2.2  mycroft 					patime = 0;
    299  1.25.2.2  mycroft 					break;
    300  1.25.2.2  mycroft 				case 'e':
    301  1.25.2.2  mycroft 					/*
    302  1.25.2.2  mycroft 					 * preserve user id, group id, file
    303  1.25.2.2  mycroft 					 * mode, access/modification times
    304  1.25.2.2  mycroft 					 * and file flags.
    305  1.25.2.2  mycroft 					 */
    306  1.25.2.2  mycroft 					pids = 1;
    307  1.25.2.2  mycroft 					pmode = 1;
    308  1.25.2.2  mycroft 					patime = 1;
    309  1.25.2.2  mycroft 					pmtime = 1;
    310  1.25.2.2  mycroft 					pfflags = 1;
    311  1.25.2.2  mycroft 					break;
    312  1.25.2.2  mycroft #if 0
    313  1.25.2.2  mycroft 				case 'f':
    314  1.25.2.2  mycroft 					/*
    315  1.25.2.2  mycroft 					 * do not preserve file flags
    316  1.25.2.2  mycroft 					 */
    317  1.25.2.2  mycroft 					pfflags = 0;
    318  1.25.2.2  mycroft 					break;
    319  1.25.2.2  mycroft #endif
    320  1.25.2.2  mycroft 				case 'm':
    321  1.25.2.2  mycroft 					/*
    322  1.25.2.2  mycroft 					 * do not preserve modification time
    323  1.25.2.2  mycroft 					 */
    324  1.25.2.2  mycroft 					pmtime = 0;
    325  1.25.2.2  mycroft 					break;
    326  1.25.2.2  mycroft 				case 'o':
    327  1.25.2.2  mycroft 					/*
    328  1.25.2.2  mycroft 					 * preserve uid/gid
    329  1.25.2.2  mycroft 					 */
    330  1.25.2.2  mycroft 					pids = 1;
    331  1.25.2.2  mycroft 					break;
    332  1.25.2.2  mycroft 				case 'p':
    333  1.25.2.2  mycroft 					/*
    334  1.25.2.2  mycroft 					 * preserver file mode bits
    335  1.25.2.2  mycroft 					 */
    336  1.25.2.2  mycroft 					pmode = 1;
    337  1.25.2.2  mycroft 					break;
    338  1.25.2.2  mycroft 				default:
    339  1.25.2.2  mycroft 					tty_warn(1,
    340  1.25.2.2  mycroft 					    "Invalid -p string: %c", *pt);
    341  1.25.2.2  mycroft 					pax_usage();
    342  1.25.2.2  mycroft 					break;
    343  1.25.2.2  mycroft 				}
    344  1.25.2.2  mycroft 			}
    345  1.25.2.2  mycroft 			flg |= PF;
    346  1.25.2.2  mycroft 			break;
    347  1.25.2.2  mycroft 		case 'r':
    348  1.25.2.2  mycroft 			/*
    349  1.25.2.2  mycroft 			 * read the archive
    350  1.25.2.2  mycroft 			 */
    351  1.25.2.2  mycroft 			flg |= RF;
    352  1.25.2.2  mycroft 			break;
    353  1.25.2.2  mycroft 		case 's':
    354  1.25.2.2  mycroft 			/*
    355  1.25.2.2  mycroft 			 * file name substitution name pattern
    356  1.25.2.2  mycroft 			 */
    357  1.25.2.2  mycroft 			if (rep_add(optarg) < 0) {
    358  1.25.2.2  mycroft 				pax_usage();
    359  1.25.2.2  mycroft 				break;
    360  1.25.2.2  mycroft 			}
    361  1.25.2.2  mycroft 			flg |= SF;
    362  1.25.2.2  mycroft 			break;
    363  1.25.2.2  mycroft 		case 't':
    364  1.25.2.2  mycroft 			/*
    365  1.25.2.2  mycroft 			 * preserve access time on filesystem nodes we read
    366  1.25.2.2  mycroft 			 */
    367  1.25.2.2  mycroft 			tflag = 1;
    368  1.25.2.2  mycroft 			flg |= TF;
    369  1.25.2.2  mycroft 			break;
    370  1.25.2.2  mycroft 		case 'u':
    371  1.25.2.2  mycroft 			/*
    372  1.25.2.2  mycroft 			 * ignore those older files
    373  1.25.2.2  mycroft 			 */
    374  1.25.2.2  mycroft 			uflag = 1;
    375  1.25.2.2  mycroft 			flg |= UF;
    376  1.25.2.2  mycroft 			break;
    377  1.25.2.2  mycroft 		case 'v':
    378  1.25.2.2  mycroft 			/*
    379  1.25.2.2  mycroft 			 * verbose operation mode
    380  1.25.2.2  mycroft 			 */
    381  1.25.2.2  mycroft 			vflag = 1;
    382  1.25.2.2  mycroft 			flg |= VF;
    383  1.25.2.2  mycroft 			break;
    384  1.25.2.2  mycroft 		case 'w':
    385  1.25.2.2  mycroft 			/*
    386  1.25.2.2  mycroft 			 * write an archive
    387  1.25.2.2  mycroft 			 */
    388  1.25.2.2  mycroft 			flg |= WF;
    389  1.25.2.2  mycroft 			break;
    390  1.25.2.2  mycroft 		case 'x':
    391  1.25.2.2  mycroft 			/*
    392  1.25.2.2  mycroft 			 * specify an archive format on write
    393  1.25.2.2  mycroft 			 */
    394  1.25.2.2  mycroft 			tmp.name = optarg;
    395  1.25.2.2  mycroft 			frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub,
    396  1.25.2.2  mycroft 			    sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt);
    397  1.25.2.2  mycroft 			if (frmt != NULL) {
    398  1.25.2.2  mycroft 				flg |= XF;
    399  1.25.2.2  mycroft 				break;
    400  1.25.2.2  mycroft 			}
    401  1.25.2.2  mycroft 			tty_warn(1, "Unknown -x format: %s", optarg);
    402  1.25.2.2  mycroft 			(void)fputs("pax: Known -x formats are:", stderr);
    403  1.25.2.2  mycroft 			for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i)
    404  1.25.2.2  mycroft 				(void)fprintf(stderr, " %s", fsub[i].name);
    405  1.25.2.2  mycroft 			(void)fputs("\n\n", stderr);
    406  1.25.2.2  mycroft 			pax_usage();
    407  1.25.2.2  mycroft 			break;
    408  1.25.2.2  mycroft 		case 'z':
    409  1.25.2.2  mycroft 			/*
    410  1.25.2.2  mycroft 			 * use gzip.  Non standard option.
    411  1.25.2.2  mycroft 			 */
    412  1.25.2.2  mycroft 			zflag = 1;
    413  1.25.2.2  mycroft 			gzip_program = GZIP_CMD;
    414  1.25.2.2  mycroft 			break;
    415  1.25.2.2  mycroft 		case 'A':
    416  1.25.2.2  mycroft 			Aflag = 1;
    417  1.25.2.2  mycroft 			flg |= CAF;
    418  1.25.2.2  mycroft 			break;
    419  1.25.2.2  mycroft 		case 'B':
    420  1.25.2.2  mycroft 			/*
    421  1.25.2.2  mycroft 			 * non-standard option on number of bytes written on a
    422  1.25.2.2  mycroft 			 * single archive volume.
    423  1.25.2.2  mycroft 			 */
    424  1.25.2.2  mycroft 			if ((wrlimit = str_offt(optarg)) <= 0) {
    425  1.25.2.2  mycroft 				tty_warn(1, "Invalid write limit %s", optarg);
    426  1.25.2.2  mycroft 				pax_usage();
    427  1.25.2.2  mycroft 			}
    428  1.25.2.2  mycroft 			if (wrlimit % BLKMULT) {
    429  1.25.2.2  mycroft 				tty_warn(1,
    430  1.25.2.2  mycroft 				    "Write limit is not a %d byte multiple",
    431  1.25.2.2  mycroft 				    BLKMULT);
    432  1.25.2.2  mycroft 				pax_usage();
    433  1.25.2.2  mycroft 			}
    434  1.25.2.2  mycroft 			flg |= CBF;
    435  1.25.2.2  mycroft 			break;
    436  1.25.2.2  mycroft 		case 'D':
    437  1.25.2.2  mycroft 			/*
    438  1.25.2.2  mycroft 			 * On extraction check file inode change time before the
    439  1.25.2.2  mycroft 			 * modification of the file name. Non standard option.
    440  1.25.2.2  mycroft 			 */
    441  1.25.2.2  mycroft 			Dflag = 1;
    442  1.25.2.2  mycroft 			flg |= CDF;
    443  1.25.2.2  mycroft 			break;
    444  1.25.2.2  mycroft 		case 'E':
    445  1.25.2.2  mycroft 			/*
    446  1.25.2.2  mycroft 			 * non-standard limit on read faults
    447  1.25.2.2  mycroft 			 * 0 indicates stop after first error, values
    448  1.25.2.2  mycroft 			 * indicate a limit, "NONE" try forever
    449  1.25.2.2  mycroft 			 */
    450  1.25.2.2  mycroft 			flg |= CEF;
    451  1.25.2.2  mycroft 			if (strcmp(NONE, optarg) == 0)
    452  1.25.2.2  mycroft 				maxflt = -1;
    453  1.25.2.2  mycroft 			else if ((maxflt = atoi(optarg)) < 0) {
    454  1.25.2.2  mycroft 				tty_warn(1,
    455  1.25.2.2  mycroft 				    "Error count value must be positive");
    456  1.25.2.2  mycroft 				pax_usage();
    457  1.25.2.2  mycroft 			}
    458  1.25.2.2  mycroft 			break;
    459  1.25.2.2  mycroft 		case 'G':
    460  1.25.2.2  mycroft 			/*
    461  1.25.2.2  mycroft 			 * non-standard option for selecting files within an
    462  1.25.2.2  mycroft 			 * archive by group (gid or name)
    463  1.25.2.2  mycroft 			 */
    464  1.25.2.2  mycroft 			if (grp_add(optarg) < 0) {
    465  1.25.2.2  mycroft 				pax_usage();
    466  1.25.2.2  mycroft 				break;
    467  1.25.2.2  mycroft 			}
    468  1.25.2.2  mycroft 			flg |= CGF;
    469  1.25.2.2  mycroft 			break;
    470  1.25.2.2  mycroft 		case 'H':
    471  1.25.2.2  mycroft 			/*
    472  1.25.2.2  mycroft 			 * follow command line symlinks only
    473  1.25.2.2  mycroft 			 */
    474  1.25.2.2  mycroft 			Hflag = 1;
    475  1.25.2.2  mycroft 			flg |= CHF;
    476  1.25.2.2  mycroft 			break;
    477  1.25.2.2  mycroft 		case 'L':
    478  1.25.2.2  mycroft 			/*
    479  1.25.2.2  mycroft 			 * follow symlinks
    480  1.25.2.2  mycroft 			 */
    481  1.25.2.2  mycroft 			Lflag = 1;
    482  1.25.2.2  mycroft 			flg |= CLF;
    483  1.25.2.2  mycroft 			break;
    484  1.25.2.2  mycroft 		case 'P':
    485  1.25.2.2  mycroft 			/*
    486  1.25.2.2  mycroft 			 * do NOT follow symlinks (default)
    487  1.25.2.2  mycroft 			 */
    488  1.25.2.2  mycroft 			Lflag = 0;
    489  1.25.2.2  mycroft 			flg |= CPF;
    490  1.25.2.2  mycroft 			break;
    491  1.25.2.2  mycroft 		case 'T':
    492  1.25.2.2  mycroft 			/*
    493  1.25.2.2  mycroft 			 * non-standard option for selecting files within an
    494  1.25.2.2  mycroft 			 * archive by modification time range (lower,upper)
    495  1.25.2.2  mycroft 			 */
    496  1.25.2.2  mycroft 			if (trng_add(optarg) < 0) {
    497  1.25.2.2  mycroft 				pax_usage();
    498  1.25.2.2  mycroft 				break;
    499  1.25.2.2  mycroft 			}
    500  1.25.2.2  mycroft 			flg |= CTF;
    501  1.25.2.2  mycroft 			break;
    502  1.25.2.2  mycroft 		case 'U':
    503  1.25.2.2  mycroft 			/*
    504  1.25.2.2  mycroft 			 * non-standard option for selecting files within an
    505  1.25.2.2  mycroft 			 * archive by user (uid or name)
    506  1.25.2.2  mycroft 			 */
    507  1.25.2.2  mycroft 			if (usr_add(optarg) < 0) {
    508  1.25.2.2  mycroft 				pax_usage();
    509  1.25.2.2  mycroft 				break;
    510  1.25.2.2  mycroft 			}
    511  1.25.2.2  mycroft 			flg |= CUF;
    512  1.25.2.2  mycroft 			break;
    513  1.25.2.2  mycroft 		case 'X':
    514  1.25.2.2  mycroft 			/*
    515  1.25.2.2  mycroft 			 * do not pass over mount points in the file system
    516  1.25.2.2  mycroft 			 */
    517  1.25.2.2  mycroft 			Xflag = 1;
    518  1.25.2.2  mycroft 			flg |= CXF;
    519  1.25.2.2  mycroft 			break;
    520  1.25.2.2  mycroft 		case 'Y':
    521  1.25.2.2  mycroft 			/*
    522  1.25.2.2  mycroft 			 * On extraction check file inode change time after the
    523  1.25.2.2  mycroft 			 * modification of the file name. Non standard option.
    524  1.25.2.2  mycroft 			 */
    525  1.25.2.2  mycroft 			Yflag = 1;
    526  1.25.2.2  mycroft 			flg |= CYF;
    527  1.25.2.2  mycroft 			break;
    528  1.25.2.2  mycroft 		case 'Z':
    529  1.25.2.2  mycroft 			/*
    530  1.25.2.2  mycroft 			 * On extraction check modification time after the
    531  1.25.2.2  mycroft 			 * modification of the file name. Non standard option.
    532  1.25.2.2  mycroft 			 */
    533  1.25.2.2  mycroft 			Zflag = 1;
    534  1.25.2.2  mycroft 			flg |= CZF;
    535  1.25.2.2  mycroft 			break;
    536  1.25.2.2  mycroft 		case '?':
    537  1.25.2.2  mycroft 		default:
    538  1.25.2.2  mycroft 			pax_usage();
    539  1.25.2.2  mycroft 			break;
    540  1.25.2.2  mycroft 		}
    541  1.25.2.2  mycroft 	}
    542  1.25.2.2  mycroft 
    543  1.25.2.2  mycroft 	/*
    544  1.25.2.2  mycroft 	 * figure out the operation mode of pax read,write,extract,copy,append
    545  1.25.2.2  mycroft 	 * or list. check that we have not been given a bogus set of flags
    546  1.25.2.2  mycroft 	 * for the operation mode.
    547  1.25.2.2  mycroft 	 */
    548  1.25.2.2  mycroft 	if (ISLIST(flg)) {
    549  1.25.2.2  mycroft 		act = LIST;
    550  1.25.2.2  mycroft 		bflg = flg & BDLIST;
    551  1.25.2.2  mycroft 	} else if (ISEXTRACT(flg)) {
    552  1.25.2.2  mycroft 		act = EXTRACT;
    553  1.25.2.2  mycroft 		bflg = flg & BDEXTR;
    554  1.25.2.2  mycroft 	} else if (ISARCHIVE(flg)) {
    555  1.25.2.2  mycroft 		act = ARCHIVE;
    556  1.25.2.2  mycroft 		bflg = flg & BDARCH;
    557  1.25.2.2  mycroft 	} else if (ISAPPND(flg)) {
    558  1.25.2.2  mycroft 		act = APPND;
    559  1.25.2.2  mycroft 		bflg = flg & BDARCH;
    560  1.25.2.2  mycroft 	} else if (ISCOPY(flg)) {
    561  1.25.2.2  mycroft 		act = COPY;
    562  1.25.2.2  mycroft 		bflg = flg & BDCOPY;
    563  1.25.2.2  mycroft 	} else
    564  1.25.2.2  mycroft 		pax_usage();
    565  1.25.2.2  mycroft 	if (bflg) {
    566  1.25.2.2  mycroft 		printflg(flg);
    567  1.25.2.2  mycroft 		pax_usage();
    568  1.25.2.2  mycroft 	}
    569  1.25.2.2  mycroft 
    570  1.25.2.2  mycroft 	/*
    571  1.25.2.2  mycroft 	 * if we are writing (ARCHIVE) we use the default format if the user
    572  1.25.2.2  mycroft 	 * did not specify a format. when we write during an APPEND, we will
    573  1.25.2.2  mycroft 	 * adopt the format of the existing archive if none was supplied.
    574  1.25.2.2  mycroft 	 */
    575  1.25.2.2  mycroft 	if (!(flg & XF) && (act == ARCHIVE))
    576  1.25.2.2  mycroft 		frmt = &(fsub[DEFLT]);
    577  1.25.2.2  mycroft 
    578  1.25.2.2  mycroft 	/*
    579  1.25.2.2  mycroft 	 * process the args as they are interpreted by the operation mode
    580  1.25.2.2  mycroft 	 */
    581  1.25.2.2  mycroft 	switch (act) {
    582  1.25.2.2  mycroft 	case LIST:
    583  1.25.2.2  mycroft 	case EXTRACT:
    584  1.25.2.2  mycroft 		for (; optind < argc; optind++)
    585  1.25.2.2  mycroft 			if (pat_add(argv[optind], 0) < 0)
    586  1.25.2.2  mycroft 				pax_usage();
    587  1.25.2.2  mycroft 		break;
    588  1.25.2.2  mycroft 	case COPY:
    589  1.25.2.2  mycroft 		if (optind >= argc) {
    590  1.25.2.2  mycroft 			tty_warn(0, "Destination directory was not supplied");
    591  1.25.2.2  mycroft 			pax_usage();
    592  1.25.2.2  mycroft 		}
    593  1.25.2.2  mycroft 		--argc;
    594  1.25.2.2  mycroft 		dirptr = argv[argc];
    595  1.25.2.2  mycroft 		/* FALLTHROUGH */
    596  1.25.2.2  mycroft 	case ARCHIVE:
    597  1.25.2.2  mycroft 	case APPND:
    598  1.25.2.2  mycroft 		for (; optind < argc; optind++)
    599  1.25.2.2  mycroft 			if (ftree_add(argv[optind], 0) < 0)
    600  1.25.2.2  mycroft 				pax_usage();
    601  1.25.2.2  mycroft 		/*
    602  1.25.2.2  mycroft 		 * no read errors allowed on updates/append operation!
    603  1.25.2.2  mycroft 		 */
    604  1.25.2.2  mycroft 		maxflt = 0;
    605  1.25.2.2  mycroft 		break;
    606  1.25.2.2  mycroft 	}
    607  1.25.2.2  mycroft }
    608  1.25.2.2  mycroft 
    609  1.25.2.2  mycroft 
    610  1.25.2.2  mycroft /*
    611  1.25.2.2  mycroft  * tar_options()
    612  1.25.2.2  mycroft  *	look at the user specified flags. set globals as required and check if
    613  1.25.2.2  mycroft  *	the user specified a legal set of flags. If not, complain and exit
    614  1.25.2.2  mycroft  */
    615  1.25.2.2  mycroft 
    616  1.25.2.2  mycroft #if __STDC__
    617  1.25.2.2  mycroft static void
    618  1.25.2.2  mycroft tar_options(int argc, char **argv)
    619  1.25.2.2  mycroft #else
    620  1.25.2.2  mycroft static void
    621  1.25.2.2  mycroft tar_options(argc, argv)
    622  1.25.2.2  mycroft 	int argc;
    623  1.25.2.2  mycroft 	char **argv;
    624  1.25.2.2  mycroft #endif
    625  1.25.2.2  mycroft {
    626  1.25.2.2  mycroft 	int c;
    627  1.25.2.2  mycroft 	int fstdin = 0;
    628  1.25.2.2  mycroft 
    629  1.25.2.2  mycroft 	/*
    630  1.25.2.2  mycroft 	 * process option flags
    631  1.25.2.2  mycroft 	 */
    632  1.25.2.2  mycroft 	while ((c = getoldopt(argc, argv, "b:cef:hlmoprutvwxzBC:LPX:Z014578"))
    633  1.25.2.2  mycroft 	    != -1)  {
    634  1.25.2.2  mycroft 		switch(c) {
    635  1.25.2.2  mycroft 		case 'b':
    636  1.25.2.2  mycroft 			/*
    637  1.25.2.2  mycroft 			 * specify blocksize
    638  1.25.2.2  mycroft 			 */
    639  1.25.2.2  mycroft 			if ((wrblksz = (int)str_offt(optarg)) <= 0) {
    640  1.25.2.2  mycroft 				tty_warn(1, "Invalid block size %s", optarg);
    641  1.25.2.2  mycroft 				tar_usage();
    642  1.25.2.2  mycroft 			}
    643  1.25.2.2  mycroft 			break;
    644  1.25.2.2  mycroft 		case 'c':
    645  1.25.2.2  mycroft 			/*
    646  1.25.2.2  mycroft 			 * create an archive
    647  1.25.2.2  mycroft 			 */
    648  1.25.2.2  mycroft 			act = ARCHIVE;
    649  1.25.2.2  mycroft 			break;
    650  1.25.2.2  mycroft 		case 'C':
    651  1.25.2.2  mycroft 			/*
    652  1.25.2.2  mycroft 			 * chdir here before extracting.
    653  1.25.2.2  mycroft 			 * do so lazily, in case it's a list
    654  1.25.2.2  mycroft 			 */
    655  1.25.2.2  mycroft 			firstminusC = optarg;
    656  1.25.2.2  mycroft 			break;
    657  1.25.2.2  mycroft 		case 'e':
    658  1.25.2.2  mycroft 			/*
    659  1.25.2.2  mycroft 			 * stop after first error
    660  1.25.2.2  mycroft 			 */
    661  1.25.2.2  mycroft 			maxflt = 0;
    662  1.25.2.2  mycroft 			break;
    663  1.25.2.2  mycroft 		case 'f':
    664  1.25.2.2  mycroft 			/*
    665  1.25.2.2  mycroft 			 * filename where the archive is stored
    666  1.25.2.2  mycroft 			 */
    667  1.25.2.2  mycroft 			if ((optarg[0] == '-') && (optarg[1]== '\0')) {
    668  1.25.2.2  mycroft 				/*
    669  1.25.2.2  mycroft 				 * treat a - as stdin
    670  1.25.2.2  mycroft 				 */
    671  1.25.2.2  mycroft 				fstdin = 1;
    672  1.25.2.2  mycroft 				arcname = (char *)0;
    673  1.25.2.2  mycroft 				break;
    674  1.25.2.2  mycroft 			}
    675  1.25.2.2  mycroft 			fstdin = 0;
    676  1.25.2.2  mycroft 			arcname = optarg;
    677  1.25.2.2  mycroft 			break;
    678  1.25.2.2  mycroft 		case 'h':
    679  1.25.2.2  mycroft 			/*
    680  1.25.2.2  mycroft 			 * follow command line symlinks only
    681  1.25.2.2  mycroft 			 */
    682  1.25.2.2  mycroft 			Hflag = 1;
    683  1.25.2.2  mycroft 			break;
    684  1.25.2.2  mycroft 		case 'l':
    685  1.25.2.2  mycroft 			/*
    686  1.25.2.2  mycroft 			 * do not pass over mount points in the file system
    687  1.25.2.2  mycroft 			 */
    688  1.25.2.2  mycroft 			Xflag = 1;
    689  1.25.2.2  mycroft 			break;
    690  1.25.2.2  mycroft 		case 'm':
    691  1.25.2.2  mycroft 			/*
    692  1.25.2.2  mycroft 			 * do not preserve modification time
    693  1.25.2.2  mycroft 			 */
    694  1.25.2.2  mycroft 			pmtime = 0;
    695  1.25.2.2  mycroft 			break;
    696  1.25.2.2  mycroft 		case 'o':
    697  1.25.2.2  mycroft 			/*
    698  1.25.2.2  mycroft 			 * This option does several things based on whether
    699  1.25.2.2  mycroft 			 * this is a create or extract operation.
    700  1.25.2.2  mycroft 			 */
    701  1.25.2.2  mycroft 			if (act == ARCHIVE) {
    702  1.25.2.2  mycroft 				/* 4.2BSD: don't add directory entries. */
    703  1.25.2.2  mycroft 				if (opt_add("write_opt=nodir") < 0)
    704  1.25.2.2  mycroft 					tar_usage();
    705  1.25.2.2  mycroft 
    706  1.25.2.2  mycroft 				/* GNU tar: write V7 format archives. */
    707  1.25.2.2  mycroft 				frmt = &(fsub[F_TAR]);
    708  1.25.2.2  mycroft 			} else {
    709  1.25.2.2  mycroft 				/* SUS: don't preserve owner/group. */
    710  1.25.2.2  mycroft 				pids = 0;
    711  1.25.2.2  mycroft 				nopids = 1;
    712  1.25.2.2  mycroft 			}
    713  1.25.2.2  mycroft 			break;
    714  1.25.2.2  mycroft 		case 'p':
    715  1.25.2.2  mycroft 			/*
    716  1.25.2.2  mycroft 			 * preserve user id, group id, file
    717  1.25.2.2  mycroft 			 * mode, access/modification times
    718  1.25.2.2  mycroft 			 */
    719  1.25.2.2  mycroft 			if (!nopids)
    720  1.25.2.2  mycroft 				pids = 1;
    721  1.25.2.2  mycroft 			pmode = 1;
    722  1.25.2.2  mycroft 			patime = 1;
    723  1.25.2.2  mycroft 			pmtime = 1;
    724  1.25.2.2  mycroft 			break;
    725  1.25.2.2  mycroft 		case 'r':
    726  1.25.2.2  mycroft 		case 'u':
    727  1.25.2.2  mycroft 			/*
    728  1.25.2.2  mycroft 			 * append to the archive
    729  1.25.2.2  mycroft 			 */
    730  1.25.2.2  mycroft 			act = APPND;
    731  1.25.2.2  mycroft 			break;
    732  1.25.2.2  mycroft 		case 't':
    733  1.25.2.2  mycroft 			/*
    734  1.25.2.2  mycroft 			 * list contents of the tape
    735  1.25.2.2  mycroft 			 */
    736  1.25.2.2  mycroft 			act = LIST;
    737  1.25.2.2  mycroft 			break;
    738  1.25.2.2  mycroft 		case 'v':
    739  1.25.2.2  mycroft 			/*
    740  1.25.2.2  mycroft 			 * verbose operation mode
    741  1.25.2.2  mycroft 			 */
    742  1.25.2.2  mycroft 			vflag = 1;
    743  1.25.2.2  mycroft 			break;
    744  1.25.2.2  mycroft 		case 'w':
    745  1.25.2.2  mycroft 			/*
    746  1.25.2.2  mycroft 			 * interactive file rename
    747  1.25.2.2  mycroft 			 */
    748  1.25.2.2  mycroft 			iflag = 1;
    749  1.25.2.2  mycroft 			break;
    750  1.25.2.2  mycroft 		case 'x':
    751  1.25.2.2  mycroft 			/*
    752  1.25.2.2  mycroft 			 * write an archive
    753  1.25.2.2  mycroft 			 */
    754  1.25.2.2  mycroft 			act = EXTRACT;
    755  1.25.2.2  mycroft 			break;
    756  1.25.2.2  mycroft 		case 'z':
    757  1.25.2.2  mycroft 			/*
    758  1.25.2.2  mycroft 			 * use gzip.  Non standard option.
    759  1.25.2.2  mycroft 			 */
    760  1.25.2.2  mycroft 			zflag = 1;
    761  1.25.2.2  mycroft 			gzip_program = GZIP_CMD;
    762  1.25.2.2  mycroft 			break;
    763  1.25.2.2  mycroft 		case 'B':
    764  1.25.2.2  mycroft 			/*
    765  1.25.2.2  mycroft 			 * Nothing to do here, this is pax default
    766  1.25.2.2  mycroft 			 */
    767  1.25.2.2  mycroft 			break;
    768  1.25.2.2  mycroft 		case 'L':
    769  1.25.2.2  mycroft 			/*
    770  1.25.2.2  mycroft 			 * follow symlinks
    771  1.25.2.2  mycroft 			 */
    772  1.25.2.2  mycroft 			Lflag = 1;
    773  1.25.2.2  mycroft 			break;
    774  1.25.2.2  mycroft 		case 'P':
    775  1.25.2.2  mycroft 			Aflag = 1;
    776  1.25.2.2  mycroft 			break;
    777  1.25.2.2  mycroft 		case 'X':
    778  1.25.2.2  mycroft 			/*
    779  1.25.2.2  mycroft 			 * GNU tar compat: exclude the files listed in optarg
    780  1.25.2.2  mycroft 			 */
    781  1.25.2.2  mycroft 			if (tar_gnutar_X_compat(optarg) != 0)
    782  1.25.2.2  mycroft 				tar_usage();
    783  1.25.2.2  mycroft 			break;
    784  1.25.2.2  mycroft 		case 'Z':
    785  1.25.2.2  mycroft 			/*
    786  1.25.2.2  mycroft 			 * use compress.
    787  1.25.2.2  mycroft 			 */
    788  1.25.2.2  mycroft 			zflag = 1;
    789  1.25.2.2  mycroft 			gzip_program = COMPRESS_CMD;
    790  1.25.2.2  mycroft 			break;
    791  1.25.2.2  mycroft 		case '0':
    792  1.25.2.2  mycroft 			arcname = DEV_0;
    793  1.25.2.2  mycroft 			break;
    794  1.25.2.2  mycroft 		case '1':
    795  1.25.2.2  mycroft 			arcname = DEV_1;
    796  1.25.2.2  mycroft 			break;
    797  1.25.2.2  mycroft 		case '4':
    798  1.25.2.2  mycroft 			arcname = DEV_4;
    799  1.25.2.2  mycroft 			break;
    800  1.25.2.2  mycroft 		case '5':
    801  1.25.2.2  mycroft 			arcname = DEV_5;
    802  1.25.2.2  mycroft 			break;
    803  1.25.2.2  mycroft 		case '7':
    804  1.25.2.2  mycroft 			arcname = DEV_7;
    805  1.25.2.2  mycroft 			break;
    806  1.25.2.2  mycroft 		case '8':
    807  1.25.2.2  mycroft 			arcname = DEV_8;
    808  1.25.2.2  mycroft 			break;
    809  1.25.2.2  mycroft 		default:
    810  1.25.2.2  mycroft 			tar_usage();
    811  1.25.2.2  mycroft 			break;
    812  1.25.2.2  mycroft 		}
    813  1.25.2.2  mycroft 	}
    814  1.25.2.2  mycroft 	argc -= optind;
    815  1.25.2.2  mycroft 	argv += optind;
    816  1.25.2.2  mycroft 
    817  1.25.2.2  mycroft 	if (firstminusC && (opt_chdir(firstminusC) < 0))
    818  1.25.2.2  mycroft 		tty_warn(1, "can't remember -C directory");
    819  1.25.2.2  mycroft 
    820  1.25.2.2  mycroft 	/*
    821  1.25.2.2  mycroft 	 * if we are writing (ARCHIVE) specify tar, otherwise run like pax
    822  1.25.2.2  mycroft 	 */
    823  1.25.2.2  mycroft 	if (act == ARCHIVE && frmt == NULL)
    824  1.25.2.2  mycroft 		frmt = &(fsub[F_USTAR]);
    825  1.25.2.2  mycroft 
    826  1.25.2.2  mycroft 	/*
    827  1.25.2.2  mycroft 	 * process the args as they are interpreted by the operation mode
    828  1.25.2.2  mycroft 	 */
    829  1.25.2.2  mycroft 	switch (act) {
    830  1.25.2.2  mycroft 	case LIST:
    831  1.25.2.2  mycroft 	default:
    832  1.25.2.2  mycroft 		while (*argv != (char *)NULL)
    833  1.25.2.2  mycroft 			if (pat_add(*argv++, 0) < 0)
    834  1.25.2.2  mycroft 				tar_usage();
    835  1.25.2.2  mycroft 		break;
    836  1.25.2.2  mycroft 	case EXTRACT:
    837  1.25.2.2  mycroft 		checkpositionalminusC(&argv, pat_add);
    838  1.25.2.2  mycroft 		break;
    839  1.25.2.2  mycroft 	case ARCHIVE:
    840  1.25.2.2  mycroft 	case APPND:
    841  1.25.2.2  mycroft 		checkpositionalminusC(&argv, ftree_add);
    842  1.25.2.2  mycroft 		/*
    843  1.25.2.2  mycroft 		 * no read errors allowed on updates/append operation!
    844  1.25.2.2  mycroft 		 */
    845  1.25.2.2  mycroft 		maxflt = 0;
    846  1.25.2.2  mycroft 		break;
    847  1.25.2.2  mycroft 	}
    848  1.25.2.2  mycroft 	if (!fstdin && ((arcname == (char *)NULL) || (*arcname == '\0'))) {
    849  1.25.2.2  mycroft 		arcname = getenv("TAPE");
    850  1.25.2.2  mycroft 		if ((arcname == (char *)NULL) || (*arcname == '\0'))
    851  1.25.2.2  mycroft 			arcname = DEV_8;
    852  1.25.2.2  mycroft 	}
    853  1.25.2.2  mycroft }
    854  1.25.2.2  mycroft 
    855  1.25.2.2  mycroft /*
    856  1.25.2.2  mycroft  * cpio_options()
    857  1.25.2.2  mycroft  *	look at the user specified flags. set globals as required and check if
    858  1.25.2.2  mycroft  *	the user specified a legal set of flags. If not, complain and exit
    859  1.25.2.2  mycroft  */
    860  1.25.2.2  mycroft 
    861  1.25.2.2  mycroft #if __STDC__
    862  1.25.2.2  mycroft static void
    863  1.25.2.2  mycroft cpio_options(int argc, char **argv)
    864  1.25.2.2  mycroft #else
    865  1.25.2.2  mycroft static void
    866  1.25.2.2  mycroft cpio_options(argc, argv)
    867  1.25.2.2  mycroft 	int argc;
    868  1.25.2.2  mycroft 	char **argv;
    869  1.25.2.2  mycroft #endif
    870  1.25.2.2  mycroft {
    871  1.25.2.2  mycroft         FSUB tmp;
    872  1.25.2.2  mycroft 	unsigned int flg = 0;
    873  1.25.2.2  mycroft 	unsigned int bflg = 0;
    874  1.25.2.2  mycroft 	int c, i;
    875  1.25.2.2  mycroft 
    876  1.25.2.2  mycroft 	cpio_mode = uflag = 1;
    877  1.25.2.2  mycroft 	/*
    878  1.25.2.2  mycroft 	 * process option flags
    879  1.25.2.2  mycroft 	 */
    880  1.25.2.2  mycroft 	while ((c = getoldopt(argc, argv, "ABC:E:H:I:LM:O:R:SVabcdfiklmoprstuv"))
    881  1.25.2.2  mycroft 	    != -1)  {
    882  1.25.2.2  mycroft 		switch(c) {
    883  1.25.2.2  mycroft 		case 'A':
    884  1.25.2.2  mycroft 			/*
    885  1.25.2.2  mycroft 			 * append to an archive
    886  1.25.2.2  mycroft 			 */
    887  1.25.2.2  mycroft 			act = APPND;
    888  1.25.2.2  mycroft 			flg |= AF;
    889  1.25.2.2  mycroft 			break;
    890  1.25.2.2  mycroft 		case 'B':
    891  1.25.2.2  mycroft 			/*
    892  1.25.2.2  mycroft 			 * set blocksize to 5120
    893  1.25.2.2  mycroft 			 */
    894  1.25.2.2  mycroft 			blksz = 5120;
    895  1.25.2.2  mycroft 			break;
    896  1.25.2.2  mycroft 		case 'C':
    897  1.25.2.2  mycroft 			/*
    898  1.25.2.2  mycroft 			 * specify blocksize
    899  1.25.2.2  mycroft 			 */
    900  1.25.2.2  mycroft 			if ((blksz = (int)str_offt(optarg)) <= 0) {
    901  1.25.2.2  mycroft 				tty_warn(1, "Invalid block size %s", optarg);
    902  1.25.2.2  mycroft 				tar_usage();
    903  1.25.2.2  mycroft 			}
    904  1.25.2.2  mycroft 			break;
    905  1.25.2.2  mycroft #ifdef notyet
    906  1.25.2.2  mycroft 		case 'E':
    907  1.25.2.2  mycroft 			arg = optarg;
    908  1.25.2.2  mycroft 			break;
    909  1.25.2.2  mycroft #endif
    910  1.25.2.2  mycroft 		case 'H':
    911  1.25.2.2  mycroft 			/*
    912  1.25.2.2  mycroft 			 * specify an archive format on write
    913  1.25.2.2  mycroft 			 */
    914  1.25.2.2  mycroft 			tmp.name = optarg;
    915  1.25.2.2  mycroft 			frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub,
    916  1.25.2.2  mycroft 			    sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt);
    917  1.25.2.2  mycroft 			if (frmt != NULL) {
    918  1.25.2.2  mycroft 				flg |= XF;
    919  1.25.2.2  mycroft 				break;
    920  1.25.2.2  mycroft 			}
    921  1.25.2.2  mycroft 			tty_warn(1, "Unknown -H format: %s", optarg);
    922  1.25.2.2  mycroft 			(void)fputs("cpio: Known -H formats are:", stderr);
    923  1.25.2.2  mycroft 			for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i)
    924  1.25.2.2  mycroft 				(void)fprintf(stderr, " %s", fsub[i].name);
    925  1.25.2.2  mycroft 			(void)fputs("\n\n", stderr);
    926  1.25.2.2  mycroft 			tar_usage();
    927  1.25.2.2  mycroft 			break;
    928  1.25.2.2  mycroft 		case 'I':
    929  1.25.2.2  mycroft 		case 'O':
    930  1.25.2.2  mycroft 			/*
    931  1.25.2.2  mycroft 			 * filename where the archive is stored
    932  1.25.2.2  mycroft 			 */
    933  1.25.2.2  mycroft 			if ((optarg[0] == '-') && (optarg[1]== '\0')) {
    934  1.25.2.2  mycroft 				/*
    935  1.25.2.2  mycroft 				 * treat a - as stdin
    936  1.25.2.2  mycroft 				 */
    937  1.25.2.2  mycroft 				arcname = (char *)0;
    938  1.25.2.2  mycroft 				break;
    939  1.25.2.2  mycroft 			}
    940  1.25.2.2  mycroft 			arcname = optarg;
    941  1.25.2.2  mycroft 			break;
    942  1.25.2.2  mycroft 		case 'L':
    943  1.25.2.2  mycroft 			/*
    944  1.25.2.2  mycroft 			 * follow symlinks
    945  1.25.2.2  mycroft 			 */
    946  1.25.2.2  mycroft 			Lflag = 1;
    947  1.25.2.2  mycroft 			flg |= CLF;
    948  1.25.2.2  mycroft 			break;
    949  1.25.2.2  mycroft #ifdef notyet
    950  1.25.2.2  mycroft 		case 'M':
    951  1.25.2.2  mycroft 			arg = optarg;
    952  1.25.2.2  mycroft 			break;
    953  1.25.2.2  mycroft 		case 'R':
    954  1.25.2.2  mycroft 			arg = optarg;
    955  1.25.2.2  mycroft 			break;
    956  1.25.2.2  mycroft #endif
    957  1.25.2.2  mycroft 		case 'S':
    958  1.25.2.2  mycroft 			cpio_swp_head = 1;
    959  1.25.2.2  mycroft 			break;
    960  1.25.2.2  mycroft #ifdef notyet
    961  1.25.2.2  mycroft 		case 'V':
    962  1.25.2.2  mycroft 			break;
    963  1.25.2.2  mycroft #endif
    964  1.25.2.2  mycroft 		case 'a':
    965  1.25.2.2  mycroft 			/*
    966  1.25.2.2  mycroft 			 * preserve access time on filesystem nodes we read
    967  1.25.2.2  mycroft 			 */
    968  1.25.2.2  mycroft 			tflag = 1;
    969  1.25.2.2  mycroft 			flg |= TF;
    970  1.25.2.2  mycroft 			break;
    971  1.25.2.2  mycroft #ifdef notyet
    972  1.25.2.2  mycroft 		case 'b':
    973  1.25.2.2  mycroft 			break;
    974  1.25.2.2  mycroft #endif
    975  1.25.2.2  mycroft 		case 'c':
    976  1.25.2.2  mycroft 			frmt = &fsub[F_SV4CPIO];
    977  1.25.2.2  mycroft 			break;
    978  1.25.2.2  mycroft 		case 'd':
    979  1.25.2.2  mycroft 			/*
    980  1.25.2.2  mycroft 			 * pax does this by default ..
    981  1.25.2.2  mycroft 			 */
    982  1.25.2.2  mycroft 			flg |= RF;
    983  1.25.2.2  mycroft 			break;
    984  1.25.2.2  mycroft 		case 'f':
    985  1.25.2.2  mycroft 			/*
    986  1.25.2.2  mycroft 			 * inverse match on patterns
    987  1.25.2.2  mycroft 			 */
    988  1.25.2.2  mycroft 			cflag = 1;
    989  1.25.2.2  mycroft 			flg |= CF;
    990  1.25.2.2  mycroft 			break;
    991  1.25.2.2  mycroft 		case 'i':
    992  1.25.2.2  mycroft 			/*
    993  1.25.2.2  mycroft 			 * read the archive
    994  1.25.2.2  mycroft 			 */
    995  1.25.2.2  mycroft 			flg |= RF;
    996  1.25.2.2  mycroft 			break;
    997  1.25.2.2  mycroft #ifdef notyet
    998  1.25.2.2  mycroft 		case 'k':
    999  1.25.2.2  mycroft 			break;
   1000  1.25.2.2  mycroft #endif
   1001  1.25.2.2  mycroft 		case 'l':
   1002  1.25.2.2  mycroft 			/*
   1003  1.25.2.2  mycroft 			 * try to link src to dest with copy (-rw)
   1004  1.25.2.2  mycroft 			 */
   1005  1.25.2.2  mycroft 			lflag = 1;
   1006  1.25.2.2  mycroft 			flg |= LF;
   1007  1.25.2.2  mycroft 			break;
   1008  1.25.2.2  mycroft 		case 'm':
   1009  1.25.2.2  mycroft 			/*
   1010  1.25.2.2  mycroft 			 * preserve mtime
   1011  1.25.2.2  mycroft 			 */
   1012  1.25.2.2  mycroft 			flg |= PF;
   1013  1.25.2.2  mycroft 			pmtime = 1;
   1014  1.25.2.2  mycroft 			break;
   1015  1.25.2.2  mycroft 		case 'o':
   1016  1.25.2.2  mycroft 			/*
   1017  1.25.2.2  mycroft 			 * write an archive
   1018  1.25.2.2  mycroft 			 */
   1019  1.25.2.2  mycroft 			flg |= WF;
   1020  1.25.2.2  mycroft 			break;
   1021  1.25.2.2  mycroft 		case 'p':
   1022  1.25.2.2  mycroft 			/*
   1023  1.25.2.2  mycroft 			 * cpio -p is like pax -rw
   1024  1.25.2.2  mycroft 			 */
   1025  1.25.2.2  mycroft 			flg |= RF | WF;
   1026  1.25.2.2  mycroft 			break;
   1027  1.25.2.2  mycroft 		case 'r':
   1028  1.25.2.2  mycroft 			/*
   1029  1.25.2.2  mycroft 			 * interactive file rename
   1030  1.25.2.2  mycroft 			 */
   1031  1.25.2.2  mycroft 			iflag = 1;
   1032  1.25.2.2  mycroft 			flg |= IF;
   1033  1.25.2.2  mycroft 			break;
   1034  1.25.2.2  mycroft #ifdef notyet
   1035  1.25.2.2  mycroft 		case 's':
   1036  1.25.2.2  mycroft 			break;
   1037  1.25.2.2  mycroft #endif
   1038  1.25.2.2  mycroft 		case 't':
   1039  1.25.2.2  mycroft 			act = LIST;
   1040  1.25.2.2  mycroft 			break;
   1041  1.25.2.2  mycroft 		case 'u':
   1042  1.25.2.2  mycroft 			/*
   1043  1.25.2.2  mycroft 			 * don't ignore those older files
   1044  1.25.2.2  mycroft 			 */
   1045  1.25.2.2  mycroft 			uflag = 0;
   1046  1.25.2.2  mycroft 			flg |= UF;
   1047  1.25.2.2  mycroft 			break;
   1048  1.25.2.2  mycroft 		case 'v':
   1049  1.25.2.2  mycroft 			/*
   1050  1.25.2.2  mycroft 			 * verbose operation mode
   1051  1.25.2.2  mycroft 			 */
   1052  1.25.2.2  mycroft 			vflag = 1;
   1053  1.25.2.2  mycroft 			flg |= VF;
   1054  1.25.2.2  mycroft 			break;
   1055  1.25.2.2  mycroft 		default:
   1056  1.25.2.2  mycroft 			cpio_usage();
   1057  1.25.2.2  mycroft 			break;
   1058  1.25.2.2  mycroft 		}
   1059  1.25.2.2  mycroft 	}
   1060  1.25.2.2  mycroft 
   1061  1.25.2.2  mycroft 	/*
   1062  1.25.2.2  mycroft 	 * figure out the operation mode of cpio. check that we have not been
   1063  1.25.2.2  mycroft 	 * given a bogus set of flags for the operation mode.
   1064  1.25.2.2  mycroft 	 */
   1065  1.25.2.2  mycroft 	if (ISLIST(flg)) {
   1066  1.25.2.2  mycroft 		act = LIST;
   1067  1.25.2.2  mycroft 		bflg = flg & BDLIST;
   1068  1.25.2.2  mycroft 	} else if (ISEXTRACT(flg)) {
   1069  1.25.2.2  mycroft 		act = EXTRACT;
   1070  1.25.2.2  mycroft 		bflg = flg & BDEXTR;
   1071  1.25.2.2  mycroft 	} else if (ISARCHIVE(flg)) {
   1072  1.25.2.2  mycroft 		act = ARCHIVE;
   1073  1.25.2.2  mycroft 		bflg = flg & BDARCH;
   1074  1.25.2.2  mycroft 	} else if (ISAPPND(flg)) {
   1075  1.25.2.2  mycroft 		act = APPND;
   1076  1.25.2.2  mycroft 		bflg = flg & BDARCH;
   1077  1.25.2.2  mycroft 	} else if (ISCOPY(flg)) {
   1078  1.25.2.2  mycroft 		act = COPY;
   1079  1.25.2.2  mycroft 		bflg = flg & BDCOPY;
   1080  1.25.2.2  mycroft 	} else
   1081  1.25.2.2  mycroft 		cpio_usage();
   1082  1.25.2.2  mycroft 	if (bflg) {
   1083  1.25.2.2  mycroft 		cpio_usage();
   1084  1.25.2.2  mycroft 	}
   1085  1.25.2.2  mycroft 
   1086  1.25.2.2  mycroft 	/*
   1087  1.25.2.2  mycroft 	 * if we are writing (ARCHIVE) we use the default format if the user
   1088  1.25.2.2  mycroft 	 * did not specify a format. when we write during an APPEND, we will
   1089  1.25.2.2  mycroft 	 * adopt the format of the existing archive if none was supplied.
   1090  1.25.2.2  mycroft 	 */
   1091  1.25.2.2  mycroft 	if (!(flg & XF) && (act == ARCHIVE))
   1092  1.25.2.2  mycroft 		frmt = &(fsub[F_BCPIO]);
   1093  1.25.2.2  mycroft 
   1094  1.25.2.2  mycroft 	/*
   1095  1.25.2.2  mycroft 	 * process the args as they are interpreted by the operation mode
   1096  1.25.2.2  mycroft 	 */
   1097  1.25.2.2  mycroft 	switch (act) {
   1098  1.25.2.2  mycroft 	case LIST:
   1099  1.25.2.2  mycroft 	case EXTRACT:
   1100  1.25.2.2  mycroft 		for (; optind < argc; optind++)
   1101  1.25.2.2  mycroft 			if (pat_add(argv[optind], 0) < 0)
   1102  1.25.2.2  mycroft 				cpio_usage();
   1103  1.25.2.2  mycroft 		break;
   1104  1.25.2.2  mycroft 	case COPY:
   1105  1.25.2.2  mycroft 		if (optind >= argc) {
   1106  1.25.2.2  mycroft 			tty_warn(0, "Destination directory was not supplied");
   1107  1.25.2.2  mycroft 			cpio_usage();
   1108  1.25.2.2  mycroft 		}
   1109  1.25.2.2  mycroft 		--argc;
   1110  1.25.2.2  mycroft 		dirptr = argv[argc];
   1111  1.25.2.2  mycroft 		/* FALLTHROUGH */
   1112  1.25.2.2  mycroft 	case ARCHIVE:
   1113  1.25.2.2  mycroft 	case APPND:
   1114  1.25.2.2  mycroft 		for (; optind < argc; optind++)
   1115  1.25.2.2  mycroft 			if (ftree_add(argv[optind], 0) < 0)
   1116  1.25.2.2  mycroft 				cpio_usage();
   1117  1.25.2.2  mycroft 		/*
   1118  1.25.2.2  mycroft 		 * no read errors allowed on updates/append operation!
   1119  1.25.2.2  mycroft 		 */
   1120  1.25.2.2  mycroft 		maxflt = 0;
   1121  1.25.2.2  mycroft 		break;
   1122  1.25.2.2  mycroft 	}
   1123  1.25.2.2  mycroft }
   1124  1.25.2.2  mycroft 
   1125  1.25.2.2  mycroft /*
   1126  1.25.2.2  mycroft  * printflg()
   1127  1.25.2.2  mycroft  *	print out those invalid flag sets found to the user
   1128  1.25.2.2  mycroft  */
   1129  1.25.2.2  mycroft 
   1130  1.25.2.2  mycroft #if __STDC__
   1131  1.25.2.2  mycroft static void
   1132  1.25.2.2  mycroft printflg(unsigned int flg)
   1133  1.25.2.2  mycroft #else
   1134  1.25.2.2  mycroft static void
   1135  1.25.2.2  mycroft printflg(flg)
   1136  1.25.2.2  mycroft 	unsigned int flg;
   1137  1.25.2.2  mycroft #endif
   1138  1.25.2.2  mycroft {
   1139  1.25.2.2  mycroft 	int nxt;
   1140  1.25.2.2  mycroft 	int pos = 0;
   1141  1.25.2.2  mycroft 
   1142  1.25.2.2  mycroft 	(void)fprintf(stderr,"%s: Invalid combination of options:", argv0);
   1143  1.25.2.2  mycroft 	while ((nxt = ffs(flg)) != 0) {
   1144  1.25.2.2  mycroft 		flg = flg >> nxt;
   1145  1.25.2.2  mycroft 		pos += nxt;
   1146  1.25.2.2  mycroft 		(void)fprintf(stderr, " -%c", flgch[pos-1]);
   1147  1.25.2.2  mycroft 	}
   1148  1.25.2.2  mycroft 	(void)putc('\n', stderr);
   1149  1.25.2.2  mycroft }
   1150  1.25.2.2  mycroft 
   1151  1.25.2.2  mycroft /*
   1152  1.25.2.2  mycroft  * c_frmt()
   1153  1.25.2.2  mycroft  *	comparison routine used by bsearch to find the format specified
   1154  1.25.2.2  mycroft  *	by the user
   1155  1.25.2.2  mycroft  */
   1156  1.25.2.2  mycroft 
   1157  1.25.2.2  mycroft #if __STDC__
   1158  1.25.2.2  mycroft static int
   1159  1.25.2.2  mycroft c_frmt(const void *a, const void *b)
   1160  1.25.2.2  mycroft #else
   1161  1.25.2.2  mycroft static int
   1162  1.25.2.2  mycroft c_frmt(a, b)
   1163  1.25.2.2  mycroft         void *a;
   1164  1.25.2.2  mycroft         void *b;
   1165  1.25.2.2  mycroft #endif
   1166  1.25.2.2  mycroft {
   1167  1.25.2.2  mycroft         return(strcmp(((FSUB *)a)->name, ((FSUB *)b)->name));
   1168  1.25.2.2  mycroft }
   1169  1.25.2.2  mycroft 
   1170  1.25.2.2  mycroft /*
   1171  1.25.2.2  mycroft  * opt_next()
   1172  1.25.2.2  mycroft  *	called by format specific options routines to get each format specific
   1173  1.25.2.2  mycroft  *	flag and value specified with -o
   1174  1.25.2.2  mycroft  * Return:
   1175  1.25.2.2  mycroft  *	pointer to next OPLIST entry or NULL (end of list).
   1176  1.25.2.2  mycroft  */
   1177  1.25.2.2  mycroft 
   1178  1.25.2.2  mycroft #if __STDC__
   1179  1.25.2.2  mycroft OPLIST *
   1180  1.25.2.2  mycroft opt_next(void)
   1181  1.25.2.2  mycroft #else
   1182  1.25.2.2  mycroft OPLIST *
   1183  1.25.2.2  mycroft opt_next()
   1184  1.25.2.2  mycroft #endif
   1185  1.25.2.2  mycroft {
   1186  1.25.2.2  mycroft 	OPLIST *opt;
   1187  1.25.2.2  mycroft 
   1188  1.25.2.2  mycroft 	if ((opt = ophead) != NULL)
   1189  1.25.2.2  mycroft 		ophead = ophead->fow;
   1190  1.25.2.2  mycroft 	return(opt);
   1191  1.25.2.2  mycroft }
   1192  1.25.2.2  mycroft 
   1193  1.25.2.2  mycroft /*
   1194  1.25.2.2  mycroft  * bad_opt()
   1195  1.25.2.2  mycroft  *	generic routine used to complain about a format specific options
   1196  1.25.2.2  mycroft  *	when the format does not support options.
   1197  1.25.2.2  mycroft  */
   1198  1.25.2.2  mycroft 
   1199  1.25.2.2  mycroft #if __STDC__
   1200  1.25.2.2  mycroft int
   1201  1.25.2.2  mycroft bad_opt(void)
   1202  1.25.2.2  mycroft #else
   1203  1.25.2.2  mycroft int
   1204  1.25.2.2  mycroft bad_opt()
   1205  1.25.2.2  mycroft #endif
   1206  1.25.2.2  mycroft {
   1207  1.25.2.2  mycroft 	OPLIST *opt;
   1208  1.25.2.2  mycroft 
   1209  1.25.2.2  mycroft 	if (ophead == NULL)
   1210  1.25.2.2  mycroft 		return(0);
   1211  1.25.2.2  mycroft 	/*
   1212  1.25.2.2  mycroft 	 * print all we were given
   1213  1.25.2.2  mycroft 	 */
   1214  1.25.2.2  mycroft 	tty_warn(1,"These format options are not supported");
   1215  1.25.2.2  mycroft 	while ((opt = opt_next()) != NULL)
   1216  1.25.2.2  mycroft 		(void)fprintf(stderr, "\t%s = %s\n", opt->name, opt->value);
   1217  1.25.2.2  mycroft 	pax_usage();
   1218  1.25.2.2  mycroft 	return(0);
   1219  1.25.2.2  mycroft }
   1220  1.25.2.2  mycroft 
   1221  1.25.2.2  mycroft /*
   1222  1.25.2.2  mycroft  * opt_add()
   1223  1.25.2.2  mycroft  *	breaks the value supplied to -o into a option name and value. options
   1224  1.25.2.2  mycroft  *	are given to -o in the form -o name-value,name=value
   1225  1.25.2.2  mycroft  *	mulltiple -o may be specified.
   1226  1.25.2.2  mycroft  * Return:
   1227  1.25.2.2  mycroft  *	0 if format in name=value format, -1 if -o is passed junk
   1228  1.25.2.2  mycroft  */
   1229  1.25.2.2  mycroft 
   1230  1.25.2.2  mycroft #if __STDC__
   1231  1.25.2.2  mycroft int
   1232  1.25.2.2  mycroft opt_add(const char *str)
   1233  1.25.2.2  mycroft #else
   1234  1.25.2.2  mycroft int
   1235  1.25.2.2  mycroft opt_add(str)
   1236  1.25.2.2  mycroft 	const char *str;
   1237  1.25.2.2  mycroft #endif
   1238  1.25.2.2  mycroft {
   1239  1.25.2.2  mycroft 	OPLIST *opt;
   1240  1.25.2.2  mycroft 	char *frpt;
   1241  1.25.2.2  mycroft 	char *pt;
   1242  1.25.2.2  mycroft 	char *endpt;
   1243  1.25.2.2  mycroft 
   1244  1.25.2.2  mycroft 	if ((str == NULL) || (*str == '\0')) {
   1245  1.25.2.2  mycroft 		tty_warn(0, "Invalid option name");
   1246  1.25.2.2  mycroft 		return(-1);
   1247  1.25.2.2  mycroft 	}
   1248  1.25.2.2  mycroft 	frpt = endpt = strdup(str);
   1249  1.25.2.2  mycroft 
   1250  1.25.2.2  mycroft 	/*
   1251  1.25.2.2  mycroft 	 * break into name and values pieces and stuff each one into a
   1252  1.25.2.2  mycroft 	 * OPLIST structure. When we know the format, the format specific
   1253  1.25.2.2  mycroft 	 * option function will go through this list
   1254  1.25.2.2  mycroft 	 */
   1255  1.25.2.2  mycroft 	while ((frpt != NULL) && (*frpt != '\0')) {
   1256  1.25.2.2  mycroft 		if ((endpt = strchr(frpt, ',')) != NULL)
   1257  1.25.2.2  mycroft 			*endpt = '\0';
   1258  1.25.2.2  mycroft 		if ((pt = strchr(frpt, '=')) == NULL) {
   1259  1.25.2.2  mycroft 			tty_warn(0, "Invalid options format");
   1260  1.25.2.2  mycroft 			return(-1);
   1261  1.25.2.2  mycroft 		}
   1262  1.25.2.2  mycroft 		if ((opt = (OPLIST *)malloc(sizeof(OPLIST))) == NULL) {
   1263  1.25.2.2  mycroft 			tty_warn(0, "Unable to allocate space for option list");
   1264  1.25.2.2  mycroft 			return(-1);
   1265  1.25.2.2  mycroft 		}
   1266  1.25.2.2  mycroft 		*pt++ = '\0';
   1267  1.25.2.2  mycroft 		opt->name = frpt;
   1268  1.25.2.2  mycroft 		opt->value = pt;
   1269  1.25.2.2  mycroft 		opt->fow = NULL;
   1270  1.25.2.2  mycroft 		if (endpt != NULL)
   1271  1.25.2.2  mycroft 			frpt = endpt + 1;
   1272  1.25.2.2  mycroft 		else
   1273  1.25.2.2  mycroft 			frpt = NULL;
   1274  1.25.2.2  mycroft 		if (ophead == NULL) {
   1275  1.25.2.2  mycroft 			optail = ophead = opt;
   1276  1.25.2.2  mycroft 			continue;
   1277  1.25.2.2  mycroft 		}
   1278  1.25.2.2  mycroft 		optail->fow = opt;
   1279  1.25.2.2  mycroft 		optail = opt;
   1280  1.25.2.2  mycroft 	}
   1281  1.25.2.2  mycroft 	return(0);
   1282  1.25.2.2  mycroft }
   1283  1.25.2.2  mycroft 
   1284  1.25.2.2  mycroft /*
   1285  1.25.2.2  mycroft  * str_offt()
   1286  1.25.2.2  mycroft  *	Convert an expression of the following forms to an off_t > 0.
   1287  1.25.2.2  mycroft  * 	1) A positive decimal number.
   1288  1.25.2.2  mycroft  *	2) A positive decimal number followed by a b (mult by 512).
   1289  1.25.2.2  mycroft  *	3) A positive decimal number followed by a k (mult by 1024).
   1290  1.25.2.2  mycroft  *	4) A positive decimal number followed by a m (mult by 512).
   1291  1.25.2.2  mycroft  *	5) A positive decimal number followed by a w (mult by sizeof int)
   1292  1.25.2.2  mycroft  *	6) Two or more positive decimal numbers (with/without k,b or w).
   1293  1.25.2.2  mycroft  *	   seperated by x (also * for backwards compatibility), specifying
   1294  1.25.2.2  mycroft  *	   the product of the indicated values.
   1295  1.25.2.2  mycroft  * Return:
   1296  1.25.2.2  mycroft  *	0 for an error, a positive value o.w.
   1297  1.25.2.2  mycroft  */
   1298  1.25.2.2  mycroft 
   1299  1.25.2.2  mycroft #if __STDC__
   1300  1.25.2.2  mycroft static off_t
   1301  1.25.2.2  mycroft str_offt(char *val)
   1302  1.25.2.2  mycroft #else
   1303  1.25.2.2  mycroft static off_t
   1304  1.25.2.2  mycroft str_offt(val)
   1305  1.25.2.2  mycroft 	char *val;
   1306  1.25.2.2  mycroft #endif
   1307  1.25.2.2  mycroft {
   1308  1.25.2.2  mycroft 	char *expr;
   1309  1.25.2.2  mycroft 	off_t num, t;
   1310  1.25.2.2  mycroft 
   1311  1.25.2.2  mycroft #	ifdef NET2_STAT
   1312  1.25.2.2  mycroft 	num = strtol(val, &expr, 0);
   1313  1.25.2.2  mycroft 	if ((num == LONG_MAX) || (num <= 0) || (expr == val))
   1314  1.25.2.2  mycroft #	else
   1315  1.25.2.2  mycroft 	num = strtoq(val, &expr, 0);
   1316  1.25.2.2  mycroft 	if ((num == QUAD_MAX) || (num <= 0) || (expr == val))
   1317  1.25.2.2  mycroft #	endif
   1318  1.25.2.2  mycroft 		return(0);
   1319  1.25.2.2  mycroft 
   1320  1.25.2.2  mycroft 	switch(*expr) {
   1321  1.25.2.2  mycroft 	case 'b':
   1322  1.25.2.2  mycroft 		t = num;
   1323  1.25.2.2  mycroft 		num *= 512;
   1324  1.25.2.2  mycroft 		if (t > num)
   1325  1.25.2.2  mycroft 			return(0);
   1326  1.25.2.2  mycroft 		++expr;
   1327  1.25.2.2  mycroft 		break;
   1328  1.25.2.2  mycroft 	case 'k':
   1329  1.25.2.2  mycroft 		t = num;
   1330  1.25.2.2  mycroft 		num *= 1024;
   1331  1.25.2.2  mycroft 		if (t > num)
   1332  1.25.2.2  mycroft 			return(0);
   1333  1.25.2.2  mycroft 		++expr;
   1334  1.25.2.2  mycroft 		break;
   1335  1.25.2.2  mycroft 	case 'm':
   1336  1.25.2.2  mycroft 		t = num;
   1337  1.25.2.2  mycroft 		num *= 1048576;
   1338  1.25.2.2  mycroft 		if (t > num)
   1339  1.25.2.2  mycroft 			return(0);
   1340  1.25.2.2  mycroft 		++expr;
   1341  1.25.2.2  mycroft 		break;
   1342  1.25.2.2  mycroft 	case 'w':
   1343  1.25.2.2  mycroft 		t = num;
   1344  1.25.2.2  mycroft 		num *= sizeof(int);
   1345  1.25.2.2  mycroft 		if (t > num)
   1346  1.25.2.2  mycroft 			return(0);
   1347  1.25.2.2  mycroft 		++expr;
   1348  1.25.2.2  mycroft 		break;
   1349  1.25.2.2  mycroft 	}
   1350  1.25.2.2  mycroft 
   1351  1.25.2.2  mycroft 	switch(*expr) {
   1352  1.25.2.2  mycroft 		case '\0':
   1353  1.25.2.2  mycroft 			break;
   1354  1.25.2.2  mycroft 		case '*':
   1355  1.25.2.2  mycroft 		case 'x':
   1356  1.25.2.2  mycroft 			t = num;
   1357  1.25.2.2  mycroft 			num *= str_offt(expr + 1);
   1358  1.25.2.2  mycroft 			if (t > num)
   1359  1.25.2.2  mycroft 				return(0);
   1360  1.25.2.2  mycroft 			break;
   1361  1.25.2.2  mycroft 		default:
   1362  1.25.2.2  mycroft 			return(0);
   1363  1.25.2.2  mycroft 	}
   1364  1.25.2.2  mycroft 	return(num);
   1365  1.25.2.2  mycroft }
   1366  1.25.2.2  mycroft 
   1367  1.25.2.2  mycroft /*
   1368  1.25.2.2  mycroft  * no_op()
   1369  1.25.2.2  mycroft  *	for those option functions where the archive format has nothing to do.
   1370  1.25.2.2  mycroft  * Return:
   1371  1.25.2.2  mycroft  *	0
   1372  1.25.2.2  mycroft  */
   1373  1.25.2.2  mycroft 
   1374  1.25.2.2  mycroft #if __STDC__
   1375  1.25.2.2  mycroft static int
   1376  1.25.2.2  mycroft no_op(void)
   1377  1.25.2.2  mycroft #else
   1378  1.25.2.2  mycroft static int
   1379  1.25.2.2  mycroft no_op()
   1380  1.25.2.2  mycroft #endif
   1381  1.25.2.2  mycroft {
   1382  1.25.2.2  mycroft 	return(0);
   1383  1.25.2.2  mycroft }
   1384  1.25.2.2  mycroft 
   1385  1.25.2.2  mycroft /*
   1386  1.25.2.2  mycroft  * pax_usage()
   1387  1.25.2.2  mycroft  *	print the usage summary to the user
   1388  1.25.2.2  mycroft  */
   1389  1.25.2.2  mycroft 
   1390  1.25.2.2  mycroft #if __STDC__
   1391  1.25.2.2  mycroft void
   1392  1.25.2.2  mycroft pax_usage(void)
   1393  1.25.2.2  mycroft #else
   1394  1.25.2.2  mycroft void
   1395  1.25.2.2  mycroft pax_usage()
   1396  1.25.2.2  mycroft #endif
   1397  1.25.2.2  mycroft {
   1398  1.25.2.2  mycroft 	(void)fputs("usage: pax [-cdnvz] [-E limit] [-f archive] ", stderr);
   1399  1.25.2.2  mycroft 	(void)fputs("[-s replstr] ... [-U user] ...", stderr);
   1400  1.25.2.2  mycroft 	(void)fputs("\n           [-G group] ... ", stderr);
   1401  1.25.2.2  mycroft 	(void)fputs("[-T [from_date][,to_date]] ... ", stderr);
   1402  1.25.2.2  mycroft 	(void)fputs("[pattern ...]\n", stderr);
   1403  1.25.2.2  mycroft 	(void)fputs("       pax -r [-cdiknuvzDYZ] [-E limit] ", stderr);
   1404  1.25.2.2  mycroft 	(void)fputs("[-f archive] [-o options] ... \n", stderr);
   1405  1.25.2.2  mycroft 	(void)fputs("           [-p string] ... [-s replstr] ... ", stderr);
   1406  1.25.2.2  mycroft 	(void)fputs("[-U user] ... [-G group] ...\n           ", stderr);
   1407  1.25.2.2  mycroft 	(void)fputs("[-T [from_date][,to_date]] ... ", stderr);
   1408  1.25.2.2  mycroft 	(void)fputs(" [pattern ...]\n", stderr);
   1409  1.25.2.2  mycroft 	(void)fputs("       pax -w [-dituvzHLPX] [-b blocksize] ", stderr);
   1410  1.25.2.2  mycroft 	(void)fputs("[[-a] [-f archive]] [-x format] \n", stderr);
   1411  1.25.2.2  mycroft 	(void)fputs("           [-B bytes] [-o options] ... ", stderr);
   1412  1.25.2.2  mycroft 	(void)fputs("[-s replstr] ... [-U user] ...", stderr);
   1413  1.25.2.2  mycroft 	(void)fputs("\n           [-G group] ... ", stderr);
   1414  1.25.2.2  mycroft 	(void)fputs("[-T [from_date][,to_date][/[c][m]]] ... ", stderr);
   1415  1.25.2.2  mycroft 	(void)fputs("[file ...]\n", stderr);
   1416  1.25.2.2  mycroft 	(void)fputs("       pax -r -w [-diklntuvzDHLPXYZ] ", stderr);
   1417  1.25.2.2  mycroft 	(void)fputs("[-p string] ... [-s replstr] ...", stderr);
   1418  1.25.2.2  mycroft 	(void)fputs("\n           [-U user] ... [-G group] ... ", stderr);
   1419  1.25.2.2  mycroft 	(void)fputs("[-T [from_date][,to_date][/[c][m]]] ... ", stderr);
   1420  1.25.2.2  mycroft 	(void)fputs("\n           [file ...] directory\n", stderr);
   1421  1.25.2.2  mycroft 	exit(1);
   1422  1.25.2.2  mycroft 	/* NOTREACHED */
   1423  1.25.2.2  mycroft }
   1424  1.25.2.2  mycroft 
   1425  1.25.2.2  mycroft /*
   1426  1.25.2.2  mycroft  * tar_usage()
   1427  1.25.2.2  mycroft  *	print the usage summary to the user
   1428  1.25.2.2  mycroft  */
   1429  1.25.2.2  mycroft 
   1430  1.25.2.2  mycroft #if __STDC__
   1431  1.25.2.2  mycroft void
   1432  1.25.2.2  mycroft tar_usage(void)
   1433  1.25.2.2  mycroft #else
   1434  1.25.2.2  mycroft void
   1435  1.25.2.2  mycroft tar_usage()
   1436  1.25.2.2  mycroft #endif
   1437  1.25.2.2  mycroft {
   1438  1.25.2.2  mycroft 	(void)fputs("usage: tar -{txru}[cevfbhlmopwBLPX014578] [tapefile] ",
   1439  1.25.2.2  mycroft 		 stderr);
   1440  1.25.2.2  mycroft 	(void)fputs("[blocksize] [exclude-file] file1 file2...\n", stderr);
   1441  1.25.2.2  mycroft 	exit(1);
   1442  1.25.2.2  mycroft 	/* NOTREACHED */
   1443  1.25.2.2  mycroft }
   1444  1.25.2.2  mycroft 
   1445  1.25.2.2  mycroft /*
   1446  1.25.2.2  mycroft  * cpio_usage()
   1447  1.25.2.2  mycroft  *	print the usage summary to the user
   1448  1.25.2.2  mycroft  */
   1449  1.25.2.2  mycroft 
   1450  1.25.2.2  mycroft #if __STDC__
   1451  1.25.2.2  mycroft void
   1452  1.25.2.2  mycroft cpio_usage(void)
   1453  1.25.2.2  mycroft #else
   1454  1.25.2.2  mycroft void
   1455  1.25.2.2  mycroft cpio_usage()
   1456  1.25.2.2  mycroft #endif
   1457  1.25.2.2  mycroft {
   1458  1.25.2.2  mycroft 
   1459  1.25.2.2  mycroft #if 1
   1460  1.25.2.2  mycroft 	(void)fputs(
   1461  1.25.2.2  mycroft 	    "usage: cpio -i [-BcdfmrStuv] [ -C blksize ] [ -H header ]\n",
   1462  1.25.2.2  mycroft 	    stderr);
   1463  1.25.2.2  mycroft 	(void)fputs("  [ -I file ] [ pattern ... ]\n", stderr);
   1464  1.25.2.2  mycroft 	(void)fputs("usage: cpio -o [-aABcLv] [ -C bufsize ] [ -H header ]\n",
   1465  1.25.2.2  mycroft 	    stderr);
   1466  1.25.2.2  mycroft 	(void)fputs("  [ -O file ]\n", stderr);
   1467  1.25.2.2  mycroft 	(void)fputs("usage: cpio -p [ adlLmuv ] directory\n", stderr);
   1468  1.25.2.2  mycroft #else
   1469  1.25.2.2  mycroft 	/* no E, M, R, V, b, k or s */
   1470  1.25.2.2  mycroft 	(void)fputs("usage: cpio -i [-bBcdfkmrsStuvV] [ -C bufsize ]\n", stderr);
   1471  1.25.2.2  mycroft 	(void)fputs("  [ -E file ] [ -H header ] [ -I file [ -M message ] ]\n",
   1472  1.25.2.2  mycroft 	    stderr);
   1473  1.25.2.2  mycroft 	(void)fputs("  [ -R id ] [ pattern ... ]\n", stderr);
   1474  1.25.2.2  mycroft 	(void)fputs("usage: cpio -o [-aABcLvV] [ -C bufsize ] [ -H header ]\n",
   1475  1.25.2.2  mycroft 	    stderr);
   1476  1.25.2.2  mycroft 	(void)fputs("  [ -O file [ -M message ] ]\n", stderr);
   1477  1.25.2.2  mycroft 	(void)fputs("usage: cpio -p [ adlLmuvV ] [ -R id ] directory\n", stderr);
   1478  1.25.2.2  mycroft #endif
   1479  1.25.2.2  mycroft 	exit(1);
   1480  1.25.2.2  mycroft 	/* NOTREACHED */
   1481  1.25.2.2  mycroft }
   1482  1.25.2.2  mycroft 
   1483  1.25.2.2  mycroft /*
   1484  1.25.2.2  mycroft  * opt_chdir
   1485  1.25.2.2  mycroft  *	call ftree_add or pat_add, depending on archive type.
   1486  1.25.2.2  mycroft  *
   1487  1.25.2.2  mycroft  * Returns: -1 for listing, else what ftree_add or pat_add returned.
   1488  1.25.2.2  mycroft  */
   1489  1.25.2.2  mycroft 
   1490  1.25.2.2  mycroft #ifdef __STDC__
   1491  1.25.2.2  mycroft int
   1492  1.25.2.2  mycroft opt_chdir(char *name)
   1493  1.25.2.2  mycroft #else
   1494  1.25.2.2  mycroft int
   1495  1.25.2.2  mycroft opt_chdir(name)
   1496  1.25.2.2  mycroft 	char *name;
   1497  1.25.2.2  mycroft #endif
   1498  1.25.2.2  mycroft {
   1499  1.25.2.2  mycroft 	switch (act) {
   1500  1.25.2.2  mycroft 	default:
   1501  1.25.2.2  mycroft 		return (-1);
   1502  1.25.2.2  mycroft 		break;
   1503  1.25.2.2  mycroft 	case ARCHIVE:
   1504  1.25.2.2  mycroft 	case APPND:
   1505  1.25.2.2  mycroft 		return (ftree_add(name, 1));
   1506  1.25.2.2  mycroft 		break;
   1507  1.25.2.2  mycroft 	case EXTRACT:
   1508  1.25.2.2  mycroft 		return (pat_add(name, 1));
   1509  1.25.2.2  mycroft 		break;
   1510  1.25.2.2  mycroft 	}
   1511  1.25.2.2  mycroft }
   1512  1.25.2.2  mycroft 
   1513  1.25.2.2  mycroft /*
   1514  1.25.2.2  mycroft  * checkpositionalminusC(argvp, addfunc)
   1515  1.25.2.2  mycroft  */
   1516  1.25.2.2  mycroft 
   1517  1.25.2.2  mycroft #ifdef __STDC__
   1518  1.25.2.2  mycroft void
   1519  1.25.2.2  mycroft checkpositionalminusC(char ***argvp, int (*addfunc)(char *, int))
   1520  1.25.2.2  mycroft #else
   1521  1.25.2.2  mycroft void
   1522  1.25.2.2  mycroft checkpositionalminusC(argvp, addfunc)
   1523  1.25.2.2  mycroft 	char ***argvp;
   1524  1.25.2.2  mycroft 	int (*addfunc)();
   1525  1.25.2.2  mycroft #endif
   1526  1.25.2.2  mycroft {
   1527  1.25.2.2  mycroft 	while (**argvp != (char *)NULL) {
   1528  1.25.2.2  mycroft 		if (!strcmp(**argvp, "-C")) {
   1529  1.25.2.2  mycroft 			/* XXX should be allow for positional -C/dir, too? */
   1530  1.25.2.2  mycroft 			if ((*addfunc)(*++*argvp, 1) < 0) {
   1531  1.25.2.2  mycroft 				tar_usage();
   1532  1.25.2.2  mycroft 			}
   1533  1.25.2.2  mycroft 			++*argvp;
   1534  1.25.2.2  mycroft 			continue;
   1535  1.25.2.2  mycroft 		}
   1536  1.25.2.2  mycroft 		if ((*addfunc)(*(*argvp)++, 0) < 0)
   1537  1.25.2.2  mycroft 			tar_usage();
   1538  1.25.2.2  mycroft 	}
   1539  1.25.2.2  mycroft }
   1540