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

📄 options.c

📁 Rsync 3.0.5 source code
💻 C
📖 第 1 页 / 共 5 页
字号:
				op->val = (op - long_options) + OPT_REFUSED_BASE;				found_match = 1;				/* These flags are set to let us easily check				 * an implied option later in the code. */				switch (*shortname) {				case 'r': case 'd': case 'l': case 'p':				case 't': case 'g': case 'o': case 'D':					refused_archive_part = op->val;					break;				case 'z':					refused_compress = op->val;					break;				case '\0':					if (wildmatch("delete", op->longName))						refused_delete = op->val;					else if (wildmatch("delete-before", op->longName))						refused_delete_before = op->val;					else if (wildmatch("delete-during", op->longName))						refused_delete_during = op->val;					else if (wildmatch("partial", op->longName))						refused_partial = op->val;					else if (wildmatch("progress", op->longName))						refused_progress = op->val;					else if (wildmatch("inplace", op->longName))						refused_inplace = op->val;					else if (wildmatch("no-iconv", op->longName))						refused_no_iconv = op->val;					break;				}				if (!is_wild)					break;			}		}		if (!found_match) {			rprintf(FLOG, "No match for refuse-options string \"%s\"\n",				bp);		}		if (!cp)			break;		*cp = ' ';		bp = cp + 1;	}}static int count_args(const char **argv){	int i = 0;	if (argv) {		while (argv[i] != NULL)			i++;	}	return i;}static OFF_T parse_size_arg(char **size_arg, char def_suf){	int reps, mult, make_compatible = 0;	const char *arg;	OFF_T size = 1;	for (arg = *size_arg; isDigit(arg); arg++) {}	if (*arg == '.')		for (arg++; isDigit(arg); arg++) {}	switch (*arg && *arg != '+' && *arg != '-' ? *arg++ : def_suf) {	case 'b': case 'B':		reps = 0;		break;	case 'k': case 'K':		reps = 1;		break;	case 'm': case 'M':		reps = 2;		break;	case 'g': case 'G':		reps = 3;		break;	default:		return -1;	}	if (*arg == 'b' || *arg == 'B')		mult = 1000, make_compatible = 1, arg++;	else if (!*arg || *arg == '+' || *arg == '-')		mult = 1024;	else if (strncasecmp(arg, "ib", 2) == 0)		mult = 1024, arg += 2;	else		return -1;	while (reps--)		size *= mult;	size *= atof(*size_arg);	if ((*arg == '+' || *arg == '-') && arg[1] == '1')		size += atoi(arg), make_compatible = 1, arg += 2;	if (*arg)		return -1;	if (size > 0 && make_compatible) {		/* We convert this manually because we may need %lld precision,		 * and that's not a portable sprintf() escape. */		char buf[128], *s = buf + sizeof buf - 1;		OFF_T num = size;		*s = '\0';		while (num) {			*--s = (char)(num % 10) + '0';			num /= 10;		}		if (!(*size_arg = strdup(s)))			out_of_memory("parse_size_arg");	}	return size;}static void create_refuse_error(int which){	/* The "which" value is the index + OPT_REFUSED_BASE. */	struct poptOption *op = &long_options[which - OPT_REFUSED_BASE];	int n = snprintf(err_buf, sizeof err_buf,			 "The server is configured to refuse --%s\n",			 op->longName) - 1;	if (op->shortName) {		snprintf(err_buf + n, sizeof err_buf - n,			 " (-%c)\n", op->shortName);	}}/** * Process command line arguments.  Called on both local and remote. * * @retval 1 if all options are OK; with globals set to appropriate * values * * @retval 0 on error, with err_buf containing an explanation **/int parse_arguments(int *argc_p, const char ***argv_p){	static poptContext pc;	char *ref = lp_refuse_options(module_id);	const char *arg, **argv = *argv_p;	int argc = *argc_p;	int opt;	if (ref && *ref)		set_refuse_options(ref);	if (am_daemon) {		set_refuse_options("log-file*");#ifdef ICONV_OPTION		if (!*lp_charset(module_id))			set_refuse_options("iconv");#endif	}#ifdef ICONV_OPTION	if (!am_daemon && !protect_args && (arg = getenv("RSYNC_ICONV")) != NULL && *arg)		iconv_opt = strdup(arg);#endif	/* TODO: Call poptReadDefaultConfig; handle errors. */	/* The context leaks in case of an error, but if there's a	 * problem we always exit anyhow. */	if (pc)		poptFreeContext(pc);	pc = poptGetContext(RSYNC_NAME, argc, argv, long_options, 0);	if (!am_server)		poptReadDefaultConfig(pc, 0);	while ((opt = poptGetNextOpt(pc)) != -1) {		/* most options are handled automatically by popt;		 * only special cases are returned and listed here. */		switch (opt) {		case OPT_VERSION:			print_rsync_version(FINFO);			exit_cleanup(0);		case OPT_SERVER:			if (!am_server) {				/* Disable popt aliases on the server side and				 * then start parsing the options again. */				poptFreeContext(pc);				pc = poptGetContext(RSYNC_NAME, argc, argv,						    long_options, 0);				am_server = 1;			}#ifdef ICONV_OPTION			iconv_opt = NULL;#endif			break;		case OPT_SENDER:			if (!am_server) {				usage(FERROR);				exit_cleanup(RERR_SYNTAX);			}			am_sender = 1;			break;		case OPT_DAEMON:			if (am_daemon) {				strlcpy(err_buf,					"Attempt to hack rsync thwarted!\n",					sizeof err_buf);				return 0;			}#ifdef ICONV_OPTION			iconv_opt = NULL;#endif			poptFreeContext(pc);			pc = poptGetContext(RSYNC_NAME, argc, argv,					    long_daemon_options, 0);			while ((opt = poptGetNextOpt(pc)) != -1) {				switch (opt) {				case 'h':					daemon_usage(FINFO);					exit_cleanup(0);				case 'v':					verbose++;					break;				default:					rprintf(FERROR,					    "rsync: %s: %s (in daemon mode)\n",					    poptBadOption(pc, POPT_BADOPTION_NOALIAS),					    poptStrerror(opt));					goto daemon_error;				}			}			if (tmpdir && strlen(tmpdir) >= MAXPATHLEN - 10) {				snprintf(err_buf, sizeof err_buf,					 "the --temp-dir path is WAY too long.\n");				return 0;			}			if (!daemon_opt) {				rprintf(FERROR, "Daemon option(s) used without --daemon.\n");			    daemon_error:				rprintf(FERROR,				    "(Type \"rsync --daemon --help\" for assistance with daemon mode.)\n");				exit_cleanup(RERR_SYNTAX);			}			*argv_p = argv = poptGetArgs(pc);			*argc_p = argc = count_args(argv);			am_starting_up = 0;			daemon_opt = 0;			am_daemon = 1;			return 1;		case OPT_MODIFY_WINDOW:			/* The value has already been set by popt, but			 * we need to remember that we're using a			 * non-default setting. */			modify_window_set = 1;			break;		case OPT_FILTER:			parse_rule(&filter_list, poptGetOptArg(pc), 0, 0);			break;		case OPT_EXCLUDE:			parse_rule(&filter_list, poptGetOptArg(pc),				   0, XFLG_OLD_PREFIXES);			break;		case OPT_INCLUDE:			parse_rule(&filter_list, poptGetOptArg(pc),				   MATCHFLG_INCLUDE, XFLG_OLD_PREFIXES);			break;		case OPT_EXCLUDE_FROM:		case OPT_INCLUDE_FROM:			arg = poptGetOptArg(pc);			if (sanitize_paths)				arg = sanitize_path(NULL, arg, NULL, 0, SP_DEFAULT);			if (daemon_filter_list.head) {				int rej;				char *dir, *cp = strdup(arg);				if (!cp)					out_of_memory("parse_arguments");				if (!*cp)					goto options_rejected;				dir = cp + (*cp == '/' ? module_dirlen : 0);				clean_fname(dir, CFN_COLLAPSE_DOT_DOT_DIRS);				rej = check_filter(&daemon_filter_list, FLOG, dir, 0) < 0;				free(cp);				if (rej)					goto options_rejected;			}			parse_filter_file(&filter_list, arg,				opt == OPT_INCLUDE_FROM ? MATCHFLG_INCLUDE : 0,				XFLG_FATAL_ERRORS | XFLG_OLD_PREFIXES);			break;		case 'a':			if (refused_archive_part) {				create_refuse_error(refused_archive_part);				return 0;			}			if (!recurse) /* preserve recurse == 2 */				recurse = 1;#ifdef SUPPORT_LINKS			preserve_links = 1;#endif			preserve_perms = 1;			preserve_times = 2;			preserve_gid = 1;			preserve_uid = 1;			preserve_devices = 1;			preserve_specials = 1;			break;		case 'D':			preserve_devices = preserve_specials = 1;			break;		case OPT_NO_D:			preserve_devices = preserve_specials = 0;			break;		case 'h':			human_readable++;			break;		case 'H':			preserve_hard_links++;			break;		case 'i':			itemize_changes++;			break;		case 'v':			verbose++;			break;		case 'q':			quiet++;			break;		case 'x':			one_file_system++;			break;		case 'F':			switch (++F_option_cnt) {			case 1:				parse_rule(&filter_list,": /.rsync-filter",0,0);				break;			case 2:				parse_rule(&filter_list,"- .rsync-filter",0,0);				break;			}			break;		case 'P':			if (refused_partial || refused_progress) {				create_refuse_error(refused_partial				    ? refused_partial : refused_progress);				return 0;			}			do_progress = 1;			keep_partial = 1;			break;		case 'z':			if (def_compress_level < Z_DEFAULT_COMPRESSION			 || def_compress_level > Z_BEST_COMPRESSION) {				snprintf(err_buf, sizeof err_buf,					"--compress-level value is invalid: %d\n",					def_compress_level);				return 0;			}			do_compression = def_compress_level != Z_NO_COMPRESSION;

⌨️ 快捷键说明

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