client: Trim off spaces from user input
authorPatrik Flykt <patrik.flykt@linux.intel.com>
Thu, 18 Apr 2013 12:28:22 +0000 (15:28 +0300)
committerPatrik Flykt <patrik.flykt@linux.intel.com>
Tue, 23 Apr 2013 09:36:20 +0000 (12:36 +0300)
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

index 20ce7f9..6d9edf2 100644 (file)
@@ -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,