1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

lvmcmdline: use strcut as const

Constity members in cmdline_context, would be nice, to replace
this static struct with couple function calls.

Also replace some 'while' loops with for loops, so code
is more readable.
This commit is contained in:
Zdenek Kabelac 2024-05-12 12:04:54 +02:00
parent f854e3a722
commit 82617852a4
3 changed files with 17 additions and 21 deletions

View File

@ -50,9 +50,9 @@ static char *_list_cmds(const char *text, int state)
len = strlen(text);
}
while (i < _cmdline->num_command_names)
if (!strncmp(text, _cmdline->command_names[i++].name, len))
return strdup(_cmdline->command_names[i - 1].name);
for (;i < _cmdline->num_command_names;++i)
if (!strncmp(text, _cmdline->command_names[i].name, len))
return strdup(_cmdline->command_names[i].name);
return NULL;
}
@ -62,8 +62,8 @@ static char *_list_args(const char *text, int state)
{
static int match_no = 0;
static size_t len = 0;
static struct command_name *cname;
static struct command_name_args *cna;
static const struct command_name *cname;
static const struct command_name_args *cna;
/* Initialise if this is a new completion attempt */
if (!state) {
@ -102,16 +102,14 @@ static char *_list_args(const char *text, int state)
/* Short form arguments */
if (len < 3) {
while (match_no < cna->num_args) {
for (;match_no < cna->num_args; ++match_no) {
char s[3];
char c;
if (!(c = (_cmdline->opt_names +
cna->valid_args[match_no++])->short_opt))
continue;
sprintf(s, "-%c", c);
if (!strncmp(text, s, len))
return strdup(s);
char c = (_cmdline->opt_names + cna->valid_args[match_no])->short_opt;
if (c) {
sprintf(s, "-%c", c);
if (!strncmp(text, s, len))
return strdup(s);
}
}
}
@ -119,10 +117,8 @@ static char *_list_args(const char *text, int state)
if (match_no < cna->num_args)
match_no = cna->num_args;
while (match_no - cna->num_args < cna->num_args) {
const char *l;
l = (_cmdline->opt_names +
cna->valid_args[match_no++ - cna->num_args])->long_opt;
for (;match_no - cna->num_args < cna->num_args; ++match_no) {
const char *l = (_cmdline->opt_names + cna->valid_args[match_no - cna->num_args])->long_opt;
if (*(l + 2) && !strncmp(text, l, len))
return strdup(l);
}

View File

@ -22,8 +22,8 @@ struct cmdline_context {
const struct opt_name *opt_names;
struct command *commands;
int num_commands;
struct command_name *command_names;
struct command_name_args *command_names_args;
const struct command_name *command_names;
const struct command_name_args *command_names_args;
int num_command_names;
};

View File

@ -2692,7 +2692,7 @@ static void _display_help(void)
log_error(" ");
for (i = 0; i < _cmdline.num_command_names; i++) {
struct command_name *cname = _cmdline.command_names + i;
const struct command_name *cname = _cmdline.command_names + i;
log_error("%-16.16s%s", cname->name, cname->desc);
}