From: Sven Verdoolaege Date: Wed, 20 Feb 2013 15:44:13 +0000 (+0100) Subject: argument parsing: handle --help option in order X-Git-Tag: isl-0.12~200 X-Git-Url: https://repo.or.cz/w/isl.git/commitdiff_plain/0524f69bc444d33a2efa36233c48daa9ba23a8bf argument parsing: handle --help option in order In the original code, we would first scan for any --help option before processing any other options. Now we first consider the options before --help. If any of these options change the defaults for any other options, then those changed defaults will be reflected in the --help output. Signed-off-by: Sven Verdoolaege --- diff --git a/isl_arg.c b/isl_arg.c index f2025eeb..78f12b46 100644 --- a/isl_arg.c +++ b/isl_arg.c @@ -1144,21 +1144,17 @@ static int next_arg(struct isl_arg *arg, int a) return -1; } -/* Unless ISL_ARG_SKIP_HELP is set, check if any of the arguments is +/* Unless ISL_ARG_SKIP_HELP is set, check if "arg" is * equal to "--help" and if so call print_help_and_exit. */ -static void check_help(struct isl_args *args, int argc, char **argv, void *opt, +static void check_help(struct isl_args *args, char *arg, char *prog, void *opt, unsigned flags) { - int i; - if (ISL_FL_ISSET(flags, ISL_ARG_SKIP_HELP)) return; - for (i = 1; i < argc; ++i) { - if (strcmp(argv[i], "--help") == 0) - print_help_and_exit(args->args, argv[0], opt); - } + if (strcmp(arg, "--help") == 0) + print_help_and_exit(args->args, prog, opt); } int isl_args_parse(struct isl_args *args, int argc, char **argv, void *opt, @@ -1171,8 +1167,6 @@ int isl_args_parse(struct isl_args *args, int argc, char **argv, void *opt, n = n_arg(args->args); - check_help(args, argc, argv, opt, flags); - for (i = 1; i < argc; ++i) { if ((strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-V") == 0) && any_version(args->args)) @@ -1198,6 +1192,7 @@ int isl_args_parse(struct isl_args *args, int argc, char **argv, void *opt, ++skip; continue; } + check_help(args, argv[1 + skip], argv[0], opt, flags); parsed = parse_option(args->args, &argv[1 + skip], NULL, opt); if (parsed) argc = drop_argument(argc, argv, 1 + skip, parsed);