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
This commit is contained in:
commit
b389e04031
@ -160,10 +160,6 @@ There are some macros to easily define options:
|
|||||||
`int_var` is set to `integer` with `--option`, and
|
`int_var` is set to `integer` with `--option`, and
|
||||||
reset to zero with `--no-option`.
|
reset to zero with `--no-option`.
|
||||||
|
|
||||||
`OPT_SET_PTR(short, long, &ptr_var, description, ptr)`::
|
|
||||||
Introduce a boolean option.
|
|
||||||
If used, set `ptr_var` to `ptr`.
|
|
||||||
|
|
||||||
`OPT_STRING(short, long, &str_var, arg_str, description)`::
|
`OPT_STRING(short, long, &str_var, arg_str, description)`::
|
||||||
Introduce an option with string argument.
|
Introduce an option with string argument.
|
||||||
The string argument is put into `str_var`.
|
The string argument is put into `str_var`.
|
||||||
|
@ -127,10 +127,6 @@ static int get_value(struct parse_opt_ctx_t *p,
|
|||||||
*(int *)opt->value = opt->defval;
|
*(int *)opt->value = opt->defval;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
case OPTION_SET_PTR:
|
|
||||||
*(void **)opt->value = unset ? NULL : (void *)opt->defval;
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
case OPTION_STRING:
|
case OPTION_STRING:
|
||||||
if (unset)
|
if (unset)
|
||||||
*(const char **)opt->value = NULL;
|
*(const char **)opt->value = NULL;
|
||||||
@ -367,7 +363,6 @@ static void parse_options_check(const struct option *opts)
|
|||||||
case OPTION_BIT:
|
case OPTION_BIT:
|
||||||
case OPTION_NEGBIT:
|
case OPTION_NEGBIT:
|
||||||
case OPTION_SET_INT:
|
case OPTION_SET_INT:
|
||||||
case OPTION_SET_PTR:
|
|
||||||
case OPTION_NUMBER:
|
case OPTION_NUMBER:
|
||||||
if ((opts->flags & PARSE_OPT_OPTARG) ||
|
if ((opts->flags & PARSE_OPT_OPTARG) ||
|
||||||
!(opts->flags & PARSE_OPT_NOARG))
|
!(opts->flags & PARSE_OPT_NOARG))
|
||||||
|
@ -12,7 +12,6 @@ enum parse_opt_type {
|
|||||||
OPTION_NEGBIT,
|
OPTION_NEGBIT,
|
||||||
OPTION_COUNTUP,
|
OPTION_COUNTUP,
|
||||||
OPTION_SET_INT,
|
OPTION_SET_INT,
|
||||||
OPTION_SET_PTR,
|
|
||||||
OPTION_CMDMODE,
|
OPTION_CMDMODE,
|
||||||
/* options with arguments (usually) */
|
/* options with arguments (usually) */
|
||||||
OPTION_STRING,
|
OPTION_STRING,
|
||||||
@ -96,7 +95,7 @@ typedef int parse_opt_ll_cb(struct parse_opt_ctx_t *ctx,
|
|||||||
*
|
*
|
||||||
* `defval`::
|
* `defval`::
|
||||||
* default value to fill (*->value) with for PARSE_OPT_OPTARG.
|
* 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.
|
* the value when met.
|
||||||
* CALLBACKS can use it like they want.
|
* CALLBACKS can use it like they want.
|
||||||
*/
|
*/
|
||||||
@ -128,8 +127,6 @@ struct option {
|
|||||||
#define OPT_BOOL(s, l, v, h) OPT_SET_INT(s, l, v, h, 1)
|
#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, \
|
#define OPT_HIDDEN_BOOL(s, l, v, h) { OPTION_SET_INT, (s), (l), (v), NULL, \
|
||||||
(h), PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1}
|
(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, \
|
#define OPT_CMDMODE(s, l, v, h, i) { OPTION_CMDMODE, (s), (l), (v), NULL, \
|
||||||
(h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, (i) }
|
(h), PARSE_OPT_NOARG|PARSE_OPT_NONEG, NULL, (i) }
|
||||||
#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h) }
|
#define OPT_INTEGER(s, l, v, h) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h) }
|
||||||
|
@ -30,7 +30,6 @@ String options
|
|||||||
--string2 <str> get another string
|
--string2 <str> get another string
|
||||||
--st <st> get another string (pervert ordering)
|
--st <st> get another string (pervert ordering)
|
||||||
-o <str> get another string
|
-o <str> get another string
|
||||||
--default-string set string to default
|
|
||||||
--list <str> add str to list
|
--list <str> add str to list
|
||||||
|
|
||||||
Magic arguments
|
Magic arguments
|
||||||
@ -293,7 +292,7 @@ cat > expect <<EOF
|
|||||||
boolean: 0
|
boolean: 0
|
||||||
integer: 0
|
integer: 0
|
||||||
timestamp: 1
|
timestamp: 1
|
||||||
string: default
|
string: (not set)
|
||||||
abbrev: 7
|
abbrev: 7
|
||||||
verbose: 0
|
verbose: 0
|
||||||
quiet: yes
|
quiet: yes
|
||||||
@ -302,8 +301,8 @@ file: (not set)
|
|||||||
arg 00: foo
|
arg 00: foo
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
test_expect_success 'OPT_DATE() and OPT_SET_PTR() work' '
|
test_expect_success 'OPT_DATE() works' '
|
||||||
test-parse-options -t "1970-01-01 00:00:01 +0000" --default-string \
|
test-parse-options -t "1970-01-01 00:00:01 +0000" \
|
||||||
foo -q > output 2> output.err &&
|
foo -q > output 2> output.err &&
|
||||||
test_must_be_empty output.err &&
|
test_must_be_empty output.err &&
|
||||||
test_cmp expect output
|
test_cmp expect output
|
||||||
|
@ -59,8 +59,6 @@ int main(int argc, char **argv)
|
|||||||
OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"),
|
OPT_STRING(0, "st", &string, "st", "get another string (pervert ordering)"),
|
||||||
OPT_STRING('o', NULL, &string, "str", "get another string"),
|
OPT_STRING('o', NULL, &string, "str", "get another string"),
|
||||||
OPT_NOOP_NOARG(0, "obsolete"),
|
OPT_NOOP_NOARG(0, "obsolete"),
|
||||||
OPT_SET_PTR(0, "default-string", &string,
|
|
||||||
"set string to default", (unsigned long)"default"),
|
|
||||||
OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),
|
OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),
|
||||||
OPT_GROUP("Magic arguments"),
|
OPT_GROUP("Magic arguments"),
|
||||||
OPT_ARGUMENT("quux", "means --quux"),
|
OPT_ARGUMENT("quux", "means --quux"),
|
||||||
|
Loading…
Reference in New Issue
Block a user