1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-19 14:04:17 +03:00

lvm: fix shell completion

Previous commit 82617852a4d3c89b09124eddedcc2c1859b9d50e
introduce bug in complession - as the rl_completion_matches()
needs to always advance to next element where the index
is held in static variable.

Add comment about this usage.

(cherry picked from commit 73298635b9db2c2a11bc4cc291b15d0f21907598)
(cherry picked from commit c33b0e11878a52aeaa42b4ebfd0692e5da7f5e07)
This commit is contained in:
Zdenek Kabelac 2024-05-24 19:49:08 +02:00 committed by Marian Csontos
parent 16af82a5af
commit fe58f4b87a

View File

@ -52,7 +52,8 @@ static char *_list_cmds(const char *text, int state)
for (;i < _cmdline->num_command_names;++i)
if (!strncmp(text, _cmdline->command_names[i].name, len))
return strdup(_cmdline->command_names[i].name);
/* increase position for next iteration */
return strdup(_cmdline->command_names[i++].name);
return NULL;
}
@ -102,9 +103,10 @@ static char *_list_args(const char *text, int state)
/* Short form arguments */
if (len < 3) {
for (;match_no < cna->num_args; ++match_no) {
while (match_no < cna->num_args) {
char s[3];
char c = (_cmdline->opt_names + cna->valid_args[match_no])->short_opt;
/* increase position for next iteration */
char c = _cmdline->opt_names[cna->valid_args[match_no++]].short_opt;
if (c) {
sprintf(s, "-%c", c);
if (!strncmp(text, s, len))
@ -117,8 +119,9 @@ static char *_list_args(const char *text, int state)
if (match_no < cna->num_args)
match_no = cna->num_args;
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;
while ((match_no - cna->num_args) < cna->num_args) {
/* increase position for next iteration */
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);
}