diff options
author | Patrik Flykt <patrik.flykt@linux.intel.com> | 2013-04-18 15:28:22 +0300 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2013-04-23 12:36:20 +0300 |
commit | 88943c8550d7f79d503c65b6eb68558e742b1a42 (patch) | |
tree | 19601b5330480e366b177b3244f46eff2ddfd488 /client | |
parent | a3204d77fed1b870f95da2466c090aa636d2cc2d (diff) | |
download | connman-88943c8550d7f79d503c65b6eb68558e742b1a42.tar.gz connman-88943c8550d7f79d503c65b6eb68558e742b1a42.tar.bz2 connman-88943c8550d7f79d503c65b6eb68558e742b1a42.zip |
client: Trim off spaces from user input
After splitting the input string into components, create a new array holding
the non-zero substrings as input for the commands. Thus the input can start
and end as well as divide its separate parts by any number spaces.
Diffstat (limited to 'client')
-rw-r--r-- | client/input.c | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/client/input.c b/client/input.c index 20ce7f9c..6d9edf2d 100644 --- a/client/input.c +++ b/client/input.c @@ -88,26 +88,38 @@ void __connmanctl_redraw_rl(void) static void rl_handler(char *input) { - char **args; - int num, err; + char **args, **trim_args; + int num, len, err, i; if (input == NULL) { rl_newline(1, '\n'); g_main_loop_quit(main_loop); return; } - if (*input != '\0') - add_history(input); args = g_strsplit(input, " ", 0); num = g_strv_length(args); - err = __connmanctl_commands(connection, args, num); + trim_args = g_new0(char *, num); + for (i = 0, len = 0; i < num; i++) { + if (*args[i] != '\0') { + trim_args[len] = args[i]; + len++; + } + } - g_strfreev(args); + if (len > 0) { - if (err > 0) - g_main_loop_quit(main_loop); + add_history(input); + + err = __connmanctl_commands(connection, trim_args, len); + + if (err > 0) + g_main_loop_quit(main_loop); + } + + g_strfreev(args); + g_free(trim_args); } static gboolean input_handler(GIOChannel *channel, GIOCondition condition, |