From patchwork Tue Jun 26 16:56:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ga=C3=ABtan_Rivet?= X-Patchwork-Id: 41589 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EEF5A1BDFD; Tue, 26 Jun 2018 18:56:54 +0200 (CEST) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id C97101BDEF for ; Tue, 26 Jun 2018 18:56:51 +0200 (CEST) Received: by mail-wr0-f193.google.com with SMTP id p1-v6so2378957wrs.9 for ; Tue, 26 Jun 2018 09:56:51 -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 :in-reply-to:references; bh=4Pp1SBn6FM9HL5D1utQNkIos2CC45rmcLx9EwDEf7Ls=; b=zCmXOR/u7ZOLt0cNDyvDVwjsd5d+E4g4iGOTA2ADA0L+VRGAB9UQw1nAlphGw/8/Qr YNvDeWVNW9w0PZxmI5AYQiGm79I5LvSuC+QkuKTgF6V9L+y2DDSC/fEqDIi2oQgCrMpF vnu1O8vJ19RNMWcyqpKKt91WOqVD52CHbvkQcOOTayQx2sHmBQNc6aJyoxrFs754LlnI s2aoeL5Jj60CcD46Tbj/GMAZLZgDjjNMsye3ErfPk3tkpIMvCm0iRa1BPKjQRKXcoD7U v6PHYVwmzgzx+WXvxrj0ze49Jye4mQyS7VBxXnSfjmSO7PF1QxeSd+5hoaHGaWrctL9C lWoQ== 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:in-reply-to:references; bh=4Pp1SBn6FM9HL5D1utQNkIos2CC45rmcLx9EwDEf7Ls=; b=TFnk4v9QVo/NhOCs3RH/Dne9wWjvSJkqZVF8FvN7qblMovaRhoI47LtiFQl6E0ScIJ Hgii+2106SYKub1Z0NsDN6kH7f01UJn8u81W/sfiatqOPQNNJNzVB3E0JtrXh8Aa/r+1 18avP67LTuoab6UH7Fa2Jc0FvtA7VIPBJ+Jrx8bL01ar/+urERcYu9gAoCiHdduxtvTb vP82+syH6DfxZiFGxvxCdOFOf2Vs/sLfLDW55eSe3+tXb9ciMOppbgodVM7mQ6wEVoqT Xj99eUHFc86XgVYuenERQj3nJu5DS4/RUqVwu8tuGnBpnXWtsuXXO/9U0XJ1XbhqJ5PA 0nbg== X-Gm-Message-State: APt69E106BA1N3NhzVzuf8xdJSeKz0ul7b5nl/bDJ7hOslUKTZowtOxt IEZ1Xt9SaQu1+vrbcsUmKiNiNZAR X-Google-Smtp-Source: AAOMgpcBO3LksjaFmj83jENmQ+vSV8ND+IDz7IeVJEcIHcaVRnhHEsgxgQ9Q3Q4bjJ1mmRDE4D/QZg== X-Received: by 2002:adf:e987:: with SMTP id h7-v6mr2182862wrm.102.1530032210767; Tue, 26 Jun 2018 09:56:50 -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 p5-v6sm2680880wre.83.2018.06.26.09.56.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Jun 2018 09:56:49 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Tue, 26 Jun 2018 18:56:06 +0200 Message-Id: <5eb09a42ed1bba9cb47960a759823f8130f39e24.1530031921.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v8 03/21] 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This function permits defining additional terminating characters, ending the parsing to arbitrary delimiters. Signed-off-by: Gaetan Rivet --- lib/Makefile | 1 + lib/librte_kvargs/rte_kvargs.c | 25 +++++++++++++++++++++++++ lib/librte_kvargs/rte_kvargs.h | 30 ++++++++++++++++++++++++++++++ lib/librte_kvargs/rte_kvargs_version.map | 7 +++++++ 4 files changed, 63 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/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index d92a5f9dc..cfbee3bd9 100644 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -180,3 +180,28 @@ rte_kvargs_parse(const char *args, const char * const valid_keys[]) return kvlist; } + +__rte_experimental +struct rte_kvargs * +rte_kvargs_parse2(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..defdf10e4 100644 --- a/lib/librte_kvargs/rte_kvargs.h +++ b/lib/librte_kvargs/rte_kvargs.h @@ -72,6 +72,36 @@ 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 occurence. + * + * 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_parse2(const char *args, + const char *const valid_keys[], + const char *valid_ends); + +/** * Free a rte_kvargs structure * * Free a rte_kvargs structure previously allocated with diff --git a/lib/librte_kvargs/rte_kvargs_version.map b/lib/librte_kvargs/rte_kvargs_version.map index 2030ec46c..b9fe44b98 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_parse2; + +} DPDK_2.0;