From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail5.wrs.com (mail5.windriver.com [192.103.53.11]) by dpdk.org (Postfix) with ESMTP id 8D7C8F614 for ; Thu, 2 Mar 2017 20:29:52 +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 v22JTpKR007621 (version=TLSv1 cipher=AES128-SHA bits=128 verify=OK); Thu, 2 Mar 2017 11:29:51 -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, 2 Mar 2017 11:29:51 -0800 From: Allain Legacy To: , CC: , Date: Thu, 2 Mar 2017 14:29:29 -0500 Message-ID: <1488482971-170522-4-git-send-email-allain.legacy@windriver.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1488482971-170522-1-git-send-email-allain.legacy@windriver.com> References: <1488482971-170522-1-git-send-email-allain.legacy@windriver.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [128.224.145.137] Subject: [dpdk-dev] [PATCH 3/5] cfgfile: add support for unamed global section 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: Thu, 02 Mar 2017 19:29:52 -0000 The current implementation of the cfgfile library requires that all key=value pairs be within [SECTION] definitions. The ini file standard allows for key=value pairs in an unnamed section. That section is considered the [GLOBAL] section. This commit adds the capability of parsing key=value pairs from such an unnamed section. The CFG_FLAG_GLOBAL_SECTION flag must be passed to the rte_cfgfile_load() API to enable this functionality. Signed-off-by: Allain Legacy --- lib/librte_cfgfile/rte_cfgfile.c | 16 ++++++++++++++++ lib/librte_cfgfile/rte_cfgfile.h | 6 ++++++ 2 files changed, 22 insertions(+) diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index 7a9206d..2aba169 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -108,6 +108,22 @@ struct rte_cfgfile * memset(cfg, 0, size); + if (flags & CFG_FLAG_GLOBAL_SECTION) { + curr_section = 0; + allocated_entries = CFG_ALLOC_ENTRY_BATCH; + cfg->sections[curr_section] = malloc( + sizeof(*cfg->sections[0]) + + sizeof(cfg->sections[0]->entries[0]) * + allocated_entries); + if (cfg->sections[curr_section] == NULL) { + printf("Error - no memory for global section\n"); + goto error1; + } + + snprintf(cfg->sections[curr_section]->name, + sizeof(cfg->sections[0]->name), "GLOBAL"); + } + while (fgets(buffer, sizeof(buffer), f) != NULL) { char *pos = NULL; size_t len = strnlen(buffer, sizeof(buffer)); diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h index b40e6a1..fce1efc 100644 --- a/lib/librte_cfgfile/rte_cfgfile.h +++ b/lib/librte_cfgfile/rte_cfgfile.h @@ -67,6 +67,12 @@ struct rte_cfgfile_entry { }; /** + * Indicates that the file supports key value entries before the first defined + * section. These entries can be accessed in the "GLOBAL" section. + */ +#define CFG_FLAG_GLOBAL_SECTION (1 << 0) + +/** * Open config file * * @param filename -- 1.8.3.1