From 36bf0bd0421922c6d730131cb873c7e1fe9fd898 Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Thu, 12 Feb 2015 10:19:03 +0200 Subject: [PATCH] tools/obexctl: Use wordexp() for parsing commands --- tools/obexctl.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/tools/obexctl.c b/tools/obexctl.c index 512a145a9..b4fdc1cf1 100644 --- a/tools/obexctl.c +++ b/tools/obexctl.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -2030,8 +2031,9 @@ static char **cmd_completion(const char *text, int start, int end) static void rl_handler(char *input) { + wordexp_t w; int argc; - char **argv = NULL; + char **argv; int i; if (!input) { @@ -2045,18 +2047,16 @@ static void rl_handler(char *input) if (!strlen(input)) goto done; - g_strstrip(input); add_history(input); - argv = g_strsplit(input, " ", -1); - if (argv == NULL) + if (wordexp(input, &w, WRDE_NOCMD)) goto done; - for (argc = 0; argv[argc];) - argc++; + if (w.we_wordc == 0) + goto free_we; - if (argc == 0) - goto done; + argv = w.we_wordv; + argc = w.we_wordc; for (i = 0; cmd_table[i].cmd; i++) { if (strcmp(argv[0], cmd_table[i].cmd)) @@ -2064,13 +2064,13 @@ static void rl_handler(char *input) if (cmd_table[i].func) { cmd_table[i].func(argc, argv); - goto done; + goto free_we; } } if (strcmp(argv[0], "help")) { printf("Invalid command\n"); - goto done; + goto free_we; } printf("Available commands:\n"); @@ -2083,8 +2083,9 @@ static void rl_handler(char *input) cmd_table[i].desc ? : ""); } +free_we: + wordfree(&w); done: - g_strfreev(argv); free(input); } -- 2.47.3