cli: (trivial) move gen_func_ifnames() from devices.c to common.c

and rename it to nmc_rl_gen_func()
This commit is contained in:
Jiří Klimeš 2016-09-15 01:20:53 +02:00 committed by Beniamino Galvani
parent 4b90b7b774
commit 1f0ba2e487
3 changed files with 30 additions and 29 deletions

View file

@ -1356,6 +1356,33 @@ nmc_rl_gen_func_basic (const char *text, int state, const char **words)
return NULL;
}
char *
nmc_rl_gen_func_ifnames (const char *text, int state)
{
int i;
const GPtrArray *devices;
const char **ifnames;
char *ret;
nm_cli.get_client (&nm_cli);
devices = nm_client_get_devices (nm_cli.client);
if (devices->len == 0)
return NULL;
ifnames = g_new (const char *, devices->len + 1);
for (i = 0; i < devices->len; i++) {
NMDevice *dev = g_ptr_array_index (devices, i);
const char *ifname = nm_device_get_iface (dev);
ifnames[i] = ifname;
}
ifnames[i] = NULL;
ret = nmc_rl_gen_func_basic (text, state, ifnames);
g_free (ifnames);
return ret;
}
/* for pre-filling a string to readline prompt */
char *nmc_rl_pre_input_deftext;

View file

@ -65,6 +65,7 @@ void nmc_cleanup_readline (void);
char *nmc_readline (const char *prompt_fmt, ...) G_GNUC_PRINTF (1, 2);
char *nmc_readline_echo (gboolean echo_on, const char *prompt_fmt, ...) G_GNUC_PRINTF (2, 3);
char *nmc_rl_gen_func_basic (const char *text, int state, const char **words);
char *nmc_rl_gen_func_ifnames (const char *text, int state);
gboolean nmc_get_in_readline (void);
void nmc_set_in_readline (gboolean in_readline);

View file

@ -3813,33 +3813,6 @@ is_single_word (const char* line)
return FALSE;
}
static char *
gen_func_ifnames (const char *text, int state)
{
int i;
const GPtrArray *devices;
const char **ifnames;
char *ret;
nm_cli.get_client (&nm_cli);
devices = nm_client_get_devices (nm_cli.client);
if (devices->len == 0)
return NULL;
ifnames = g_new (const char *, devices->len + 1);
for (i = 0; i < devices->len; i++) {
NMDevice *dev = g_ptr_array_index (devices, i);
const char *ifname = nm_device_get_iface (dev);
ifnames[i] = ifname;
}
ifnames[i] = NULL;
ret = nmc_rl_gen_func_basic (text, state, ifnames);
g_free (ifnames);
return ret;
}
static char **
nmcli_device_tab_completion (const char *text, int start, int end)
{
@ -3856,9 +3829,9 @@ nmcli_device_tab_completion (const char *text, int start, int end)
if (!is_single_word (rl_line_buffer))
return NULL;
generator_func = gen_func_ifnames;
generator_func = nmc_rl_gen_func_ifnames;
} else if (g_strcmp0 (rl_prompt, PROMPT_INTERFACES) == 0) {
generator_func = gen_func_ifnames;
generator_func = nmc_rl_gen_func_ifnames;
}
if (generator_func)