From: Zdenek Kabelac Date: Sat, 11 May 2024 20:27:36 +0000 (+0200) Subject: command: better const usage for struct cmd_name X-Git-Tag: v2_03_24~38 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=433154fc8ad694eb64947328e0c606c7df90ac85;p=lvm2.git command: better const usage for struct cmd_name No need to store _CMD string - as it's not used anywhere. Use LVM_COMMAND_COUNT as end of array. --- diff --git a/tools/command.c b/tools/command.c index eb7c5993a..91b50b81a 100644 --- a/tools/command.c +++ b/tools/command.c @@ -32,9 +32,8 @@ /* see cmd_names[] below, one for each unique "ID" in command-lines.in */ struct cmd_name { - const char *enum_name; /* "foo_CMD" */ - int cmd_enum; /* foo_CMD */ - const char *name; /* "foo" from string after ID: */ + const char name[68]; /* "foo" from string after ID: */ + uint16_t cmd_enum; /* foo_CMD */ }; /* create table of value names, e.g. String, and corresponding enum from vals.h */ @@ -72,7 +71,7 @@ static const struct lv_type lv_types[LVT_COUNT + 1] = { /* create table of command IDs */ static const struct cmd_name cmd_names[CMD_COUNT + 1] = { -#define cmd(a, b) { # a, a, # b }, +#define cmd(a, b) { # b, a }, #include "../include/cmds.h" #undef cmd }; diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index ceced2379..35b368a1c 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -1380,7 +1380,7 @@ int lvm_register_commands(struct cmd_context *cmd, const char *run_name) /* Sort all commands by its name for quick binary search */ qsort(commands_idx, COMMAND_COUNT, sizeof(long), _command_name_compare); - for (i = 0; command_names[i].name; i++) + for (i = 0; i < LVM_COMMAND_COUNT; ++i) _set_valid_args_for_command_name(i); _cmdline.num_command_names = i; /* Also counted how many command entries we have */ @@ -2077,7 +2077,7 @@ static void _usage_all(void) { int i; - for (i = 0; command_names[i].name; i++) + for (i = 0; i < LVM_COMMAND_COUNT; ++i) _usage(command_names[i].name, 1, 1); print_usage_notes(NULL);