From 88943c8550d7f79d503c65b6eb68558e742b1a42 Mon Sep 17 00:00:00 2001 From: Patrik Flykt Date: Thu, 18 Apr 2013 15:28:22 +0300 Subject: 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. --- client/input.c | 28 ++++++++++++++++++++-------- 1 file 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, -- cgit v1.2.3