1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-30 17:18:21 +03:00

command: use const declaration for arrays

This commit is contained in:
Zdenek Kabelac 2024-04-28 18:14:27 +02:00
parent 063910c54b
commit d2f953c9db
5 changed files with 28 additions and 28 deletions

View File

@ -93,7 +93,7 @@ struct cmd_context {
*/ */
const char *cmd_line; const char *cmd_line;
const char *name; /* needed before cmd->command is set */ const char *name; /* needed before cmd->command is set */
struct command_name *cname; const struct command_name *cname;
struct command *command; struct command *command;
int command_enum; /* duplicate from command->command_enum for lib code */ int command_enum; /* duplicate from command->command_enum for lib code */
char **argv; char **argv;

View File

@ -39,7 +39,7 @@ struct cmd_name {
/* create table of value names, e.g. String, and corresponding enum from vals.h */ /* 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 }, #define val(a, b, c, d) { # a, a, b, c, d },
#include "vals.h" #include "vals.h"
#undef val #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 */ /* 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 }, #define lvp(a, b, c) { # a, a, b, c },
#include "lv_props.h" #include "lv_props.h"
#undef lvp #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 */ /* 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 }, #define lvt(a, b, c) { # a, a, b, c },
#include "lv_types.h" #include "lv_types.h"
#undef lvt #undef lvt
@ -71,7 +71,7 @@ struct lv_type lv_types[LVT_COUNT + 1] = {
/* create table of command IDs */ /* 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 }, #define cmd(a, b) { # a, a, # b },
#include "../include/cmds.h" #include "../include/cmds.h"
#undef cmd #undef cmd
@ -356,7 +356,7 @@ static uint64_t _lv_to_bits(struct command *cmd, char *name)
return lvt_bits; 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; static int _command_names_count = -1;
int first = 0, last, middle; int first = 0, last, middle;
@ -393,7 +393,7 @@ struct command_name *find_command_name(const char *name)
return NULL; 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])) if (!islower(name[0]))
return NULL; /* Commands starts with lower-case */ 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) 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 any_req = (cmd->cmd_flags & CMD_FLAG_ANY_REQUIRED_OPT) ? 1 : 0;
int include_extents = 0; int include_extents = 0;
int ro, rp, oo, op, opt_enum, first; 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"); 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; int oo, opt_enum;
@ -1981,7 +1981,7 @@ void print_usage_common_lvm(struct command_name *cname, struct command *cmd)
printf("\n\n"); 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 oo, opt_enum;
int found_common_command = 0; int found_common_command = 0;
@ -2067,7 +2067,7 @@ void print_usage_common_cmd(struct command_name *cname, struct command *cmd)
printf("\n\n"); 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)) if (cname && command_has_alternate_extents(cname->name))
printf(" Special options for command:\n" printf(" Special options for command:\n"

View File

@ -270,12 +270,12 @@ struct lv_type {
int define_commands(struct cmd_context *cmdtool, const char *run_name); int define_commands(struct cmd_context *cmdtool, const char *run_name);
int command_id_to_enum(const char *str); int command_id_to_enum(const char *str);
void print_usage(struct command *cmd, int longhelp, int desc_first); 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_cmd(const struct command_name *cname, struct command *cmd);
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);
void print_usage_notes(struct command_name *cname); void print_usage_notes(const struct command_name *cname);
void factor_common_options(void); void factor_common_options(void);
int command_has_alternate_extents(const char *name); int command_has_alternate_extents(const char *name);
void configure_command_option_values(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 #endif

View File

@ -1353,7 +1353,7 @@ int lvm_register_commands(struct cmd_context *cmd, const char *run_name)
{ {
int i; int i;
const char *last_name = NULL; const char *last_name = NULL;
struct command_name *cname = NULL; const struct command_name *cname = NULL;
/* already initialized */ /* already initialized */
if (_cmdline.commands) 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) 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; struct command *cmd = NULL;
int show_full = longhelp; int show_full = longhelp;
int i; 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) static int _find_arg(const char *cmd_name, int goval)
{ {
struct command_name *cname; const struct command_name *cname;
int arg_enum; int arg_enum;
int i; int i;

View File

@ -127,7 +127,7 @@ static const char *_lvt_enum_to_name(int lvt_enum)
* Otherwise, this function has to be updated in * Otherwise, this function has to be updated in
* sync with any string changes in vals.h * 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; const char *str;
char *line; 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); 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 val_enum;
int sep = 0; 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) 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 any_req = (cmd->cmd_flags & CMD_FLAG_ANY_REQUIRED_OPT) ? 1 : 0;
int sep, ro, rp, oo, op, opt_enum; int sep, ro, rp, oo, op, opt_enum;
int need_ro_indent_end = 0; int need_ro_indent_end = 0;
@ -709,7 +709,7 @@ out:
static void _print_man_usage_common_lvm(struct command *cmd) 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; int i, sep, oo, opt_enum;
if (!(cname = _find_command_name(cmd->name))) 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) 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 i, sep, oo, opt_enum;
int found_common_command = 0; int found_common_command = 0;
@ -922,7 +922,7 @@ static void _print_man_usage_common_cmd(struct command *cmd)
* "another line of text." * "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; const char *desc = opt_names[opt_enum].desc;
char buf[DESC_LINE]; 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. * 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 opt_enum, val_enum;
int sep = 0; 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. * 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 opt_enum, val_enum;
int i; 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; struct command *cmd;
int ci, rp, op; int ci, rp, op;
@ -1352,7 +1352,7 @@ out_close:
static int _print_man(char *name, char *des_file, int secondary) 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; struct command *cmd, *prev_cmd = NULL;
char *lvmname = name; char *lvmname = name;
int i; int i;