From: asterix Date: Thu, 5 Jan 2012 17:26:02 +0000 (+0000) Subject: Allow string arguments to be quote within "". X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=4072b28a98d392ad14cea12d8b4ca1377c7b7a43;p=bertos.git Allow string arguments to be quote within "". Some string arguments may need to use spaces, allow them by using double quotes to enclose the string. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@5221 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/mware/parser.c b/bertos/mware/parser.c index 217cc6c1..2197d848 100644 --- a/bertos/mware/parser.c +++ b/bertos/mware/parser.c @@ -89,17 +89,31 @@ DECLARE_HASHTABLE_STATIC(commands, CONFIG_MAX_COMMANDS_NUMBER, get_key_from_comm * \return True if a word was extracted, false if we got to the end * of the string without extracting any word. */ -static bool get_word(const char **begin, const char **end) +bool get_word(const char **begin, const char **end) { const char *cur = *end; + bool open_quote = false; while ((*cur == ' ' || *cur == '\t') && *cur) ++cur; + if (*cur == '"') + open_quote = true; + *begin = cur; - while ((*cur != ' ' && *cur != '\t') && *cur) + if (open_quote) + { ++cur; + while (*cur != '"' && *cur) + ++cur; + if (*cur != '"') + return false; + ++cur; + } + else + while ((*cur != ' ' && *cur != '\t') && *cur) + ++cur; *end = cur; @@ -139,6 +153,12 @@ static bool parseArgs(const char *fmt, const char *input, parms argv[]) case 's': (*argv).str.p = begin; (*argv).str.sz = end - begin; + /* Remove the quotes from argument */ + if (*begin == '"' && *(end - 1) == '"') + { + (*argv).str.p += 1; + (*argv).str.sz -= 2; + } argv++; break; diff --git a/bertos/mware/parser.h b/bertos/mware/parser.h index 9d4423d3..a3575546 100644 --- a/bertos/mware/parser.h +++ b/bertos/mware/parser.h @@ -263,6 +263,7 @@ INLINE bool parser_execute_cmd(const struct CmdTemplate* templ, parms args[CONFI const struct CmdTemplate* parser_get_cmd_template(const char* line); bool parser_get_cmd_arguments(const char* line, const struct CmdTemplate* templ, parms args[CONFIG_PARSER_MAX_ARGS]); +bool get_word(const char **begin, const char **end); #if CONFIG_ENABLE_COMPAT_BEHAVIOUR /**