From d2f953c9db3789406e0e9fe392aa75c406e55211 Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Sun, 28 Apr 2024 18:14:27 +0200 Subject: [PATCH] command: use const declaration for arrays --- lib/commands/toolcontext.h | 2 +- tools/command.c | 20 ++++++++++---------- tools/command.h | 8 ++++---- tools/lvmcmdline.c | 6 +++--- tools/man-generator.c | 20 ++++++++++---------- 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/commands/toolcontext.h b/lib/commands/toolcontext.h index cfe1de1aa..dec11ecbc 100644 --- a/lib/commands/toolcontext.h +++ b/lib/commands/toolcontext.h @@ -93,7 +93,7 @@ struct cmd_context { */ const char *cmd_line; const char *name; /* needed before cmd->command is set */ - struct command_name *cname; + const struct command_name *cname; struct command *command; int command_enum; /* duplicate from command->command_enum for lib code */ char **argv; diff --git a/tools/command.c b/tools/command.c index e484906fb..b1eb2be8a 100644 --- a/tools/command.c +++ b/tools/command.c @@ -39,7 +39,7 @@ struct cmd_name { /* create table of value names, e.g. String, and corresponding enum from vals.h */ -struct val_name val_names[VAL_COUNT + 1] = { +const struct val_name val_names[VAL_COUNT + 1] = { #define val(a, b, c, d) { # a, a, b, c, d }, #include "vals.h" #undef val @@ -55,7 +55,7 @@ struct opt_name opt_names[ARG_COUNT + 1] = { /* create table of lv property names, e.g. lv_is_foo, and corresponding enum from lv_props.h */ -struct lv_prop lv_props[LVP_COUNT + 1] = { +const struct lv_prop lv_props[LVP_COUNT + 1] = { #define lvp(a, b, c) { # a, a, b, c }, #include "lv_props.h" #undef lvp @@ -63,7 +63,7 @@ struct lv_prop lv_props[LVP_COUNT + 1] = { /* create table of lv type names, e.g. linear and corresponding enum from lv_types.h */ -struct lv_type lv_types[LVT_COUNT + 1] = { +const struct lv_type lv_types[LVT_COUNT + 1] = { #define lvt(a, b, c) { # a, a, b, c }, #include "lv_types.h" #undef lvt @@ -71,7 +71,7 @@ struct lv_type lv_types[LVT_COUNT + 1] = { /* create table of command IDs */ -struct cmd_name cmd_names[CMD_COUNT + 1] = { +const struct cmd_name cmd_names[CMD_COUNT + 1] = { #define cmd(a, b) { # a, a, # b }, #include "../include/cmds.h" #undef cmd @@ -356,7 +356,7 @@ static uint64_t _lv_to_bits(struct command *cmd, char *name) return lvt_bits; } -struct command_name *find_command_name(const char *name) +const struct command_name *find_command_name(const char *name) { static int _command_names_count = -1; int first = 0, last, middle; @@ -393,7 +393,7 @@ struct command_name *find_command_name(const char *name) return NULL; } -static struct command_name *_find_command_name(const char *name) +static const struct command_name *_find_command_name(const char *name) { if (!islower(name[0])) return NULL; /* Commands starts with lower-case */ @@ -1706,7 +1706,7 @@ static void _print_usage_def(struct command *cmd, int opt_enum, struct arg_def * void print_usage(struct command *cmd, int longhelp, int desc_first) { - struct command_name *cname = _find_command_name(cmd->name); + const struct command_name *cname = _find_command_name(cmd->name); int any_req = (cmd->cmd_flags & CMD_FLAG_ANY_REQUIRED_OPT) ? 1 : 0; int include_extents = 0; int ro, rp, oo, op, opt_enum, first; @@ -1936,7 +1936,7 @@ void print_usage(struct command *cmd, int longhelp, int desc_first) printf("\n"); } -void print_usage_common_lvm(struct command_name *cname, struct command *cmd) +void print_usage_common_lvm(const struct command_name *cname, struct command *cmd) { int oo, opt_enum; @@ -1981,7 +1981,7 @@ void print_usage_common_lvm(struct command_name *cname, struct command *cmd) printf("\n\n"); } -void print_usage_common_cmd(struct command_name *cname, struct command *cmd) +void print_usage_common_cmd(const struct command_name *cname, struct command *cmd) { int oo, opt_enum; int found_common_command = 0; @@ -2067,7 +2067,7 @@ void print_usage_common_cmd(struct command_name *cname, struct command *cmd) printf("\n\n"); } -void print_usage_notes(struct command_name *cname) +void print_usage_notes(const struct command_name *cname) { if (cname && command_has_alternate_extents(cname->name)) printf(" Special options for command:\n" diff --git a/tools/command.h b/tools/command.h index 185fdbdf1..6d65ba373 100644 --- a/tools/command.h +++ b/tools/command.h @@ -270,12 +270,12 @@ struct lv_type { int define_commands(struct cmd_context *cmdtool, const char *run_name); int command_id_to_enum(const char *str); void print_usage(struct command *cmd, int longhelp, int desc_first); -void print_usage_common_cmd(struct command_name *cname, struct command *cmd); -void print_usage_common_lvm(struct command_name *cname, struct command *cmd); -void print_usage_notes(struct command_name *cname); +void print_usage_common_cmd(const struct command_name *cname, struct command *cmd); +void print_usage_common_lvm(const struct command_name *cname, struct command *cmd); +void print_usage_notes(const struct command_name *cname); void factor_common_options(void); int command_has_alternate_extents(const char *name); void configure_command_option_values(const char *name); -struct command_name *find_command_name(const char *name); +const struct command_name *find_command_name(const char *name); #endif diff --git a/tools/lvmcmdline.c b/tools/lvmcmdline.c index 6ae82032d..dd2daeee1 100644 --- a/tools/lvmcmdline.c +++ b/tools/lvmcmdline.c @@ -1353,7 +1353,7 @@ int lvm_register_commands(struct cmd_context *cmd, const char *run_name) { int i; const char *last_name = NULL; - struct command_name *cname = NULL; + const struct command_name *cname = NULL; /* already initialized */ if (_cmdline.commands) @@ -2057,7 +2057,7 @@ static void _short_usage(const char *name) static int _usage(const char *name, int longhelp, int skip_notes) { - struct command_name *cname = find_command_name(name); + const struct command_name *cname = find_command_name(name); struct command *cmd = NULL; int show_full = longhelp; int i; @@ -2214,7 +2214,7 @@ static void _add_getopt_arg(int opt_enum, char **optstrp, struct option **longop static int _find_arg(const char *cmd_name, int goval) { - struct command_name *cname; + const struct command_name *cname; int arg_enum; int i; diff --git a/tools/man-generator.c b/tools/man-generator.c index efe2a56f7..dfb2a368f 100644 --- a/tools/man-generator.c +++ b/tools/man-generator.c @@ -127,7 +127,7 @@ static const char *_lvt_enum_to_name(int lvt_enum) * Otherwise, this function has to be updated in * sync with any string changes in vals.h */ -static void _print_val_man(struct command_name *cname, int opt_enum, int val_enum) +static void _print_val_man(const struct command_name *cname, int opt_enum, int val_enum) { const char *str; char *line; @@ -230,7 +230,7 @@ static void _print_val_man(struct command_name *cname, int opt_enum, int val_enu printf("\\fB%s\\fP", str); } -static void _print_def_man(struct command_name *cname, int opt_enum, struct arg_def *def, int usage, uint64_t *lv_type_bits) +static void _print_def_man(const struct command_name *cname, int opt_enum, struct arg_def *def, int usage, uint64_t *lv_type_bits) { int val_enum; int sep = 0; @@ -346,7 +346,7 @@ static const char *_man_long_opt_name(const char *cmdname, int opt_enum) static void _print_man_usage(char *lvmname, struct command *cmd) { - struct command_name *cname; + const struct command_name *cname; int any_req = (cmd->cmd_flags & CMD_FLAG_ANY_REQUIRED_OPT) ? 1 : 0; int sep, ro, rp, oo, op, opt_enum; int need_ro_indent_end = 0; @@ -709,7 +709,7 @@ out: static void _print_man_usage_common_lvm(struct command *cmd) { - struct command_name *cname; + const struct command_name *cname; int i, sep, oo, opt_enum; if (!(cname = _find_command_name(cmd->name))) @@ -793,7 +793,7 @@ static void _print_man_usage_common_lvm(struct command *cmd) static void _print_man_usage_common_cmd(struct command *cmd) { - struct command_name *cname; + const struct command_name *cname; int i, sep, oo, opt_enum; int found_common_command = 0; @@ -922,7 +922,7 @@ static void _print_man_usage_common_cmd(struct command *cmd) * "another line of text." */ -static void _print_man_option_desc(struct command_name *cname, int opt_enum) +static void _print_man_option_desc(const struct command_name *cname, int opt_enum) { const char *desc = opt_names[opt_enum].desc; char buf[DESC_LINE]; @@ -990,7 +990,7 @@ static void _print_man_option_desc(struct command_name *cname, int opt_enum) * Print a list of all options names for a given command name. */ -static void _print_man_all_options_list(struct command_name *cname) +static void _print_man_all_options_list(const struct command_name *cname) { int opt_enum, val_enum; int sep = 0; @@ -1047,7 +1047,7 @@ static void _print_man_all_options_list(struct command_name *cname) * All options used for a given command name, along with descriptions. */ -static void _print_man_all_options_desc(struct command_name *cname) +static void _print_man_all_options_desc(const struct command_name *cname) { int opt_enum, val_enum; int i; @@ -1112,7 +1112,7 @@ static void _print_man_all_options_desc(struct command_name *cname) } } -static void _print_man_all_positions_desc(struct command_name *cname) +static void _print_man_all_positions_desc(const struct command_name *cname) { struct command *cmd; int ci, rp, op; @@ -1352,7 +1352,7 @@ out_close: static int _print_man(char *name, char *des_file, int secondary) { - struct command_name *cname; + const struct command_name *cname; struct command *cmd, *prev_cmd = NULL; char *lvmname = name; int i;