diff --git a/tools/command.c b/tools/command.c index 21b58f103..3ad5b816d 100644 --- a/tools/command.c +++ b/tools/command.c @@ -48,7 +48,7 @@ static const struct val_name val_names[VAL_COUNT + 1] = { /* create table of option names, e.g. --foo, and corresponding enum from args.h */ static struct opt_name opt_names[ARG_COUNT + 1] = { -#define arg(a, b, c, d, e, f, g) { # a, a, b, "", "--" c, d, e, f, g }, +#define arg(a, b, c, d, e, f, g) { # a, b, a, "--" c, d, e, f, g }, #include "args.h" #undef arg }; @@ -211,12 +211,9 @@ static int _val_str_to_num(char *str) if ((new = strchr(name, '_'))) *new = '\0'; - for (i = 0; i < VAL_COUNT; i++) { - if (!val_names[i].name) - break; + for (i = 0; i < VAL_COUNT; ++i) if (!strncmp(name, val_names[i].name, strlen(val_names[i].name))) return val_names[i].val_enum; - } return 0; } diff --git a/tools/command.h b/tools/command.h index 6d65ba373..fc8d5dc18 100644 --- a/tools/command.h +++ b/tools/command.h @@ -227,11 +227,10 @@ struct command { /* see global opt_names[] */ struct opt_name { - const char *name; /* "foo_ARG" */ - uint16_t opt_enum; /* foo_ARG */ + const char name[27]; /* "foo_ARG" */ const char short_opt; /* -f */ - char _padding[5]; - const char *long_opt; /* --foo */ + uint16_t opt_enum; /* foo_ARG */ + const char long_opt[28]; /* --foo */ uint16_t val_enum; /* xyz_VAL when --foo takes a val like "--foo xyz" */ uint16_t flags; uint16_t prio; @@ -241,28 +240,28 @@ struct opt_name { /* see global val_names[] */ struct val_name { - const char *enum_name; /* "foo_VAL" */ + const char enum_name[30]; /* "foo_VAL" */ uint16_t val_enum; /* foo_VAL */ int (*fn) (struct cmd_context *cmd, struct arg_values *av); /* foo_arg() */ - const char *name; /* FooVal */ + const char name[32]; /* FooVal */ const char *usage; }; /* see global lv_props[] */ struct lv_prop { - const char *enum_name; /* "is_foo_LVP" */ + const char enum_name[30]; /* "is_foo_LVP" */ uint16_t lvp_enum; /* is_foo_LVP */ - const char *name; /* "lv_is_foo" */ + const char name[32]; /* "lv_is_foo" */ int (*fn) (struct cmd_context *cmd, struct logical_volume *lv); /* lv_is_foo() */ }; /* see global lv_types[] */ struct lv_type { - const char *enum_name; /* "foo_LVT" */ + const char enum_name[30]; /* "foo_LVT" */ uint16_t lvt_enum; /* foo_LVT */ - const char *name; /* "foo" */ + const char name[32]; /* "foo" */ int (*fn) (struct cmd_context *cmd, struct logical_volume *lv); /* lv_is_foo() */ }; diff --git a/tools/vals.h b/tools/vals.h index 8e1819f6f..bcd56fc70 100644 --- a/tools/vals.h +++ b/tools/vals.h @@ -146,5 +146,5 @@ val(dumptype_VAL, dumptype_arg, "DumpType", "headers|metadata|metadata_all|metad val(headings_VAL, headings_arg, "HeadingsType", "none|abbrev|full|0|1|2") /* this should always be last */ -val(VAL_COUNT, NULL, NULL, NULL) +val(VAL_COUNT, NULL, "", NULL)