2013-12-27 14:10:34

by Sebastian Chlad

[permalink] [raw]
Subject: [PATCH] tools/bluetooth-player: Formatting commands

Formatting commands passed to bluetooth player.
Whitespace character trimmed.
---
tools/bluetooth-player.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/tools/bluetooth-player.c b/tools/bluetooth-player.c
index 622d391..1dadc70 100644
--- a/tools/bluetooth-player.c
+++ b/tools/bluetooth-player.c
@@ -1065,9 +1065,10 @@ static char **cmd_completion(const char *text, int start, int end)

static void rl_handler(char *input)
{
+
int argc;
char **argv = NULL;
- int i;
+ int i, len;

if (!input) {
rl_insert_text("quit");
@@ -1080,6 +1081,12 @@ static void rl_handler(char *input)
if (!strlen(input))
goto done;

+ if (input) {
+ len = strlen(input);
+ if (len > 0 && input[len - 1] == ' ')
+ input[len - 1] = '\0';
+ }
+
add_history(input);

argv = g_strsplit(input, " ", -1);
--
1.7.9.5



2013-12-31 11:55:15

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH] tools/bluetooth-player: Formatting commands

Hi Sebastian,

On Mon, Dec 30, 2013 at 4:31 PM, Sebastian Chlad
<[email protected]> wrote:
> Formatting commands passed to bluetooth player.
> Whitespace character trimmed.
> ---
> tools/bluetooth-player.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/tools/bluetooth-player.c b/tools/bluetooth-player.c
> index 622d391..2afdd17 100644
> --- a/tools/bluetooth-player.c
> +++ b/tools/bluetooth-player.c
> @@ -1080,6 +1080,7 @@ static void rl_handler(char *input)
> if (!strlen(input))
> goto done;
>
> + g_strstrip(input);
> add_history(input);
>
> argv = g_strsplit(input, " ", -1);
> --
> 1.7.9.5

Pushed, I went ahead and pushed a similar fix to obexctl and it seems
bluetoothctl could use the same logic but it doesn't use g_strsplit
and it does in fact check trailing whitespaces:

if (arg) {
int len = strlen(arg);
if (len > 0 && arg[len - 1] == ' ')
arg[len - 1] = '\0';
}

We might be better off with g_strstrip + g_strsplit since we depend on
glib anyway.


--
Luiz Augusto von Dentz

2013-12-30 14:31:32

by Sebastian Chlad

[permalink] [raw]
Subject: [PATCH] tools/bluetooth-player: Formatting commands

Formatting commands passed to bluetooth player.
Whitespace character trimmed.
---
tools/bluetooth-player.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/tools/bluetooth-player.c b/tools/bluetooth-player.c
index 622d391..2afdd17 100644
--- a/tools/bluetooth-player.c
+++ b/tools/bluetooth-player.c
@@ -1080,6 +1080,7 @@ static void rl_handler(char *input)
if (!strlen(input))
goto done;

+ g_strstrip(input);
add_history(input);

argv = g_strsplit(input, " ", -1);
--
1.7.9.5


2013-12-27 15:22:19

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH] tools/bluetooth-player: Formatting commands

Hi Sebastian,

On Fri, Dec 27, 2013, Sebastian Chlad wrote:
> Formatting commands passed to bluetooth player.
> Whitespace character trimmed.
> ---
> tools/bluetooth-player.c | 9 ++++++++-
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/tools/bluetooth-player.c b/tools/bluetooth-player.c
> index 622d391..1dadc70 100644
> --- a/tools/bluetooth-player.c
> +++ b/tools/bluetooth-player.c
> @@ -1065,9 +1065,10 @@ static char **cmd_completion(const char *text, int start, int end)
>
> static void rl_handler(char *input)
> {
> +

This line addition is unnecessary.

> int argc;
> char **argv = NULL;
> - int i;
> + int i, len;
>
> if (!input) {
> rl_insert_text("quit");
> @@ -1080,6 +1081,12 @@ static void rl_handler(char *input)
> if (!strlen(input))
> goto done;
>
> + if (input) {
> + len = strlen(input);
> + if (len > 0 && input[len - 1] == ' ')
> + input[len - 1] = '\0';
> + }

Since bluetooth-player uses GLib I suppose it'd make more sense to use
the provided g_strstrip convenience function (or g_strchomp if you
really only want to strip trailing whitespace).

Johan