diff options
author | Jiří Klimeš <blueowl@centrum.cz> | 2016-09-15 01:20:53 +0200 |
---|---|---|
committer | Beniamino Galvani <bgalvani@redhat.com> | 2016-09-19 17:05:08 +0200 |
commit | 9d885436171c10b80de8abe75c9c7f2a68308fdf (patch) | |
tree | 055044bdf11c6deaf0a535f5683ad47ee538f304 | |
parent | 5984bdd895cf9d3e30d272a443e971a8121196b6 (diff) | |
download | NetworkManager-9d885436171c10b80de8abe75c9c7f2a68308fdf.tar.gz |
cli: (trivial) move gen_func_ifnames() from devices.c to common.c
and rename it to nmc_rl_gen_func()
(cherry picked from commit 1f0ba2e48738cbacb0dc3610bae776bf8f10d7e4)
-rw-r--r-- | clients/cli/common.c | 27 | ||||
-rw-r--r-- | clients/cli/common.h | 1 | ||||
-rw-r--r-- | clients/cli/devices.c | 31 |
3 files changed, 30 insertions, 29 deletions
diff --git a/clients/cli/common.c b/clients/cli/common.c index 62cd6c9c77..f8dc523982 100644 --- a/clients/cli/common.c +++ b/clients/cli/common.c @@ -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; diff --git a/clients/cli/common.h b/clients/cli/common.h index 579c44a7d0..114a8e634d 100644 --- a/clients/cli/common.h +++ b/clients/cli/common.h @@ -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); diff --git a/clients/cli/devices.c b/clients/cli/devices.c index 32c84bb69a..550f0c2e1d 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -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) |