From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f67.google.com (mail-wr1-f67.google.com [209.85.221.67]) by dpdk.org (Postfix) with ESMTP id 4CAD51B449 for ; Wed, 11 Jul 2018 23:45:44 +0200 (CEST) Received: by mail-wr1-f67.google.com with SMTP id c13-v6so19557957wrt.1 for ; Wed, 11 Jul 2018 14:45:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ri/JnyweicfVQyHpzve2mJ+UMofLqZON5aR82jts/ao=; b=KxAf/Hc1s6+VRYoBpVqM6UVa11rWiBSQrOaovYvfGEpvJFLmx0nny/3CJOB9LYAjCF 3XL+wpt5xztveFdL5SnzntuRTaPNJFER0eRTGLUdEuQje0G0gbErRYxHTf0s12/JrkZq h009ycUayjocP0pSgTy+KS4LxTaf2ldYhyNa30DdXZj7Mmziv+egz2FyTIrW/rp7tNOK IhAUVNES2JFHD1h24+GN1cxwnwVwf5Aqa39i9YGgRTJkLi3wyKo9RQb2w92eZ9HCqnPU bdJIaa6e/rlen/Tgyv/7MThODWdGsyIpss8VrEEpXk3DTo6OrT0PXdRRuZmi+YSzL64X ZYzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ri/JnyweicfVQyHpzve2mJ+UMofLqZON5aR82jts/ao=; b=Dkkg72nf6UsRypLdTPS17VYGcexWOXbIL1H4YhWFc+aQ2HYofIznbIQBFrVgcdzjPU fPfeIimdh8rO3jA9FmXcLuhunlMcz45uuWgQsJFETbuX0PvAGcK9LHbKQG4eziSQauY3 DLNp4nT7hjWV7gcOHstGzjiT/Z2MX+MYXIZX8+azwE3H4p0pT1MjcOYJ2FWagDRYpA98 L9QzxcYQ+97eN1xhFLV20K+dOoIELhCwlSrDO5a+VdIPMrKgkp0NSxzpcOL/6Raitz56 xY0hs9zYsd+qUZxBDG7vvtld13Up/bdEl0iOaj4C/Srg+UZQFrkf8Xo4xkCQE1eH0R56 bKow== X-Gm-Message-State: AOUpUlHVMRBEu1aEVoS/prK2vfXcwKdc/yDQT2vndCIGokVXBm3+t1ZE f5KPWM8K+nBpqEidJLb13qbfUw/F X-Google-Smtp-Source: AAOMgpeDS5UiqnnxNDirJ+0Gf9jbtWqBKdQxHicDhdCMrB+9Lh+fVU2dK2avh9QqOQJ2NLqOyEFieg== X-Received: by 2002:a5d:4c4c:: with SMTP id n12-v6mr200751wrt.71.1531345543655; Wed, 11 Jul 2018 14:45:43 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id h5-v6sm10550936wrr.19.2018.07.11.14.45.42 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 11 Jul 2018 14:45:42 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 11 Jul 2018 23:44:55 +0200 Message-Id: <27f0f6106f22f2d1943f0d838d326670e9a37a65.1531345404.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v11 05/25] kvargs: introduce a more flexible parsing function 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, 11 Jul 2018 21:45:44 -0000 This function permits defining additional terminating characters, ending the parsing to arbitrary delimiters. Signed-off-by: Gaetan Rivet Acked-by: Thomas Monjalon Acked-by: Shreyansh Jain --- lib/Makefile | 1 + lib/librte_kvargs/meson.build | 2 ++ lib/librte_kvargs/rte_kvargs.c | 25 ++++++++++++++++++ lib/librte_kvargs/rte_kvargs.h | 32 ++++++++++++++++++++++++ lib/librte_kvargs/rte_kvargs_version.map | 7 ++++++ 5 files changed, 67 insertions(+) diff --git a/lib/Makefile b/lib/Makefile index e8e903c8f..8a65525cd 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -5,6 +5,7 @@ include $(RTE_SDK)/mk/rte.vars.mk DIRS-y += librte_compat DIRS-$(CONFIG_RTE_LIBRTE_KVARGS) += librte_kvargs +DEPDIRS-librte_kvargs := librte_compat DIRS-$(CONFIG_RTE_LIBRTE_EAL) += librte_eal DIRS-$(CONFIG_RTE_LIBRTE_PCI) += librte_pci DEPDIRS-librte_pci := librte_eal diff --git a/lib/librte_kvargs/meson.build b/lib/librte_kvargs/meson.build index 0a81e8da7..a1c724961 100644 --- a/lib/librte_kvargs/meson.build +++ b/lib/librte_kvargs/meson.build @@ -7,3 +7,5 @@ includes += include_directories('../../../lib/librte_eal/common/include') version = 1 sources = files('rte_kvargs.c') headers = files('rte_kvargs.h') + +deps += 'compat' diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index 747f14964..52262fe54 100644 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -168,3 +168,28 @@ rte_kvargs_parse(const char *args, const char * const valid_keys[]) return kvlist; } + +__rte_experimental +struct rte_kvargs * +rte_kvargs_parse_delim(const char *args, const char * const valid_keys[], + const char *valid_ends) +{ + struct rte_kvargs *kvlist = NULL; + char *copy; + size_t len; + + if (valid_ends == NULL) + return rte_kvargs_parse(args, valid_keys); + + copy = strdup(args); + if (copy == NULL) + return NULL; + + len = strcspn(copy, valid_ends); + copy[len] = '\0'; + + kvlist = rte_kvargs_parse(copy, valid_keys); + + free(copy); + return kvlist; +} diff --git a/lib/librte_kvargs/rte_kvargs.h b/lib/librte_kvargs/rte_kvargs.h index 51b8120b8..7f32fd1f6 100644 --- a/lib/librte_kvargs/rte_kvargs.h +++ b/lib/librte_kvargs/rte_kvargs.h @@ -25,6 +25,8 @@ extern "C" { #endif +#include + /** Maximum number of key/value associations */ #define RTE_KVARGS_MAX 32 @@ -71,6 +73,36 @@ struct rte_kvargs { struct rte_kvargs *rte_kvargs_parse(const char *args, const char *const valid_keys[]); +/** + * Allocate a rte_kvargs and store key/value associations from a string. + * This version will consider any byte from valid_ends as a possible + * terminating character, and will not parse beyond any of their occurrence. + * + * The function allocates and fills an rte_kvargs structure from a given + * string whose format is key1=value1,key2=value2,... + * + * The structure can be freed with rte_kvargs_free(). + * + * @param args + * The input string containing the key/value associations + * + * @param valid_keys + * A list of valid keys (table of const char *, the last must be NULL). + * This argument is ignored if NULL + * + * @param valid_ends + * Acceptable terminating characters. + * If NULL, the behavior is the same as ``rte_kvargs_parse``. + * + * @return + * - A pointer to an allocated rte_kvargs structure on success + * - NULL on error + */ +__rte_experimental +struct rte_kvargs *rte_kvargs_parse_delim(const char *args, + const char *const valid_keys[], + const char *valid_ends); + /** * Free a rte_kvargs structure * diff --git a/lib/librte_kvargs/rte_kvargs_version.map b/lib/librte_kvargs/rte_kvargs_version.map index 2030ec46c..afce125a9 100644 --- a/lib/librte_kvargs/rte_kvargs_version.map +++ b/lib/librte_kvargs/rte_kvargs_version.map @@ -8,3 +8,10 @@ DPDK_2.0 { local: *; }; + +EXPERIMENTAL { + global: + + rte_kvargs_parse_delim; + +} DPDK_2.0; -- 2.18.0