From: Junio C Hamano Date: Tue, 8 Apr 2014 19:00:16 +0000 (-0700) Subject: Merge branch 'mr/opt-set-ptr' X-Git-Tag: v2.0.0-rc0~16 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/b389e04031ffe4c725161a082ff748bd33688641?ds=inline;hp=-c Merge branch 'mr/opt-set-ptr' OPT_SET_PTR() implementation was broken on IL32P64 platforms; it turns out that the macro is not used by any real user. * mr/opt-set-ptr: parse-options: remove unused OPT_SET_PTR parse-options: add cast to correct pointer type to OPT_SET_PTR MSVC: fix t0040-parse-options crash --- b389e04031ffe4c725161a082ff748bd33688641 diff --combined parse-options.c index c81d3a0655,245bf3d6f3..b536896f26 --- a/parse-options.c +++ b/parse-options.c @@@ -127,10 -127,6 +127,6 @@@ static int get_value(struct parse_opt_c *(int *)opt->value = opt->defval; return 0; - case OPTION_SET_PTR: - *(void **)opt->value = unset ? NULL : (void *)opt->defval; - return 0; - case OPTION_STRING: if (unset) *(const char **)opt->value = NULL; @@@ -223,10 -219,13 +219,10 @@@ static int parse_long_opt(struct parse_ const struct option *options) { const struct option *all_opts = options; - const char *arg_end = strchr(arg, '='); + const char *arg_end = strchrnul(arg, '='); const struct option *abbrev_option = NULL, *ambiguous_option = NULL; int abbrev_flags = 0, ambiguous_flags = 0; - if (!arg_end) - arg_end = arg + strlen(arg); - for (; options->type != OPTION_END; options++) { const char *rest, *long_name = options->long_name; int flags = 0, opt_flags = 0; @@@ -367,7 -366,6 +363,6 @@@ static void parse_options_check(const s case OPTION_BIT: case OPTION_NEGBIT: case OPTION_SET_INT: - case OPTION_SET_PTR: case OPTION_NUMBER: if ((opts->flags & PARSE_OPT_OPTARG) || !(opts->flags & PARSE_OPT_NOARG)) @@@ -375,9 -373,6 +370,9 @@@ default: ; /* ok. (usually accepts an argument) */ } + if (opts->argh && + strcspn(opts->argh, " _") != strlen(opts->argh)) + err |= optbug(opts, "multi-word argh should use dash to separate words"); } if (err) exit(128); diff --combined parse-options.h index 8fa02dc9a9,dd46f88422..3189676695 --- a/parse-options.h +++ b/parse-options.h @@@ -12,7 -12,6 +12,6 @@@ enum parse_opt_type OPTION_NEGBIT, OPTION_COUNTUP, OPTION_SET_INT, - OPTION_SET_PTR, OPTION_CMDMODE, /* options with arguments (usually) */ OPTION_STRING, @@@ -96,7 -95,7 +95,7 @@@ typedef int parse_opt_ll_cb(struct pars * * `defval`:: * default value to fill (*->value) with for PARSE_OPT_OPTARG. - * OPTION_{BIT,SET_INT,SET_PTR} store the {mask,integer,pointer} to put in + * OPTION_{BIT,SET_INT} store the {mask,integer,pointer} to put in * the value when met. * CALLBACKS can use it like they want. */ @@@ -128,8 -127,6 +127,6 @@@ struct option #define OPT_BOOL(s, l, v, h) OPT_SET_INT(s, l, v, h, 1) #define OPT_HIDDEN_BOOL(s, l, v, h) { OPTION_SET_INT, (s), (l), (v), NULL, \ (h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1} - #define OPT_SET_PTR(s, l, v, h, p) { OPTION_SET_PTR, (s), (l), (v), NULL, \ - (h), PARSE_OPT_NOARG, NULL, (p) } #define OPT_CMDMODE(s, l, v, h, i) { OPTION_CMDMODE, (s), (l), (v), NULL, \ (h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, (i) } #define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h) } @@@ -143,7 -140,7 +140,7 @@@ { OPTION_CALLBACK, (s), (l), (v), N_("time"),(h), 0, \ parse_opt_approxidate_cb } #define OPT_EXPIRY_DATE(s, l, v, h) \ - { OPTION_CALLBACK, (s), (l), (v), N_("expiry date"),(h), 0, \ + { OPTION_CALLBACK, (s), (l), (v), N_("expiry-date"),(h), 0, \ parse_opt_expiry_date_cb } #define OPT_CALLBACK(s, l, v, a, h, f) \ { OPTION_CALLBACK, (s), (l), (v), (a), (h), 0, (f) }