コード例 #1
0
ファイル: ubimirror.c プロジェクト: OpenNoah/mtd-utils
static int
parse_opt(int argc, char **argv, myargs *args)
{
	while (1) {
		int key;

		key = getopt_long(argc, argv, "cs:?V", long_options, NULL);
		if (key == -1)
			break;

		switch (key) {
			case 'c':
				err_msg("%s", copyright);
				ABORT_ARGP;
				break;
			case 's':
				args->side = get_update_side(optarg);
				if (args->side < 0) {
					err_msg("Unsupported seqnum: %s.\n"
						"Supported seqnums are '0' "
						"and '1'\n", optarg);
					ERR_ARGP;
				}
				break;
			case '?': /* help */
				err_msg("Usage: ubimirror [OPTION...] "
					"<source> <destination>\n");
				err_msg("%s", doc);
				err_msg("%s", optionsstr);
				err_msg("\nReport bugs to %s\n",
					PACKAGE_BUGREPORT);
				exit(0);
				break;
			case 'V':
				err_msg("%s", PROGRAM_VERSION);
				exit(0);
				break;
			default:
				err_msg("%s", usage);
				exit(-1);
			}
	}

	while (optind < argc) {
		/* only two entries allowed */
		if (args->vol_no >= VOL_ARGS_MAX) {
			err_msg("%s", usage);
			ERR_ARGP;
		}
		args->vol[(args->vol_no)++] = argv[optind++];
	}

	return 0;
}
static int
parse_opt(int argc, char **argv, myargs *args)
{
	int rc = 0;

	while (1) {
		int key;

		key = getopt_long(argc, argv, "clbxs:i:o:?V",
				  long_options, NULL);
		if (key == -1)
			break;

		switch (key) {
			case 'c':
				err_msg("%s\n", copyright);
				ABORT_ARGP;
				break;
			case 'l':
				args->action = ACT_LIST;
				break;
			case 'b':
				args->both = 1;
				break;
			case 'x':
				args->x86 = 1;
				break;
			case 's':
				args->side = get_update_side(optarg);
				if (args->side < 0) {
					err_msg("Unsupported seqnum: %d.\n"
						"Supported seqnums are "
						"'0' and '1'\n",
						args->side, optarg);
					ERR_ARGP;
				}
				break;
			case 'i':
				args->file_in = optarg;
				break;
			case 'o':
				args->file_out = optarg;
				break;
			case '?': /* help */
				err_msg("Usage: pddcustomize [OPTION...] "
					"[key=value] [...]");
				err_msg("%s", doc);
				err_msg("%s", optionsstr);
				err_msg("\nReport bugs to %s",
					PACKAGE_BUGREPORT);
				exit(0);
				break;
			case 'V':
				err_msg("%s", PROGRAM_VERSION);
				exit(0);
				break;
			default:
				err_msg("%s", usage);
				exit(-1);
		}
	}

	if (optind < argc) {
		rc = extract_pair(args->env_in, argv[optind++]);
		if (rc != 0)
			ERR_ARGP;
	}

	return 0;
}