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:
parent
f854e3a722
commit
82617852a4
26
tools/lvm.c
26
tools/lvm.c
@ -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,27 +102,23 @@ 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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Long form arguments */
|
||||
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);
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user