]> sourceware.org Git - lvm2.git/commitdiff
command: better const usage for struct cmd_name
authorZdenek Kabelac <zkabelac@redhat.com>
Sat, 11 May 2024 20:27:36 +0000 (22:27 +0200)
committerZdenek Kabelac <zkabelac@redhat.com>
Sun, 12 May 2024 21:53:19 +0000 (23:53 +0200)
No need to store _CMD string - as it's not used anywhere.
Use LVM_COMMAND_COUNT as end of array.

tools/command.c
tools/lvmcmdline.c

index eb7c5993a85ffc3b9f52913831ff652f761e42f9..91b50b81a1818bb54f85d8384ed22345cd305cc7 100644 (file)
@@ -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
 };
index ceced23792ff0a540cf85c3ea843c2dac675e059..35b368a1cae5e6070964b56ee02dffe9897661fe 100644 (file)
@@ -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);
This page took 0.040533 seconds and 5 git commands to generate.