From 1006fee8027936c68e0f0b2f8dae766ad090764a Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 9 Nov 2015 17:32:51 +0100 Subject: [PATCH] Add an option to strip trailing whitespace when parsing commands --- src/core/commands.c | 5 +++++ src/core/commands.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/core/commands.c b/src/core/commands.c index 9e451bc8..0fb373c7 100644 --- a/src/core/commands.c +++ b/src/core/commands.c @@ -748,6 +748,11 @@ int cmd_get_params(const char *data, gpointer *free_me, int count, ...) if (cnt == 0 && count & PARAM_FLAG_GETREST) { /* get rest */ arg = datad; + + /* strip the trailing whitespace */ + if (count & PARAM_FLAG_STRIP_TRAILING_WS) { + arg = g_strchomp (arg); + } } else { arg = (count & PARAM_FLAG_NOQUOTES) ? cmd_get_param(&datad) : diff --git a/src/core/commands.h b/src/core/commands.h index d65185e5..72105ad3 100644 --- a/src/core/commands.h +++ b/src/core/commands.h @@ -152,6 +152,8 @@ int command_have_option(const char *cmd, const char *option); #define PARAM_FLAG_OPTCHAN 0x00010000 /* optional channel in first argument, but don't treat "*" as current channel */ #define PARAM_FLAG_OPTCHAN_NAME (0x00020000|PARAM_FLAG_OPTCHAN) +/* strip the trailing whitespace */ +#define PARAM_FLAG_STRIP_TRAILING_WS 0x00040000 char *cmd_get_param(char **data); char *cmd_get_quoted_param(char **data);