summaryrefslogtreecommitdiff
path: root/lib/librte_kvargs
diff options
context:
space:
mode:
authorThomas Monjalon <thomas@monjalon.net>2018-10-22 15:15:27 +0200
committerFerruh Yigit <ferruh.yigit@intel.com>2018-10-26 22:14:06 +0200
commitcc0579f2339a1100152fc1bdbed1b579e9618cb7 (patch)
tree26ae1b891017621e19c5bab3eb172fcb495b0322 /lib/librte_kvargs
parent6bd7fbd03c6282689415ea3ff99622a631109984 (diff)
downloaddpdk-cc0579f2339a1100152fc1bdbed1b579e9618cb7.zip
dpdk-cc0579f2339a1100152fc1bdbed1b579e9618cb7.tar.gz
dpdk-cc0579f2339a1100152fc1bdbed1b579e9618cb7.tar.xz
kvargs: support list value
If a value contains a comma, rte_kvargs_tokenize() will split here. In order to support list syntax [a,b] as value, an extra parsing of the square brackets is added. Signed-off-by: Thomas Monjalon <thomas@monjalon.net>
Diffstat (limited to 'lib/librte_kvargs')
-rw-r--r--lib/librte_kvargs/rte_kvargs.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c
index 7ec1ea5..f7030c6 100644
--- a/lib/librte_kvargs/rte_kvargs.c
+++ b/lib/librte_kvargs/rte_kvargs.c
@@ -44,6 +44,20 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params)
kvlist->pairs[i].value == NULL)
return -1;
+ /* Detect list [a,b] to skip comma delimiter in list. */
+ str = kvlist->pairs[i].value;
+ if (str[0] == '[') {
+ /* Find the end of the list. */
+ while (str[strlen(str) - 1] != ']') {
+ /* Restore the comma erased by strtok_r(). */
+ str[strlen(str)] = ',';
+ /* Parse until next comma. */
+ str = strtok_r(NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1);
+ if (str == NULL)
+ return -1; /* no closing bracket */
+ }
+ }
+
kvlist->count++;
str = NULL;
}