From: asterix Date: Thu, 5 Jan 2012 17:26:01 +0000 (+0000) Subject: Change parser strings to include length. X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=8ad8e5d325736480a881a7f30bd757f96b87376e;p=bertos.git Change parser strings to include length. By default, parsed arguments from the parser module are not valid strings. This patch introduces string length to each string parameter. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@5220 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/mware/parser.c b/bertos/mware/parser.c index 71aec30d..217cc6c1 100644 --- a/bertos/mware/parser.c +++ b/bertos/mware/parser.c @@ -137,7 +137,9 @@ static bool parseArgs(const char *fmt, const char *input, parms argv[]) break; case 's': - (*argv++).s = begin; + (*argv).str.p = begin; + (*argv).str.sz = end - begin; + argv++; break; default: @@ -264,7 +266,7 @@ bool parser_get_cmd_arguments(const char* input, const struct CmdTemplate* cmdp, if (!input) return false; - args[0].s = cmdp->name; + args[0].str.p = cmdp->name; if (!parseArgs(cmdp->arg_fmt, input, args + 1)) return false; diff --git a/bertos/mware/parser.h b/bertos/mware/parser.h index 281db396..9d4423d3 100644 --- a/bertos/mware/parser.h +++ b/bertos/mware/parser.h @@ -131,8 +131,14 @@ typedef enum RC_SKIP = 2 ///< Skip following commands } ResultCode; +typedef struct +{ + const char *p; + int sz; +} str_parm; + /** union that contains parameters passed to and from commands */ -typedef union { long l; const char *s; } parms; +typedef union { long l; str_parm str; } parms; /** pointer to commands */ typedef ResultCode (*CmdFuncPtr)(parms args_results[]);