⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 options.c

📁 早期freebsd实现
💻 C
📖 第 1 页 / 共 2 页
字号:
 *	the user specified a legal set of flags. If not, complain and exit */#if __STDC__static voidtar_options(register int argc, register char **argv)#elsestatic voidtar_options(argc, argv)	register int argc;	register char **argv;#endif{	register char *cp;	int fstdin = 0;	if (argc < 2)		tar_usage();	/*	 * process option flags	 */	++argv;	for (cp = *argv++; *cp != '\0'; ++cp) {		switch (*cp) {		case '-':			/*			 * skip over -			 */			break;		case 'b':			/*			 * specify blocksize			 */			if (*argv == (char *)NULL) {				warn(1,"blocksize must be specified with 'b'");				tar_usage();			}			if ((wrblksz = (int)str_offt(*argv)) <= 0) {				warn(1, "Invalid block size %s", *argv);				tar_usage();			}			++argv;			break;		case 'c':			/*			 * create an archive			 */			act = ARCHIVE;			break;		case 'e':			/*			 * stop after first error			 */			maxflt = 0;			break;		case 'f':			/*			 * filename where the archive is stored			 */			if (*argv == (char *)NULL) {				warn(1, "filename must be specified with 'f'");				tar_usage();			}			if ((argv[0][0] == '-') && (argv[0][1]== '\0')) {				/*				 * treat a - as stdin				 */				++argv;				++fstdin;				arcname = (char *)0;				break;			}			fstdin = 0;			arcname = *argv++;			break;		case 'm':			/*			 * do not preserve modification time			 */			pmtime = 0;			break;		case 'o':			if (opt_add("write_opt=nodir") < 0)				tar_usage();			break;		case 'p':			/*			 * preserve user id, group id, file			 * mode, access/modification times			 */			pids = 1;			pmode = 1;			patime = 1;			pmtime = 1;			break;		case 'r':		case 'u':			/*			 * append to the archive			 */			act = APPND;			break;		case 't':			/*			 * list contents of the tape			 */			act = LIST;			break;		case 'v':			/*			 * verbose operation mode			 */			vflag = 1;			break;		case 'w':			/*			 * interactive file rename			 */			iflag = 1;			break;		case 'x':			/*			 * write an archive			 */			act = EXTRACT;			break;		case 'B':			/*			 * Nothing to do here, this is pax default			 */			break;		case 'H':			/*			 * follow command line symlinks only			 */			Hflag = 1;			break;		case 'L':			/*			 * follow symlinks			 */			Lflag = 1;			break;		case 'P':			/*			 * do not follow symlinks			 */			Lflag = 0;			break;		case 'X':			/*			 * do not pass over mount points in the file system			 */			Xflag = 1;			break;		case '0':			arcname = DEV_0;			break;		case '1':			arcname = DEV_1;			break;		case '4':			arcname = DEV_4;			break;		case '5':			arcname = DEV_5;			break;		case '7':			arcname = DEV_7;			break;		case '8':			arcname = DEV_8;			break;		default:			tar_usage();			break;		}	}	/*	 * if we are writing (ARCHIVE) specify tar, otherwise run like pax	 */	if (act == ARCHIVE)		frmt = &(fsub[F_TAR]);	/*	 * process the args as they are interpreted by the operation mode	 */	switch (act) {	case LIST:	case EXTRACT:	default:		while (*argv != (char *)NULL)			if (pat_add(*argv++) < 0)				tar_usage();		break;	case ARCHIVE:	case APPND:		while (*argv != (char *)NULL)			if (ftree_add(*argv++) < 0)				tar_usage();		/*		 * no read errors allowed on updates/append operation!		 */		maxflt = 0;		break;	}	if (!fstdin && ((arcname == (char *)NULL) || (*arcname == '\0'))) {		arcname = getenv("TAPE");		if ((arcname == (char *)NULL) || (*arcname == '\0'))			arcname = DEV_8;	}}#ifdef notdef/* * cpio_options() *	look at the user specified flags. set globals as required and check if *	the user specified a legal set of flags. If not, complain and exit */#if __STDC__static voidcpio_options(register int argc, register char **argv)#elsestatic voidcpio_options(argc, argv)	register int argc;	register char **argv;#endif{}#endif/* * printflg() *	print out those invalid flag sets found to the user */#if __STDC__static voidprintflg(unsigned int flg)#elsestatic voidprintflg(flg)	unsigned int flg;#endif{	int nxt;	int pos = 0;	(void)fprintf(stderr,"%s: Invalid combination of options:", argv0);	while (nxt = ffs(flg)) {		flg = flg >> nxt;		pos += nxt;		(void)fprintf(stderr, " -%c", flgch[pos-1]);	}	(void)putc('\n', stderr);}/* * c_frmt() *	comparison routine used by bsearch to find the format specified *	by the user */#if __STDC__static intc_frmt(const void *a, const void *b)#elsestatic intc_frmt(a, b)        void *a;        void *b;#endif{        return(strcmp(((FSUB *)a)->name, ((FSUB *)b)->name));}/* * opt_next() *	called by format specific options routines to get each format specific *	flag and value specified with -o * Return: *	pointer to next OPLIST entry or NULL (end of list). */#if __STDC__OPLIST *opt_next(void)#elseOPLIST *opt_next()#endif{	OPLIST *opt;	if ((opt = ophead) != NULL)		ophead = ophead->fow;	return(opt);}/* * bad_opt() *	generic routine used to complain about a format specific options *	when the format does not support options. */#if __STDC__intbad_opt(void)#elseintbad_opt()#endif{	register OPLIST *opt;	if (ophead == NULL)		return(0);	/*	 * print all we were given	 */	warn(1,"These format options are not supported");	while ((opt = opt_next()) != NULL)		(void)fprintf(stderr, "\t%s = %s\n", opt->name, opt->value);	pax_usage();	return(0);}/* * opt_add() *	breaks the value supplied to -o into a option name and value. options *	are given to -o in the form -o name-value,name=value *	mulltiple -o may be specified. * Return: *	0 if format in name=value format, -1 if -o is passed junk */#if __STDC__intopt_add(register char *str)#elseintopt_add(str)	register char *str;#endif{	register OPLIST *opt;	register char *frpt;	register char *pt;	register char *endpt;	if ((str == NULL) || (*str == '\0')) {		warn(0, "Invalid option name");		return(-1);	}	frpt = endpt = str;	/*	 * break into name and values pieces and stuff each one into a	 * OPLIST structure. When we know the format, the format specific	 * option function will go through this list	 */	while ((frpt != NULL) && (*frpt != '\0')) {		if ((endpt = strchr(frpt, ',')) != NULL)			*endpt = '\0';		if ((pt = strchr(frpt, '=')) == NULL) {			warn(0, "Invalid options format");			return(-1);		}		if ((opt = (OPLIST *)malloc(sizeof(OPLIST))) == NULL) {			warn(0, "Unable to allocate space for option list");			return(-1);		}		*pt++ = '\0';		opt->name = frpt;		opt->value = pt;		opt->fow = NULL;		if (endpt != NULL)			frpt = endpt + 1;		else			frpt = NULL;		if (ophead == NULL) {			optail = ophead = opt;			continue;		}		optail->fow = opt;		optail = opt;	}	return(0);}/* * str_offt() *	Convert an expression of the following forms to an off_t > 0. * 	1) A positive decimal number. *	2) A positive decimal number followed by a b (mult by 512). *	3) A positive decimal number followed by a k (mult by 1024). *	4) A positive decimal number followed by a m (mult by 512). *	5) A positive decimal number followed by a w (mult by sizeof int) *	6) Two or more positive decimal numbers (with/without k,b or w). *	   seperated by x (also * for backwards compatibility), specifying *	   the product of the indicated values. * Return: *	0 for an error, a positive value o.w. */#if __STDC__static off_tstr_offt(char *val)#elsestatic off_tstr_offt(val)	char *val;#endif{	char *expr;	off_t num, t;#	ifdef NET2_STAT	num = strtol(val, &expr, 0);	if ((num == LONG_MAX) || (num <= 0) || (expr == val))#	else	num = strtoq(val, &expr, 0);	if ((num == QUAD_MAX) || (num <= 0) || (expr == val))#	endif		return(0);	switch(*expr) {	case 'b':		t = num;		num *= 512;		if (t > num)			return(0);		++expr;		break;	case 'k':		t = num;		num *= 1024;		if (t > num)			return(0);		++expr;		break;	case 'm':		t = num;		num *= 1048576;		if (t > num)			return(0);		++expr;		break;	case 'w':		t = num;		num *= sizeof(int);		if (t > num)			return(0);		++expr;		break;	}	switch(*expr) {		case '\0':			break;		case '*':		case 'x':			t = num;			num *= str_offt(expr + 1);			if (t > num)				return(0);			break;		default:			return(0);	}	return(num);}/* * no_op() *	for those option functions where the archive format has nothing to do. * Return: *	0 */#if __STDC__static intno_op(void)#elsestatic intno_op()#endif{	return(0);}/* * pax_usage() *	print the usage summary to the user */#if __STDC__voidpax_usage(void)#elsevoidpax_usage()#endif{	(void)fputs("usage: pax [-cdnv] [-E limit] [-f archive] ", stderr);	(void)fputs("[-s replstr] ... [-U user] ...", stderr);	(void)fputs("\n           [-G group] ... ", stderr);	(void)fputs("[-T [from_date][,to_date]] ... ", stderr);	(void)fputs("[pattern ...]\n", stderr);	(void)fputs("       pax -r [-cdiknuvDYZ] [-E limit] ", stderr);	(void)fputs("[-f archive] [-o options] ... \n", stderr);	(void)fputs("           [-p string] ... [-s replstr] ... ", stderr);	(void)fputs("[-U user] ... [-G group] ...\n           ", stderr);	(void)fputs("[-T [from_date][,to_date]] ... ", stderr);	(void)fputs(" [pattern ...]\n", stderr);	(void)fputs("       pax -w [-dituvHLPX] [-b blocksize] ", stderr);	(void)fputs("[ [-a] [-f archive] ] [-x format] \n", stderr);	(void)fputs("           [-B bytes] [-s replstr] ... ", stderr);	(void)fputs("[-o options] ... [-U user] ...", stderr);	(void)fputs("\n           [-G group] ... ", stderr);	(void)fputs("[-T [from_date][,to_date][/[c][m]]] ... ", stderr);	(void)fputs("[file ...]\n", stderr);	(void)fputs("       pax -r -w [-diklntuvDHLPXYZ] ", stderr);	(void)fputs("[-p string] ... [-s replstr] ...", stderr);	(void)fputs("\n           [-U user] ... [-G group] ... ", stderr);	(void)fputs("[-T [from_date][,to_date][/[c][m]]] ... ", stderr);	(void)fputs("\n           [file ...] directory\n", stderr);	exit(1);}/* * tar_usage() *	print the usage summary to the user */#if __STDC__voidtar_usage(void)#elsevoidtar_usage()#endif{	(void)fputs("usage: tar -{txru}[cevfbmopwBHLPX014578] [tapefile] ",		 stderr);	(void)fputs("[blocksize] file1 file2...\n", stderr);	exit(1);}#ifdef notdef/* * cpio_usage() *	print the usage summary to the user */#if __STDC__voidcpio_usage(void)#elsevoidcpio_usage()#endif{	exit(1);}#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -