From patchwork Thu Mar 9 13:11:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Allain Legacy X-Patchwork-Id: 21637 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 [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 9B0B7D0C9; Thu, 9 Mar 2017 14:12:15 +0100 (CET) Received: from mail5.wrs.com (mail5.windriver.com [192.103.53.11]) by dpdk.org (Postfix) with ESMTP id D470837B4 for ; Thu, 9 Mar 2017 14:11:35 +0100 (CET) Received: from ALA-HCA.corp.ad.wrs.com (ala-hca.corp.ad.wrs.com [147.11.189.40]) by mail5.wrs.com (8.15.2/8.15.2) with ESMTPS id v29DBYxX005546 (version=TLSv1 cipher=AES128-SHA bits=128 verify=OK); Thu, 9 Mar 2017 05:11:34 -0800 Received: from yow-cgts4-lx.wrs.com (128.224.145.137) by ALA-HCA.corp.ad.wrs.com (147.11.189.50) with Microsoft SMTP Server (TLS) id 14.3.294.0; Thu, 9 Mar 2017 05:11:34 -0800 From: Allain Legacy To: , CC: , Date: Thu, 9 Mar 2017 08:11:00 -0500 Message-ID: <1489065060-98370-7-git-send-email-allain.legacy@windriver.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1489065060-98370-1-git-send-email-allain.legacy@windriver.com> References: <1488482971-170522-1-git-send-email-allain.legacy@windriver.com> <1489065060-98370-1-git-send-email-allain.legacy@windriver.com> MIME-Version: 1.0 X-Originating-IP: [128.224.145.137] Subject: [dpdk-dev] [PATCH v2 6/6] cfgfile: add support for empty value string 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 commit adds support to the cfgfile library for parsing a key=value line that has no value string specified (e.g., "key="). This can be used to override a configuration attribute that has a default value or default list of values to set it back to an undefined value to disable functionality. Signed-off-by: Allain Legacy --- lib/librte_cfgfile/rte_cfgfile.c | 11 ++++++----- test/test/test_cfgfile.c | 17 +---------------- test/test/test_cfgfiles/etc/sample1.ini | 2 +- test/test/test_cfgfiles/etc/sample2.ini | 2 +- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index 35c81e4..d3022b9 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -219,11 +219,12 @@ struct rte_cfgfile * struct rte_cfgfile_section *sect = cfg->sections[curr_section]; - char *split[2]; - if (rte_strsplit(buffer, sizeof(buffer), split, 2, '=') - != 2) { + int n; + char *split[2] = {NULL}; + n = rte_strsplit(buffer, sizeof(buffer), split, 2, '='); + if ((n < 1) || (n > 2)) { printf("Error at line %d - cannot split " - "string\n", lineno); + "string, n=%d\n", lineno, n); goto error1; } @@ -254,7 +255,7 @@ struct rte_cfgfile * snprintf(entry->name, sizeof(entry->name), "%s", split[0]); snprintf(entry->value, sizeof(entry->value), "%s", - split[1]); + split[1] ? split[1] : ""); _strip(entry->name, strnlen(entry->name, sizeof(entry->name))); _strip(entry->value, strnlen(entry->value, diff --git a/test/test/test_cfgfile.c b/test/test/test_cfgfile.c index eab8ccc..d8214d1 100644 --- a/test/test/test_cfgfile.c +++ b/test/test/test_cfgfile.c @@ -105,8 +105,7 @@ "key2 unexpected value: %s", value); value = rte_cfgfile_get_entry(cfgfile, "section2", "key3"); - TEST_ASSERT(strcmp("value3", value) == 0, - "key3 unexpected value: %s", value); + TEST_ASSERT(strlen(value) == 0, "key3 unexpected value: %s", value); return 0; } @@ -167,17 +166,6 @@ } static int -test_cfgfile_invalid_key_value_pair(void) -{ - struct rte_cfgfile *cfgfile; - - cfgfile = rte_cfgfile_load(CFG_FILES_ETC "/invalid_key_value.ini", 0); - TEST_ASSERT_NULL(cfgfile, "Expected failured did not occur"); - - return 0; -} - -static int test_cfgfile_missing_section(void) { struct rte_cfgfile *cfgfile; @@ -251,9 +239,6 @@ if (test_cfgfile_invalid_section_header()) return -1; - if (test_cfgfile_invalid_key_value_pair()) - return -1; - if (test_cfgfile_missing_section()) return -1; diff --git a/test/test/test_cfgfiles/etc/sample1.ini b/test/test/test_cfgfiles/etc/sample1.ini index aef91c2..5b001d3 100644 --- a/test/test/test_cfgfiles/etc/sample1.ini +++ b/test/test/test_cfgfiles/etc/sample1.ini @@ -8,5 +8,5 @@ key1=value1 ; this is section 2 ;key1=value1 key2=value2 -key3=value3 ; this is key3 +key3= ; this is key3 ignore-missing-separator diff --git a/test/test/test_cfgfiles/etc/sample2.ini b/test/test/test_cfgfiles/etc/sample2.ini index 21075e9..8fee5a7 100644 --- a/test/test/test_cfgfiles/etc/sample2.ini +++ b/test/test/test_cfgfiles/etc/sample2.ini @@ -8,5 +8,5 @@ key1=value1 # this is section 2 #key1=value1 key2=value2 -key3=value3 # this is key3 +key3= # this is key3 ignore-missing-separator