From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id C06541B5BB for ; Wed, 10 Oct 2018 21:23:35 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 6A5DB20D2D; Wed, 10 Oct 2018 15:23:35 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 10 Oct 2018 15:23:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=kf2fiOdU/B 5VEaMedEj1pgh78QtCL1ovvKofyK8o9Ks=; b=XHbbfmaq8quxkfw71JSNV74FKy SmCHmC2w+ydFGxpo6rZvvnmkGQoLHkAu6NmITQtUgjzS3IW5jbjJFH3UJrSaRgcv 3gnZg60Cuah7vytyaHnWARHJkTcoE3aqu9hwVuFuGSd2gpGBiWMzBa7aQwx3lUM3 FUdRh2ukx9zSCdVRE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=kf2fiOdU/B5VEaMedEj1pgh78QtCL1ovvKofyK8o9Ks=; b=yP+RgpN3 vI3S6ev+EmTSqsJYj3p+Z5yUIEeuxIc0sEPtRRIkBAI0PlS058ghMVOaZVVyvWyX yr1s3s4Zn5+t7WD8yXX++0uPqnPK7IbEWezZcS8KRYzhwibM+4IhOG5z1ofn8lg8 QSmKckUEY9kK9/4z3IOLuXG76r7wpW3VbDJMSenlODPNHDbPJZahArJXbvI4ux5d mkYmcIG0BNx/ilsBVxV116tLsuuuerWGpdF+a2CeMOKWhMkC6g9mQqNigP9XspkN LA+p2kILfjwcWc2r78yN6C4hbK+RbKY/PPrMyVG1696zGJp5K0RgDDiWVxvK95JO RDrX96s1B1jSPA== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 30D7FE489A; Wed, 10 Oct 2018 15:23:34 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com, olivier.matz@6wind.com, remy.horton@intel.com, bruce.richardson@intel.com Date: Wed, 10 Oct 2018 21:23:27 +0200 Message-Id: <20181010192330.21105-2-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181010192330.21105-1-thomas@monjalon.net> References: <20181009021858.19216-1-thomas@monjalon.net> <20181010192330.21105-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 1/4] kvargs: support list value X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Oct 2018 19:23:36 -0000 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 --- lib/librte_kvargs/rte_kvargs.c | 14 ++++++++++++++ test/test/test_kvargs.c | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index a28f76945..e616da351 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; } diff --git a/test/test/test_kvargs.c b/test/test/test_kvargs.c index e6738624e..a42056f36 100644 --- a/test/test/test_kvargs.c +++ b/test/test/test_kvargs.c @@ -137,6 +137,26 @@ static int test_valid_kvargs(void) } rte_kvargs_free(kvlist); + /* third test using list as value */ + args = "foo=[0,1],check=value2"; + valid_keys = valid_keys_list; + kvlist = rte_kvargs_parse(args, valid_keys); + if (kvlist == NULL) { + printf("rte_kvargs_parse() error"); + goto fail; + } + if (strcmp(kvlist->pairs[0].value, "[0,1]") != 0) { + printf("wrong value %s", kvlist->pairs[0].value); + goto fail; + } + count = kvlist->count; + if (count != 2) { + printf("invalid count value %d\n", count); + rte_kvargs_free(kvlist); + goto fail; + } + rte_kvargs_free(kvlist); + return 0; fail: @@ -162,6 +182,7 @@ static int test_invalid_kvargs(void) "foo=1,,foo=2", /* empty key/value */ "foo=1,foo", /* no value */ "foo=1,=2", /* no key */ + "foo=[1,2", /* no closing bracket in value */ ",=", /* also test with a smiley */ NULL }; const char **args; -- 2.19.0