Home | History | Annotate | Line # | Download | only in pax
options.c revision 1.7
      1  1.7  tls /*	$NetBSD: options.c,v 1.7 1997/01/11 02:06:41 tls Exp $	*/
      2  1.5  cgd 
      3  1.1  jtc /*-
      4  1.1  jtc  * Copyright (c) 1992 Keith Muller.
      5  1.1  jtc  * Copyright (c) 1992, 1993
      6  1.1  jtc  *	The Regents of the University of California.  All rights reserved.
      7  1.1  jtc  *
      8  1.1  jtc  * This code is derived from software contributed to Berkeley by
      9  1.1  jtc  * Keith Muller of the University of California, San Diego.
     10  1.1  jtc  *
     11  1.1  jtc  * Redistribution and use in source and binary forms, with or without
     12  1.1  jtc  * modification, are permitted provided that the following conditions
     13  1.1  jtc  * are met:
     14  1.1  jtc  * 1. Redistributions of source code must retain the above copyright
     15  1.1  jtc  *    notice, this list of conditions and the following disclaimer.
     16  1.1  jtc  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  jtc  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  jtc  *    documentation and/or other materials provided with the distribution.
     19  1.1  jtc  * 3. All advertising materials mentioning features or use of this software
     20  1.1  jtc  *    must display the following acknowledgement:
     21  1.1  jtc  *	This product includes software developed by the University of
     22  1.1  jtc  *	California, Berkeley and its contributors.
     23  1.1  jtc  * 4. Neither the name of the University nor the names of its contributors
     24  1.1  jtc  *    may be used to endorse or promote products derived from this software
     25  1.1  jtc  *    without specific prior written permission.
     26  1.1  jtc  *
     27  1.1  jtc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     28  1.1  jtc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     29  1.1  jtc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     30  1.1  jtc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     31  1.1  jtc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     32  1.1  jtc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     33  1.1  jtc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     34  1.1  jtc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     35  1.1  jtc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     36  1.1  jtc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     37  1.1  jtc  * SUCH DAMAGE.
     38  1.1  jtc  */
     39  1.1  jtc 
     40  1.1  jtc #ifndef lint
     41  1.5  cgd #if 0
     42  1.5  cgd static char sccsid[] = "@(#)options.c	8.2 (Berkeley) 4/18/94";
     43  1.5  cgd #else
     44  1.7  tls static char rcsid[] = "$NetBSD: options.c,v 1.7 1997/01/11 02:06:41 tls Exp $";
     45  1.5  cgd #endif
     46  1.1  jtc #endif /* not lint */
     47  1.1  jtc 
     48  1.1  jtc #include <sys/types.h>
     49  1.1  jtc #include <sys/time.h>
     50  1.1  jtc #include <sys/stat.h>
     51  1.1  jtc #include <sys/mtio.h>
     52  1.1  jtc #include <sys/param.h>
     53  1.1  jtc #include <stdio.h>
     54  1.1  jtc #include <ctype.h>
     55  1.1  jtc #include <string.h>
     56  1.1  jtc #include <unistd.h>
     57  1.1  jtc #include <stdlib.h>
     58  1.1  jtc #include <limits.h>
     59  1.1  jtc #include "pax.h"
     60  1.1  jtc #include "options.h"
     61  1.1  jtc #include "cpio.h"
     62  1.1  jtc #include "tar.h"
     63  1.1  jtc #include "extern.h"
     64  1.1  jtc 
     65  1.1  jtc /*
     66  1.1  jtc  * Routines which handle command line options
     67  1.1  jtc  */
     68  1.1  jtc 
     69  1.1  jtc static char flgch[] = FLGCH;	/* list of all possible flags */
     70  1.1  jtc static OPLIST *ophead = NULL;	/* head for format specific options -x */
     71  1.1  jtc static OPLIST *optail = NULL;	/* option tail */
     72  1.1  jtc 
     73  1.1  jtc static int no_op __P((void));
     74  1.1  jtc static void printflg __P((unsigned int));
     75  1.1  jtc static int c_frmt __P((const void *, const void *));
     76  1.1  jtc static off_t str_offt __P((char *));
     77  1.7  tls static void pax_options __P((int, char **));
     78  1.1  jtc static void pax_usage __P((void));
     79  1.7  tls static void tar_options __P((int, char **));
     80  1.1  jtc static void tar_usage __P((void));
     81  1.1  jtc #ifdef notdef
     82  1.7  tls static void cpio_options __P((int, char **));
     83  1.1  jtc static void cpio_usage __P((void));
     84  1.1  jtc #endif
     85  1.1  jtc 
     86  1.6  mrg #define GZIP_CMD	"gzip"		/* command to run as gzip */
     87  1.6  mrg #define COMPRESS_CMD	"compress"	/* command to run as compress */
     88  1.6  mrg 
     89  1.1  jtc /*
     90  1.1  jtc  *	Format specific routine table - MUST BE IN SORTED ORDER BY NAME
     91  1.1  jtc  *	(see pax.h for description of each function)
     92  1.1  jtc  *
     93  1.1  jtc  * 	name, blksz, hdsz, udev, hlk, blkagn, inhead, id, st_read,
     94  1.1  jtc  *	read, end_read, st_write, write, end_write, trail,
     95  1.1  jtc  *	rd_data, wr_data, options
     96  1.1  jtc  */
     97  1.1  jtc 
     98  1.1  jtc FSUB fsub[] = {
     99  1.1  jtc /* 0: OLD BINARY CPIO */
    100  1.1  jtc 	"bcpio", 5120, sizeof(HD_BCPIO), 1, 0, 0, 1, bcpio_id, cpio_strd,
    101  1.1  jtc 	bcpio_rd, bcpio_endrd, cpio_stwr, bcpio_wr, cpio_endwr, cpio_trail,
    102  1.1  jtc 	rd_wrfile, wr_rdfile, bad_opt,
    103  1.1  jtc 
    104  1.1  jtc /* 1: OLD OCTAL CHARACTER CPIO */
    105  1.1  jtc 	"cpio", 5120, sizeof(HD_CPIO), 1, 0, 0, 1, cpio_id, cpio_strd,
    106  1.1  jtc 	cpio_rd, cpio_endrd, cpio_stwr, cpio_wr, cpio_endwr, cpio_trail,
    107  1.1  jtc 	rd_wrfile, wr_rdfile, bad_opt,
    108  1.1  jtc 
    109  1.1  jtc /* 2: SVR4 HEX CPIO */
    110  1.1  jtc 	"sv4cpio", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, vcpio_id, cpio_strd,
    111  1.1  jtc 	vcpio_rd, vcpio_endrd, cpio_stwr, vcpio_wr, cpio_endwr, cpio_trail,
    112  1.1  jtc 	rd_wrfile, wr_rdfile, bad_opt,
    113  1.1  jtc 
    114  1.1  jtc /* 3: SVR4 HEX CPIO WITH CRC */
    115  1.1  jtc 	"sv4crc", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, crc_id, crc_strd,
    116  1.1  jtc 	vcpio_rd, vcpio_endrd, crc_stwr, vcpio_wr, cpio_endwr, cpio_trail,
    117  1.1  jtc 	rd_wrfile, wr_rdfile, bad_opt,
    118  1.1  jtc 
    119  1.1  jtc /* 4: OLD TAR */
    120  1.1  jtc 	"tar", 10240, BLKMULT, 0, 1, BLKMULT, 0, tar_id, no_op,
    121  1.1  jtc 	tar_rd, tar_endrd, no_op, tar_wr, tar_endwr, tar_trail,
    122  1.1  jtc 	rd_wrfile, wr_rdfile, tar_opt,
    123  1.1  jtc 
    124  1.1  jtc /* 5: POSIX USTAR */
    125  1.1  jtc 	"ustar", 10240, BLKMULT, 0, 1, BLKMULT, 0, ustar_id, ustar_strd,
    126  1.1  jtc 	ustar_rd, tar_endrd, ustar_stwr, ustar_wr, tar_endwr, tar_trail,
    127  1.1  jtc 	rd_wrfile, wr_rdfile, bad_opt,
    128  1.1  jtc };
    129  1.1  jtc #define F_TAR	4	/* format when called as tar */
    130  1.1  jtc #define DEFLT	5	/* default write format from list above */
    131  1.1  jtc 
    132  1.1  jtc /*
    133  1.1  jtc  * ford is the archive search order used by get_arc() to determine what kind
    134  1.1  jtc  * of archive we are dealing with. This helps to properly id  archive formats
    135  1.1  jtc  * some formats may be subsets of others....
    136  1.1  jtc  */
    137  1.1  jtc int ford[] = {5, 4, 3, 2, 1, 0, -1 };
    138  1.1  jtc 
    139  1.1  jtc /*
    140  1.1  jtc  * options()
    141  1.1  jtc  *	figure out if we are pax, tar or cpio. Call the appropriate options
    142  1.1  jtc  *	parser
    143  1.1  jtc  */
    144  1.1  jtc 
    145  1.1  jtc #if __STDC__
    146  1.1  jtc void
    147  1.7  tls options(int argc, char **argv)
    148  1.1  jtc #else
    149  1.1  jtc void
    150  1.1  jtc options(argc, argv)
    151  1.7  tls 	int argc;
    152  1.7  tls 	char **argv;
    153  1.1  jtc #endif
    154  1.1  jtc {
    155  1.1  jtc 
    156  1.1  jtc 	/*
    157  1.1  jtc 	 * Are we acting like pax, tar or cpio (based on argv[0])
    158  1.1  jtc 	 */
    159  1.1  jtc 	if ((argv0 = strrchr(argv[0], '/')) != NULL)
    160  1.1  jtc 		argv0++;
    161  1.1  jtc 	else
    162  1.1  jtc 		argv0 = argv[0];
    163  1.1  jtc 
    164  1.1  jtc 	if (strcmp(NM_TAR, argv0) == 0)
    165  1.1  jtc 		return(tar_options(argc, argv));
    166  1.1  jtc #	ifdef notdef
    167  1.1  jtc 	else if (strcmp(NM_CPIO, argv0) == 0)
    168  1.1  jtc 		return(cpio_options(argc, argv));
    169  1.1  jtc #	endif
    170  1.1  jtc 	/*
    171  1.1  jtc 	 * assume pax as the default
    172  1.1  jtc 	 */
    173  1.1  jtc 	argv0 = NM_PAX;
    174  1.1  jtc 	return(pax_options(argc, argv));
    175  1.1  jtc }
    176  1.1  jtc 
    177  1.1  jtc /*
    178  1.1  jtc  * pax_options()
    179  1.1  jtc  *	look at the user specified flags. set globals as required and check if
    180  1.1  jtc  *	the user specified a legal set of flags. If not, complain and exit
    181  1.1  jtc  */
    182  1.1  jtc 
    183  1.1  jtc #if __STDC__
    184  1.1  jtc static void
    185  1.7  tls pax_options(int argc, char **argv)
    186  1.1  jtc #else
    187  1.1  jtc static void
    188  1.1  jtc pax_options(argc, argv)
    189  1.7  tls 	int argc;
    190  1.7  tls 	char **argv;
    191  1.1  jtc #endif
    192  1.1  jtc {
    193  1.7  tls 	int c;
    194  1.7  tls 	int i;
    195  1.1  jtc 	unsigned int flg = 0;
    196  1.1  jtc 	unsigned int bflg = 0;
    197  1.7  tls 	char *pt;
    198  1.1  jtc         FSUB tmp;
    199  1.1  jtc 	extern char *optarg;
    200  1.1  jtc 	extern int optind;
    201  1.1  jtc 
    202  1.1  jtc 	/*
    203  1.1  jtc 	 * process option flags
    204  1.1  jtc 	 */
    205  1.6  mrg 	while ((c=getopt(argc,argv,"ab:cdf:iklno:p:rs:tuvwx:zB:DE:G:HLPT:U:XYZ"))
    206  1.1  jtc 	    != EOF) {
    207  1.1  jtc 		switch (c) {
    208  1.1  jtc 		case 'a':
    209  1.1  jtc 			/*
    210  1.1  jtc 			 * append
    211  1.1  jtc 			 */
    212  1.1  jtc 			flg |= AF;
    213  1.1  jtc 			break;
    214  1.1  jtc 		case 'b':
    215  1.1  jtc 			/*
    216  1.1  jtc 			 * specify blocksize
    217  1.1  jtc 			 */
    218  1.1  jtc 			flg |= BF;
    219  1.1  jtc 			if ((wrblksz = (int)str_offt(optarg)) <= 0) {
    220  1.1  jtc 				warn(1, "Invalid block size %s", optarg);
    221  1.1  jtc 				pax_usage();
    222  1.1  jtc 			}
    223  1.1  jtc 			break;
    224  1.1  jtc 		case 'c':
    225  1.1  jtc 			/*
    226  1.1  jtc 			 * inverse match on patterns
    227  1.1  jtc 			 */
    228  1.1  jtc 			cflag = 1;
    229  1.1  jtc 			flg |= CF;
    230  1.1  jtc 			break;
    231  1.1  jtc 		case 'd':
    232  1.1  jtc 			/*
    233  1.1  jtc 			 * match only dir on extract, not the subtree at dir
    234  1.1  jtc 			 */
    235  1.1  jtc 			dflag = 1;
    236  1.1  jtc 			flg |= DF;
    237  1.1  jtc 			break;
    238  1.1  jtc 		case 'f':
    239  1.1  jtc 			/*
    240  1.1  jtc 			 * filename where the archive is stored
    241  1.1  jtc 			 */
    242  1.1  jtc 			arcname = optarg;
    243  1.1  jtc 			flg |= FF;
    244  1.1  jtc 			break;
    245  1.1  jtc 		case 'i':
    246  1.1  jtc 			/*
    247  1.1  jtc 			 * interactive file rename
    248  1.1  jtc 			 */
    249  1.1  jtc 			iflag = 1;
    250  1.1  jtc 			flg |= IF;
    251  1.1  jtc 			break;
    252  1.1  jtc 		case 'k':
    253  1.1  jtc 			/*
    254  1.1  jtc 			 * do not clobber files that exist
    255  1.1  jtc 			 */
    256  1.1  jtc 			kflag = 1;
    257  1.1  jtc 			flg |= KF;
    258  1.1  jtc 			break;
    259  1.1  jtc 		case 'l':
    260  1.1  jtc 			/*
    261  1.1  jtc 			 * try to link src to dest with copy (-rw)
    262  1.1  jtc 			 */
    263  1.1  jtc 			lflag = 1;
    264  1.1  jtc 			flg |= LF;
    265  1.1  jtc 			break;
    266  1.1  jtc 		case 'n':
    267  1.1  jtc 			/*
    268  1.1  jtc 			 * select first match for a pattern only
    269  1.1  jtc 			 */
    270  1.1  jtc 			nflag = 1;
    271  1.1  jtc 			flg |= NF;
    272  1.1  jtc 			break;
    273  1.1  jtc 		case 'o':
    274  1.1  jtc 			/*
    275  1.1  jtc 			 * pass format specific options
    276  1.1  jtc 			 */
    277  1.1  jtc 			flg |= OF;
    278  1.1  jtc 			if (opt_add(optarg) < 0)
    279  1.1  jtc 				pax_usage();
    280  1.1  jtc 			break;
    281  1.1  jtc 		case 'p':
    282  1.1  jtc 			/*
    283  1.1  jtc 			 * specify file characteristic options
    284  1.1  jtc 			 */
    285  1.1  jtc 			for (pt = optarg; *pt != '\0'; ++pt) {
    286  1.1  jtc 				switch(*pt) {
    287  1.1  jtc 				case 'a':
    288  1.1  jtc 					/*
    289  1.1  jtc 					 * do not preserve access time
    290  1.1  jtc 					 */
    291  1.1  jtc 					patime = 0;
    292  1.1  jtc 					break;
    293  1.1  jtc 				case 'e':
    294  1.1  jtc 					/*
    295  1.1  jtc 					 * preserve user id, group id, file
    296  1.1  jtc 					 * mode, access/modification times
    297  1.1  jtc 					 */
    298  1.1  jtc 					pids = 1;
    299  1.1  jtc 					pmode = 1;
    300  1.1  jtc 					patime = 1;
    301  1.1  jtc 					pmtime = 1;
    302  1.1  jtc 					break;
    303  1.1  jtc 				case 'm':
    304  1.1  jtc 					/*
    305  1.1  jtc 					 * do not preserve modification time
    306  1.1  jtc 					 */
    307  1.1  jtc 					pmtime = 0;
    308  1.1  jtc 					break;
    309  1.1  jtc 				case 'o':
    310  1.1  jtc 					/*
    311  1.1  jtc 					 * preserve uid/gid
    312  1.1  jtc 					 */
    313  1.1  jtc 					pids = 1;
    314  1.1  jtc 					break;
    315  1.1  jtc 				case 'p':
    316  1.1  jtc 					/*
    317  1.1  jtc 					 * preserver file mode bits
    318  1.1  jtc 					 */
    319  1.1  jtc 					pmode = 1;
    320  1.1  jtc 					break;
    321  1.1  jtc 				default:
    322  1.1  jtc 					warn(1, "Invalid -p string: %c", *pt);
    323  1.1  jtc 					pax_usage();
    324  1.1  jtc 					break;
    325  1.1  jtc 				}
    326  1.1  jtc 			}
    327  1.1  jtc 			flg |= PF;
    328  1.1  jtc 			break;
    329  1.1  jtc 		case 'r':
    330  1.1  jtc 			/*
    331  1.1  jtc 			 * read the archive
    332  1.1  jtc 			 */
    333  1.1  jtc 			flg |= RF;
    334  1.1  jtc 			break;
    335  1.1  jtc 		case 's':
    336  1.1  jtc 			/*
    337  1.1  jtc 			 * file name substitution name pattern
    338  1.1  jtc 			 */
    339  1.1  jtc 			if (rep_add(optarg) < 0) {
    340  1.1  jtc 				pax_usage();
    341  1.1  jtc 				break;
    342  1.1  jtc 			}
    343  1.1  jtc 			flg |= SF;
    344  1.1  jtc 			break;
    345  1.1  jtc 		case 't':
    346  1.1  jtc 			/*
    347  1.1  jtc 			 * preserve access time on filesystem nodes we read
    348  1.1  jtc 			 */
    349  1.1  jtc 			tflag = 1;
    350  1.1  jtc 			flg |= TF;
    351  1.1  jtc 			break;
    352  1.1  jtc 		case 'u':
    353  1.1  jtc 			/*
    354  1.1  jtc 			 * ignore those older files
    355  1.1  jtc 			 */
    356  1.1  jtc 			uflag = 1;
    357  1.1  jtc 			flg |= UF;
    358  1.1  jtc 			break;
    359  1.1  jtc 		case 'v':
    360  1.1  jtc 			/*
    361  1.1  jtc 			 * verbose operation mode
    362  1.1  jtc 			 */
    363  1.1  jtc 			vflag = 1;
    364  1.1  jtc 			flg |= VF;
    365  1.1  jtc 			break;
    366  1.1  jtc 		case 'w':
    367  1.1  jtc 			/*
    368  1.1  jtc 			 * write an archive
    369  1.1  jtc 			 */
    370  1.1  jtc 			flg |= WF;
    371  1.1  jtc 			break;
    372  1.1  jtc 		case 'x':
    373  1.1  jtc 			/*
    374  1.1  jtc 			 * specify an archive format on write
    375  1.1  jtc 			 */
    376  1.1  jtc 			tmp.name = optarg;
    377  1.1  jtc 			if (frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub,
    378  1.1  jtc 			    sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt)) {
    379  1.1  jtc 				flg |= XF;
    380  1.1  jtc 				break;
    381  1.1  jtc 			}
    382  1.1  jtc 			warn(1, "Unknown -x format: %s", optarg);
    383  1.1  jtc 			(void)fputs("pax: Known -x formats are:", stderr);
    384  1.1  jtc 			for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i)
    385  1.1  jtc 				(void)fprintf(stderr, " %s", fsub[i].name);
    386  1.1  jtc 			(void)fputs("\n\n", stderr);
    387  1.1  jtc 			pax_usage();
    388  1.1  jtc 			break;
    389  1.6  mrg 		case 'z':
    390  1.6  mrg 			/*
    391  1.6  mrg 			 * use gzip.  Non standard option.
    392  1.6  mrg 			 */
    393  1.6  mrg 			zflag = 1;
    394  1.6  mrg 			gzip_program = GZIP_CMD;
    395  1.6  mrg 			break;
    396  1.1  jtc 		case 'B':
    397  1.1  jtc 			/*
    398  1.1  jtc 			 * non-standard option on number of bytes written on a
    399  1.1  jtc 			 * single archive volume.
    400  1.1  jtc 			 */
    401  1.1  jtc 			if ((wrlimit = str_offt(optarg)) <= 0) {
    402  1.1  jtc 				warn(1, "Invalid write limit %s", optarg);
    403  1.1  jtc 				pax_usage();
    404  1.1  jtc 			}
    405  1.1  jtc 			if (wrlimit % BLKMULT) {
    406  1.1  jtc 				warn(1, "Write limit is not a %d byte multiple",
    407  1.1  jtc 				    BLKMULT);
    408  1.1  jtc 				pax_usage();
    409  1.1  jtc 			}
    410  1.1  jtc 			flg |= CBF;
    411  1.1  jtc 			break;
    412  1.1  jtc 		case 'D':
    413  1.1  jtc 			/*
    414  1.1  jtc 			 * On extraction check file inode change time before the
    415  1.1  jtc 			 * modification of the file name. Non standard option.
    416  1.1  jtc 			 */
    417  1.1  jtc 			Dflag = 1;
    418  1.1  jtc 			flg |= CDF;
    419  1.1  jtc 			break;
    420  1.1  jtc 		case 'E':
    421  1.1  jtc 			/*
    422  1.1  jtc 			 * non-standard limit on read faults
    423  1.1  jtc 			 * 0 indicates stop after first error, values
    424  1.1  jtc 			 * indicate a limit, "NONE" try forever
    425  1.1  jtc 			 */
    426  1.1  jtc 			flg |= CEF;
    427  1.1  jtc 			if (strcmp(NONE, optarg) == 0)
    428  1.1  jtc 				maxflt = -1;
    429  1.1  jtc 			else if ((maxflt = atoi(optarg)) < 0) {
    430  1.1  jtc 				warn(1, "Error count value must be positive");
    431  1.1  jtc 				pax_usage();
    432  1.1  jtc 			}
    433  1.1  jtc 			break;
    434  1.1  jtc 		case 'G':
    435  1.1  jtc 			/*
    436  1.1  jtc 			 * non-standard option for selecting files within an
    437  1.1  jtc 			 * archive by group (gid or name)
    438  1.1  jtc 			 */
    439  1.1  jtc 			if (grp_add(optarg) < 0) {
    440  1.1  jtc 				pax_usage();
    441  1.1  jtc 				break;
    442  1.1  jtc 			}
    443  1.1  jtc 			flg |= CGF;
    444  1.1  jtc 			break;
    445  1.1  jtc 		case 'H':
    446  1.1  jtc 			/*
    447  1.1  jtc 			 * follow command line symlinks only
    448  1.1  jtc 			 */
    449  1.1  jtc 			Hflag = 1;
    450  1.1  jtc 			flg |= CHF;
    451  1.1  jtc 			break;
    452  1.1  jtc 		case 'L':
    453  1.1  jtc 			/*
    454  1.1  jtc 			 * follow symlinks
    455  1.1  jtc 			 */
    456  1.1  jtc 			Lflag = 1;
    457  1.1  jtc 			flg |= CLF;
    458  1.1  jtc 			break;
    459  1.1  jtc 		case 'P':
    460  1.1  jtc 			/*
    461  1.1  jtc 			 * do NOT follow symlinks (default)
    462  1.1  jtc 			 */
    463  1.1  jtc 			Lflag = 0;
    464  1.1  jtc 			flg |= CPF;
    465  1.1  jtc 			break;
    466  1.1  jtc 		case 'T':
    467  1.1  jtc 			/*
    468  1.1  jtc 			 * non-standard option for selecting files within an
    469  1.1  jtc 			 * archive by modification time range (lower,upper)
    470  1.1  jtc 			 */
    471  1.1  jtc 			if (trng_add(optarg) < 0) {
    472  1.1  jtc 				pax_usage();
    473  1.1  jtc 				break;
    474  1.1  jtc 			}
    475  1.1  jtc 			flg |= CTF;
    476  1.1  jtc 			break;
    477  1.1  jtc 		case 'U':
    478  1.1  jtc 			/*
    479  1.1  jtc 			 * non-standard option for selecting files within an
    480  1.1  jtc 			 * archive by user (uid or name)
    481  1.1  jtc 			 */
    482  1.1  jtc 			if (usr_add(optarg) < 0) {
    483  1.1  jtc 				pax_usage();
    484  1.1  jtc 				break;
    485  1.1  jtc 			}
    486  1.1  jtc 			flg |= CUF;
    487  1.1  jtc 			break;
    488  1.1  jtc 		case 'X':
    489  1.1  jtc 			/*
    490  1.1  jtc 			 * do not pass over mount points in the file system
    491  1.1  jtc 			 */
    492  1.1  jtc 			Xflag = 1;
    493  1.1  jtc 			flg |= CXF;
    494  1.1  jtc 			break;
    495  1.1  jtc 		case 'Y':
    496  1.1  jtc 			/*
    497  1.1  jtc 			 * On extraction check file inode change time after the
    498  1.1  jtc 			 * modification of the file name. Non standard option.
    499  1.1  jtc 			 */
    500  1.1  jtc 			Yflag = 1;
    501  1.1  jtc 			flg |= CYF;
    502  1.1  jtc 			break;
    503  1.1  jtc 		case 'Z':
    504  1.1  jtc 			/*
    505  1.1  jtc 			 * On extraction check modification time after the
    506  1.1  jtc 			 * modification of the file name. Non standard option.
    507  1.1  jtc 			 */
    508  1.1  jtc 			Zflag = 1;
    509  1.1  jtc 			flg |= CZF;
    510  1.1  jtc 			break;
    511  1.1  jtc 		case '?':
    512  1.1  jtc 		default:
    513  1.1  jtc 			pax_usage();
    514  1.1  jtc 			break;
    515  1.1  jtc 		}
    516  1.1  jtc 	}
    517  1.1  jtc 
    518  1.1  jtc 	/*
    519  1.1  jtc 	 * figure out the operation mode of pax read,write,extract,copy,append
    520  1.1  jtc 	 * or list. check that we have not been given a bogus set of flags
    521  1.1  jtc 	 * for the operation mode.
    522  1.1  jtc 	 */
    523  1.1  jtc 	if (ISLIST(flg)) {
    524  1.1  jtc 		act = LIST;
    525  1.1  jtc 		bflg = flg & BDLIST;
    526  1.1  jtc 	} else if (ISEXTRACT(flg)) {
    527  1.1  jtc 		act = EXTRACT;
    528  1.1  jtc 		bflg = flg & BDEXTR;
    529  1.1  jtc 	} else if (ISARCHIVE(flg)) {
    530  1.1  jtc 		act = ARCHIVE;
    531  1.1  jtc 		bflg = flg & BDARCH;
    532  1.1  jtc 	} else if (ISAPPND(flg)) {
    533  1.1  jtc 		act = APPND;
    534  1.1  jtc 		bflg = flg & BDARCH;
    535  1.1  jtc 	} else if (ISCOPY(flg)) {
    536  1.1  jtc 		act = COPY;
    537  1.1  jtc 		bflg = flg & BDCOPY;
    538  1.1  jtc 	} else
    539  1.1  jtc 		pax_usage();
    540  1.1  jtc 	if (bflg) {
    541  1.1  jtc 		printflg(flg);
    542  1.1  jtc 		pax_usage();
    543  1.1  jtc 	}
    544  1.1  jtc 
    545  1.1  jtc 	/*
    546  1.1  jtc 	 * if we are writing (ARCHIVE) we use the default format if the user
    547  1.1  jtc 	 * did not specify a format. when we write during an APPEND, we will
    548  1.1  jtc 	 * adopt the format of the existing archive if none was supplied.
    549  1.1  jtc 	 */
    550  1.1  jtc 	if (!(flg & XF) && (act == ARCHIVE))
    551  1.1  jtc 		frmt = &(fsub[DEFLT]);
    552  1.1  jtc 
    553  1.1  jtc 	/*
    554  1.1  jtc 	 * process the args as they are interpreted by the operation mode
    555  1.1  jtc 	 */
    556  1.1  jtc 	switch (act) {
    557  1.1  jtc 	case LIST:
    558  1.1  jtc 	case EXTRACT:
    559  1.1  jtc 		for (; optind < argc; optind++)
    560  1.1  jtc 			if (pat_add(argv[optind]) < 0)
    561  1.1  jtc 				pax_usage();
    562  1.1  jtc 		break;
    563  1.1  jtc 	case COPY:
    564  1.1  jtc 		if (optind >= argc) {
    565  1.1  jtc 			warn(0, "Destination directory was not supplied");
    566  1.1  jtc 			pax_usage();
    567  1.1  jtc 		}
    568  1.1  jtc 		--argc;
    569  1.1  jtc 		dirptr = argv[argc];
    570  1.1  jtc 		/* FALL THROUGH */
    571  1.1  jtc 	case ARCHIVE:
    572  1.1  jtc 	case APPND:
    573  1.1  jtc 		for (; optind < argc; optind++)
    574  1.1  jtc 			if (ftree_add(argv[optind]) < 0)
    575  1.1  jtc 				pax_usage();
    576  1.1  jtc 		/*
    577  1.1  jtc 		 * no read errors allowed on updates/append operation!
    578  1.1  jtc 		 */
    579  1.1  jtc 		maxflt = 0;
    580  1.1  jtc 		break;
    581  1.1  jtc 	}
    582  1.1  jtc }
    583  1.1  jtc 
    584  1.1  jtc 
    585  1.1  jtc /*
    586  1.1  jtc  * tar_options()
    587  1.1  jtc  *	look at the user specified flags. set globals as required and check if
    588  1.1  jtc  *	the user specified a legal set of flags. If not, complain and exit
    589  1.1  jtc  */
    590  1.1  jtc 
    591  1.1  jtc #if __STDC__
    592  1.1  jtc static void
    593  1.7  tls tar_options(int argc, char **argv)
    594  1.1  jtc #else
    595  1.1  jtc static void
    596  1.1  jtc tar_options(argc, argv)
    597  1.7  tls 	int argc;
    598  1.7  tls 	char **argv;
    599  1.1  jtc #endif
    600  1.1  jtc {
    601  1.7  tls 	int c;
    602  1.1  jtc 	int fstdin = 0;
    603  1.1  jtc 
    604  1.1  jtc 	/*
    605  1.1  jtc 	 * process option flags
    606  1.1  jtc 	 */
    607  1.6  mrg 	while ((c = getoldopt(argc, argv, "b:cef:moprutvwxzBHLPXZ014578"))
    608  1.4  jtc 	    != EOF)  {
    609  1.4  jtc 		switch(c) {
    610  1.1  jtc 		case 'b':
    611  1.1  jtc 			/*
    612  1.1  jtc 			 * specify blocksize
    613  1.1  jtc 			 */
    614  1.4  jtc 			if ((wrblksz = (int)str_offt(optarg)) <= 0) {
    615  1.4  jtc 				warn(1, "Invalid block size %s", optarg);
    616  1.1  jtc 				tar_usage();
    617  1.1  jtc 			}
    618  1.1  jtc 			break;
    619  1.1  jtc 		case 'c':
    620  1.1  jtc 			/*
    621  1.1  jtc 			 * create an archive
    622  1.1  jtc 			 */
    623  1.1  jtc 			act = ARCHIVE;
    624  1.1  jtc 			break;
    625  1.1  jtc 		case 'e':
    626  1.1  jtc 			/*
    627  1.1  jtc 			 * stop after first error
    628  1.1  jtc 			 */
    629  1.1  jtc 			maxflt = 0;
    630  1.1  jtc 			break;
    631  1.1  jtc 		case 'f':
    632  1.1  jtc 			/*
    633  1.1  jtc 			 * filename where the archive is stored
    634  1.1  jtc 			 */
    635  1.4  jtc 			if ((optarg[0] == '-') && (optarg[1]== '\0')) {
    636  1.1  jtc 				/*
    637  1.1  jtc 				 * treat a - as stdin
    638  1.1  jtc 				 */
    639  1.4  jtc 				fstdin = 1;
    640  1.1  jtc 				arcname = (char *)0;
    641  1.1  jtc 				break;
    642  1.1  jtc 			}
    643  1.1  jtc 			fstdin = 0;
    644  1.4  jtc 			arcname = optarg;
    645  1.1  jtc 			break;
    646  1.1  jtc 		case 'm':
    647  1.1  jtc 			/*
    648  1.1  jtc 			 * do not preserve modification time
    649  1.1  jtc 			 */
    650  1.1  jtc 			pmtime = 0;
    651  1.1  jtc 			break;
    652  1.1  jtc 		case 'o':
    653  1.1  jtc 			if (opt_add("write_opt=nodir") < 0)
    654  1.1  jtc 				tar_usage();
    655  1.1  jtc 			break;
    656  1.1  jtc 		case 'p':
    657  1.1  jtc 			/*
    658  1.1  jtc 			 * preserve user id, group id, file
    659  1.1  jtc 			 * mode, access/modification times
    660  1.1  jtc 			 */
    661  1.1  jtc 			pids = 1;
    662  1.1  jtc 			pmode = 1;
    663  1.1  jtc 			patime = 1;
    664  1.1  jtc 			pmtime = 1;
    665  1.1  jtc 			break;
    666  1.1  jtc 		case 'r':
    667  1.1  jtc 		case 'u':
    668  1.1  jtc 			/*
    669  1.1  jtc 			 * append to the archive
    670  1.1  jtc 			 */
    671  1.1  jtc 			act = APPND;
    672  1.1  jtc 			break;
    673  1.1  jtc 		case 't':
    674  1.1  jtc 			/*
    675  1.1  jtc 			 * list contents of the tape
    676  1.1  jtc 			 */
    677  1.1  jtc 			act = LIST;
    678  1.1  jtc 			break;
    679  1.1  jtc 		case 'v':
    680  1.1  jtc 			/*
    681  1.1  jtc 			 * verbose operation mode
    682  1.1  jtc 			 */
    683  1.1  jtc 			vflag = 1;
    684  1.1  jtc 			break;
    685  1.1  jtc 		case 'w':
    686  1.1  jtc 			/*
    687  1.1  jtc 			 * interactive file rename
    688  1.1  jtc 			 */
    689  1.1  jtc 			iflag = 1;
    690  1.1  jtc 			break;
    691  1.1  jtc 		case 'x':
    692  1.1  jtc 			/*
    693  1.1  jtc 			 * write an archive
    694  1.1  jtc 			 */
    695  1.1  jtc 			act = EXTRACT;
    696  1.1  jtc 			break;
    697  1.6  mrg 		case 'z':
    698  1.6  mrg 			/*
    699  1.6  mrg 			 * use gzip.  Non standard option.
    700  1.6  mrg 			 */
    701  1.6  mrg 			zflag = 1;
    702  1.6  mrg 			gzip_program = GZIP_CMD;
    703  1.6  mrg 			break;
    704  1.1  jtc 		case 'B':
    705  1.1  jtc 			/*
    706  1.1  jtc 			 * Nothing to do here, this is pax default
    707  1.1  jtc 			 */
    708  1.1  jtc 			break;
    709  1.1  jtc 		case 'H':
    710  1.1  jtc 			/*
    711  1.1  jtc 			 * follow command line symlinks only
    712  1.1  jtc 			 */
    713  1.1  jtc 			Hflag = 1;
    714  1.1  jtc 			break;
    715  1.1  jtc 		case 'L':
    716  1.1  jtc 			/*
    717  1.1  jtc 			 * follow symlinks
    718  1.1  jtc 			 */
    719  1.1  jtc 			Lflag = 1;
    720  1.1  jtc 			break;
    721  1.1  jtc 		case 'P':
    722  1.1  jtc 			/*
    723  1.1  jtc 			 * do not follow symlinks
    724  1.1  jtc 			 */
    725  1.1  jtc 			Lflag = 0;
    726  1.1  jtc 			break;
    727  1.1  jtc 		case 'X':
    728  1.1  jtc 			/*
    729  1.1  jtc 			 * do not pass over mount points in the file system
    730  1.1  jtc 			 */
    731  1.1  jtc 			Xflag = 1;
    732  1.6  mrg 			break;
    733  1.6  mrg 		case 'Z':
    734  1.6  mrg 			/*
    735  1.6  mrg 			 * use compress.
    736  1.6  mrg 			 */
    737  1.6  mrg 			zflag = 1;
    738  1.6  mrg 			gzip_program = COMPRESS_CMD;
    739  1.1  jtc 			break;
    740  1.1  jtc 		case '0':
    741  1.1  jtc 			arcname = DEV_0;
    742  1.1  jtc 			break;
    743  1.1  jtc 		case '1':
    744  1.1  jtc 			arcname = DEV_1;
    745  1.1  jtc 			break;
    746  1.1  jtc 		case '4':
    747  1.1  jtc 			arcname = DEV_4;
    748  1.1  jtc 			break;
    749  1.1  jtc 		case '5':
    750  1.1  jtc 			arcname = DEV_5;
    751  1.1  jtc 			break;
    752  1.1  jtc 		case '7':
    753  1.1  jtc 			arcname = DEV_7;
    754  1.1  jtc 			break;
    755  1.1  jtc 		case '8':
    756  1.1  jtc 			arcname = DEV_8;
    757  1.1  jtc 			break;
    758  1.1  jtc 		default:
    759  1.1  jtc 			tar_usage();
    760  1.1  jtc 			break;
    761  1.1  jtc 		}
    762  1.1  jtc 	}
    763  1.4  jtc 	argc -= optind;
    764  1.4  jtc 	argv += optind;
    765  1.1  jtc 
    766  1.1  jtc 	/*
    767  1.1  jtc 	 * if we are writing (ARCHIVE) specify tar, otherwise run like pax
    768  1.1  jtc 	 */
    769  1.1  jtc 	if (act == ARCHIVE)
    770  1.1  jtc 		frmt = &(fsub[F_TAR]);
    771  1.1  jtc 
    772  1.1  jtc 	/*
    773  1.1  jtc 	 * process the args as they are interpreted by the operation mode
    774  1.1  jtc 	 */
    775  1.1  jtc 	switch (act) {
    776  1.1  jtc 	case LIST:
    777  1.1  jtc 	case EXTRACT:
    778  1.1  jtc 	default:
    779  1.1  jtc 		while (*argv != (char *)NULL)
    780  1.1  jtc 			if (pat_add(*argv++) < 0)
    781  1.1  jtc 				tar_usage();
    782  1.1  jtc 		break;
    783  1.1  jtc 	case ARCHIVE:
    784  1.1  jtc 	case APPND:
    785  1.1  jtc 		while (*argv != (char *)NULL)
    786  1.1  jtc 			if (ftree_add(*argv++) < 0)
    787  1.1  jtc 				tar_usage();
    788  1.1  jtc 		/*
    789  1.1  jtc 		 * no read errors allowed on updates/append operation!
    790  1.1  jtc 		 */
    791  1.1  jtc 		maxflt = 0;
    792  1.1  jtc 		break;
    793  1.1  jtc 	}
    794  1.1  jtc 	if (!fstdin && ((arcname == (char *)NULL) || (*arcname == '\0'))) {
    795  1.1  jtc 		arcname = getenv("TAPE");
    796  1.1  jtc 		if ((arcname == (char *)NULL) || (*arcname == '\0'))
    797  1.1  jtc 			arcname = DEV_8;
    798  1.1  jtc 	}
    799  1.1  jtc }
    800  1.1  jtc 
    801  1.1  jtc #ifdef notdef
    802  1.1  jtc /*
    803  1.1  jtc  * cpio_options()
    804  1.1  jtc  *	look at the user specified flags. set globals as required and check if
    805  1.1  jtc  *	the user specified a legal set of flags. If not, complain and exit
    806  1.1  jtc  */
    807  1.1  jtc 
    808  1.1  jtc #if __STDC__
    809  1.1  jtc static void
    810  1.7  tls cpio_options(int argc, char **argv)
    811  1.1  jtc #else
    812  1.1  jtc static void
    813  1.1  jtc cpio_options(argc, argv)
    814  1.7  tls 	int argc;
    815  1.7  tls 	char **argv;
    816  1.1  jtc #endif
    817  1.1  jtc {
    818  1.1  jtc }
    819  1.1  jtc #endif
    820  1.1  jtc 
    821  1.1  jtc /*
    822  1.1  jtc  * printflg()
    823  1.1  jtc  *	print out those invalid flag sets found to the user
    824  1.1  jtc  */
    825  1.1  jtc 
    826  1.1  jtc #if __STDC__
    827  1.1  jtc static void
    828  1.1  jtc printflg(unsigned int flg)
    829  1.1  jtc #else
    830  1.1  jtc static void
    831  1.1  jtc printflg(flg)
    832  1.1  jtc 	unsigned int flg;
    833  1.1  jtc #endif
    834  1.1  jtc {
    835  1.1  jtc 	int nxt;
    836  1.1  jtc 	int pos = 0;
    837  1.1  jtc 
    838  1.1  jtc 	(void)fprintf(stderr,"%s: Invalid combination of options:", argv0);
    839  1.1  jtc 	while (nxt = ffs(flg)) {
    840  1.1  jtc 		flg = flg >> nxt;
    841  1.1  jtc 		pos += nxt;
    842  1.1  jtc 		(void)fprintf(stderr, " -%c", flgch[pos-1]);
    843  1.1  jtc 	}
    844  1.1  jtc 	(void)putc('\n', stderr);
    845  1.1  jtc }
    846  1.1  jtc 
    847  1.1  jtc /*
    848  1.1  jtc  * c_frmt()
    849  1.1  jtc  *	comparison routine used by bsearch to find the format specified
    850  1.1  jtc  *	by the user
    851  1.1  jtc  */
    852  1.1  jtc 
    853  1.1  jtc #if __STDC__
    854  1.1  jtc static int
    855  1.1  jtc c_frmt(const void *a, const void *b)
    856  1.1  jtc #else
    857  1.1  jtc static int
    858  1.1  jtc c_frmt(a, b)
    859  1.1  jtc         void *a;
    860  1.1  jtc         void *b;
    861  1.1  jtc #endif
    862  1.1  jtc {
    863  1.1  jtc         return(strcmp(((FSUB *)a)->name, ((FSUB *)b)->name));
    864  1.1  jtc }
    865  1.1  jtc 
    866  1.1  jtc /*
    867  1.1  jtc  * opt_next()
    868  1.1  jtc  *	called by format specific options routines to get each format specific
    869  1.1  jtc  *	flag and value specified with -o
    870  1.1  jtc  * Return:
    871  1.1  jtc  *	pointer to next OPLIST entry or NULL (end of list).
    872  1.1  jtc  */
    873  1.1  jtc 
    874  1.1  jtc #if __STDC__
    875  1.1  jtc OPLIST *
    876  1.1  jtc opt_next(void)
    877  1.1  jtc #else
    878  1.1  jtc OPLIST *
    879  1.1  jtc opt_next()
    880  1.1  jtc #endif
    881  1.1  jtc {
    882  1.1  jtc 	OPLIST *opt;
    883  1.1  jtc 
    884  1.1  jtc 	if ((opt = ophead) != NULL)
    885  1.1  jtc 		ophead = ophead->fow;
    886  1.1  jtc 	return(opt);
    887  1.1  jtc }
    888  1.1  jtc 
    889  1.1  jtc /*
    890  1.1  jtc  * bad_opt()
    891  1.1  jtc  *	generic routine used to complain about a format specific options
    892  1.1  jtc  *	when the format does not support options.
    893  1.1  jtc  */
    894  1.1  jtc 
    895  1.1  jtc #if __STDC__
    896  1.1  jtc int
    897  1.1  jtc bad_opt(void)
    898  1.1  jtc #else
    899  1.1  jtc int
    900  1.1  jtc bad_opt()
    901  1.1  jtc #endif
    902  1.1  jtc {
    903  1.7  tls 	OPLIST *opt;
    904  1.1  jtc 
    905  1.1  jtc 	if (ophead == NULL)
    906  1.1  jtc 		return(0);
    907  1.1  jtc 	/*
    908  1.1  jtc 	 * print all we were given
    909  1.1  jtc 	 */
    910  1.1  jtc 	warn(1,"These format options are not supported");
    911  1.1  jtc 	while ((opt = opt_next()) != NULL)
    912  1.1  jtc 		(void)fprintf(stderr, "\t%s = %s\n", opt->name, opt->value);
    913  1.1  jtc 	pax_usage();
    914  1.1  jtc 	return(0);
    915  1.1  jtc }
    916  1.1  jtc 
    917  1.1  jtc /*
    918  1.1  jtc  * opt_add()
    919  1.1  jtc  *	breaks the value supplied to -o into a option name and value. options
    920  1.1  jtc  *	are given to -o in the form -o name-value,name=value
    921  1.1  jtc  *	mulltiple -o may be specified.
    922  1.1  jtc  * Return:
    923  1.1  jtc  *	0 if format in name=value format, -1 if -o is passed junk
    924  1.1  jtc  */
    925  1.1  jtc 
    926  1.1  jtc #if __STDC__
    927  1.1  jtc int
    928  1.7  tls opt_add(char *str)
    929  1.1  jtc #else
    930  1.1  jtc int
    931  1.1  jtc opt_add(str)
    932  1.7  tls 	char *str;
    933  1.1  jtc #endif
    934  1.1  jtc {
    935  1.7  tls 	OPLIST *opt;
    936  1.7  tls 	char *frpt;
    937  1.7  tls 	char *pt;
    938  1.7  tls 	char *endpt;
    939  1.1  jtc 
    940  1.1  jtc 	if ((str == NULL) || (*str == '\0')) {
    941  1.1  jtc 		warn(0, "Invalid option name");
    942  1.1  jtc 		return(-1);
    943  1.1  jtc 	}
    944  1.1  jtc 	frpt = endpt = str;
    945  1.1  jtc 
    946  1.1  jtc 	/*
    947  1.1  jtc 	 * break into name and values pieces and stuff each one into a
    948  1.1  jtc 	 * OPLIST structure. When we know the format, the format specific
    949  1.1  jtc 	 * option function will go through this list
    950  1.1  jtc 	 */
    951  1.1  jtc 	while ((frpt != NULL) && (*frpt != '\0')) {
    952  1.1  jtc 		if ((endpt = strchr(frpt, ',')) != NULL)
    953  1.1  jtc 			*endpt = '\0';
    954  1.1  jtc 		if ((pt = strchr(frpt, '=')) == NULL) {
    955  1.1  jtc 			warn(0, "Invalid options format");
    956  1.1  jtc 			return(-1);
    957  1.1  jtc 		}
    958  1.1  jtc 		if ((opt = (OPLIST *)malloc(sizeof(OPLIST))) == NULL) {
    959  1.1  jtc 			warn(0, "Unable to allocate space for option list");
    960  1.1  jtc 			return(-1);
    961  1.1  jtc 		}
    962  1.1  jtc 		*pt++ = '\0';
    963  1.1  jtc 		opt->name = frpt;
    964  1.1  jtc 		opt->value = pt;
    965  1.1  jtc 		opt->fow = NULL;
    966  1.1  jtc 		if (endpt != NULL)
    967  1.1  jtc 			frpt = endpt + 1;
    968  1.1  jtc 		else
    969  1.1  jtc 			frpt = NULL;
    970  1.1  jtc 		if (ophead == NULL) {
    971  1.1  jtc 			optail = ophead = opt;
    972  1.1  jtc 			continue;
    973  1.1  jtc 		}
    974  1.1  jtc 		optail->fow = opt;
    975  1.1  jtc 		optail = opt;
    976  1.1  jtc 	}
    977  1.1  jtc 	return(0);
    978  1.1  jtc }
    979  1.1  jtc 
    980  1.1  jtc /*
    981  1.1  jtc  * str_offt()
    982  1.1  jtc  *	Convert an expression of the following forms to an off_t > 0.
    983  1.1  jtc  * 	1) A positive decimal number.
    984  1.1  jtc  *	2) A positive decimal number followed by a b (mult by 512).
    985  1.1  jtc  *	3) A positive decimal number followed by a k (mult by 1024).
    986  1.1  jtc  *	4) A positive decimal number followed by a m (mult by 512).
    987  1.1  jtc  *	5) A positive decimal number followed by a w (mult by sizeof int)
    988  1.1  jtc  *	6) Two or more positive decimal numbers (with/without k,b or w).
    989  1.1  jtc  *	   seperated by x (also * for backwards compatibility), specifying
    990  1.1  jtc  *	   the product of the indicated values.
    991  1.1  jtc  * Return:
    992  1.1  jtc  *	0 for an error, a positive value o.w.
    993  1.1  jtc  */
    994  1.1  jtc 
    995  1.1  jtc #if __STDC__
    996  1.1  jtc static off_t
    997  1.1  jtc str_offt(char *val)
    998  1.1  jtc #else
    999  1.1  jtc static off_t
   1000  1.1  jtc str_offt(val)
   1001  1.1  jtc 	char *val;
   1002  1.1  jtc #endif
   1003  1.1  jtc {
   1004  1.1  jtc 	char *expr;
   1005  1.1  jtc 	off_t num, t;
   1006  1.1  jtc 
   1007  1.1  jtc #	ifdef NET2_STAT
   1008  1.1  jtc 	num = strtol(val, &expr, 0);
   1009  1.1  jtc 	if ((num == LONG_MAX) || (num <= 0) || (expr == val))
   1010  1.1  jtc #	else
   1011  1.1  jtc 	num = strtoq(val, &expr, 0);
   1012  1.1  jtc 	if ((num == QUAD_MAX) || (num <= 0) || (expr == val))
   1013  1.1  jtc #	endif
   1014  1.1  jtc 		return(0);
   1015  1.1  jtc 
   1016  1.1  jtc 	switch(*expr) {
   1017  1.1  jtc 	case 'b':
   1018  1.1  jtc 		t = num;
   1019  1.1  jtc 		num *= 512;
   1020  1.1  jtc 		if (t > num)
   1021  1.1  jtc 			return(0);
   1022  1.1  jtc 		++expr;
   1023  1.1  jtc 		break;
   1024  1.1  jtc 	case 'k':
   1025  1.1  jtc 		t = num;
   1026  1.1  jtc 		num *= 1024;
   1027  1.1  jtc 		if (t > num)
   1028  1.1  jtc 			return(0);
   1029  1.1  jtc 		++expr;
   1030  1.1  jtc 		break;
   1031  1.1  jtc 	case 'm':
   1032  1.1  jtc 		t = num;
   1033  1.1  jtc 		num *= 1048576;
   1034  1.1  jtc 		if (t > num)
   1035  1.1  jtc 			return(0);
   1036  1.1  jtc 		++expr;
   1037  1.1  jtc 		break;
   1038  1.1  jtc 	case 'w':
   1039  1.1  jtc 		t = num;
   1040  1.1  jtc 		num *= sizeof(int);
   1041  1.1  jtc 		if (t > num)
   1042  1.1  jtc 			return(0);
   1043  1.1  jtc 		++expr;
   1044  1.1  jtc 		break;
   1045  1.1  jtc 	}
   1046  1.1  jtc 
   1047  1.1  jtc 	switch(*expr) {
   1048  1.1  jtc 		case '\0':
   1049  1.1  jtc 			break;
   1050  1.1  jtc 		case '*':
   1051  1.1  jtc 		case 'x':
   1052  1.1  jtc 			t = num;
   1053  1.1  jtc 			num *= str_offt(expr + 1);
   1054  1.1  jtc 			if (t > num)
   1055  1.1  jtc 				return(0);
   1056  1.1  jtc 			break;
   1057  1.1  jtc 		default:
   1058  1.1  jtc 			return(0);
   1059  1.1  jtc 	}
   1060  1.1  jtc 	return(num);
   1061  1.1  jtc }
   1062  1.1  jtc 
   1063  1.1  jtc /*
   1064  1.1  jtc  * no_op()
   1065  1.1  jtc  *	for those option functions where the archive format has nothing to do.
   1066  1.1  jtc  * Return:
   1067  1.1  jtc  *	0
   1068  1.1  jtc  */
   1069  1.1  jtc 
   1070  1.1  jtc #if __STDC__
   1071  1.1  jtc static int
   1072  1.1  jtc no_op(void)
   1073  1.1  jtc #else
   1074  1.1  jtc static int
   1075  1.1  jtc no_op()
   1076  1.1  jtc #endif
   1077  1.1  jtc {
   1078  1.1  jtc 	return(0);
   1079  1.1  jtc }
   1080  1.1  jtc 
   1081  1.1  jtc /*
   1082  1.1  jtc  * pax_usage()
   1083  1.1  jtc  *	print the usage summary to the user
   1084  1.1  jtc  */
   1085  1.1  jtc 
   1086  1.1  jtc #if __STDC__
   1087  1.1  jtc void
   1088  1.1  jtc pax_usage(void)
   1089  1.1  jtc #else
   1090  1.1  jtc void
   1091  1.1  jtc pax_usage()
   1092  1.1  jtc #endif
   1093  1.1  jtc {
   1094  1.1  jtc 	(void)fputs("usage: pax [-cdnv] [-E limit] [-f archive] ", stderr);
   1095  1.1  jtc 	(void)fputs("[-s replstr] ... [-U user] ...", stderr);
   1096  1.1  jtc 	(void)fputs("\n           [-G group] ... ", stderr);
   1097  1.1  jtc 	(void)fputs("[-T [from_date][,to_date]] ... ", stderr);
   1098  1.1  jtc 	(void)fputs("[pattern ...]\n", stderr);
   1099  1.1  jtc 	(void)fputs("       pax -r [-cdiknuvDYZ] [-E limit] ", stderr);
   1100  1.1  jtc 	(void)fputs("[-f archive] [-o options] ... \n", stderr);
   1101  1.1  jtc 	(void)fputs("           [-p string] ... [-s replstr] ... ", stderr);
   1102  1.1  jtc 	(void)fputs("[-U user] ... [-G group] ...\n           ", stderr);
   1103  1.1  jtc 	(void)fputs("[-T [from_date][,to_date]] ... ", stderr);
   1104  1.1  jtc 	(void)fputs(" [pattern ...]\n", stderr);
   1105  1.1  jtc 	(void)fputs("       pax -w [-dituvHLPX] [-b blocksize] ", stderr);
   1106  1.1  jtc 	(void)fputs("[ [-a] [-f archive] ] [-x format] \n", stderr);
   1107  1.1  jtc 	(void)fputs("           [-B bytes] [-s replstr] ... ", stderr);
   1108  1.1  jtc 	(void)fputs("[-o options] ... [-U user] ...", stderr);
   1109  1.1  jtc 	(void)fputs("\n           [-G group] ... ", stderr);
   1110  1.1  jtc 	(void)fputs("[-T [from_date][,to_date][/[c][m]]] ... ", stderr);
   1111  1.1  jtc 	(void)fputs("[file ...]\n", stderr);
   1112  1.1  jtc 	(void)fputs("       pax -r -w [-diklntuvDHLPXYZ] ", stderr);
   1113  1.1  jtc 	(void)fputs("[-p string] ... [-s replstr] ...", stderr);
   1114  1.1  jtc 	(void)fputs("\n           [-U user] ... [-G group] ... ", stderr);
   1115  1.1  jtc 	(void)fputs("[-T [from_date][,to_date][/[c][m]]] ... ", stderr);
   1116  1.1  jtc 	(void)fputs("\n           [file ...] directory\n", stderr);
   1117  1.1  jtc 	exit(1);
   1118  1.1  jtc }
   1119  1.1  jtc 
   1120  1.1  jtc /*
   1121  1.1  jtc  * tar_usage()
   1122  1.1  jtc  *	print the usage summary to the user
   1123  1.1  jtc  */
   1124  1.1  jtc 
   1125  1.1  jtc #if __STDC__
   1126  1.1  jtc void
   1127  1.1  jtc tar_usage(void)
   1128  1.1  jtc #else
   1129  1.1  jtc void
   1130  1.1  jtc tar_usage()
   1131  1.1  jtc #endif
   1132  1.1  jtc {
   1133  1.1  jtc 	(void)fputs("usage: tar -{txru}[cevfbmopwBHLPX014578] [tapefile] ",
   1134  1.1  jtc 		 stderr);
   1135  1.1  jtc 	(void)fputs("[blocksize] file1 file2...\n", stderr);
   1136  1.1  jtc 	exit(1);
   1137  1.1  jtc }
   1138  1.1  jtc 
   1139  1.1  jtc #ifdef notdef
   1140  1.1  jtc /*
   1141  1.1  jtc  * cpio_usage()
   1142  1.1  jtc  *	print the usage summary to the user
   1143  1.1  jtc  */
   1144  1.1  jtc 
   1145  1.1  jtc #if __STDC__
   1146  1.1  jtc void
   1147  1.1  jtc cpio_usage(void)
   1148  1.1  jtc #else
   1149  1.1  jtc void
   1150  1.1  jtc cpio_usage()
   1151  1.1  jtc #endif
   1152  1.1  jtc {
   1153  1.1  jtc 	exit(1);
   1154  1.1  jtc }
   1155  1.1  jtc #endif
   1156