From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f42.google.com (mail-pa0-f42.google.com [209.85.220.42]) by dpdk.org (Postfix) with ESMTP id 04188568A for ; Wed, 10 Feb 2016 20:13:06 +0100 (CET) Received: by mail-pa0-f42.google.com with SMTP id ho8so16226601pac.2 for ; Wed, 10 Feb 2016 11:13:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bigswitch-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nS7u8p+GbeumedVaYf21MXE3rSS3ya3+9SJ/KUM6iII=; b=e3KUKtEzYcVWZtxLgH4PPfpPeVyiqyUvRDSuru3LAwW+4BYmf1K2HnVZhBemkqBN3u 5IiYOrXVXrdNY4aPkub0mWaWnVxeOCumRvlwniAUDLVlDt3FnpSnEOyniE8tZ7DPqIpG hT4dId7uvZOekY76WfegBEzjktIr8og5/M7DHgUtWotgfs+zHvLjQ7zq4oklnRCqXce2 wMJJGVeQq7Ru2eo+Z8/VK6uErPU6itbQ3AFAdZvpsiLQWvK9CkWsikQXP237QhSSMbhj 3rKidgwzSqTbHw32RVj7sw14jSpfRoSn7vrJ8sbVxDBMgD+h4CGuWy6XkbXCEcEL7h6f bcRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nS7u8p+GbeumedVaYf21MXE3rSS3ya3+9SJ/KUM6iII=; b=DHLSm4bSBotmsqvi70buuztiaQIIQjs4t813F7EqVFOmFbbjYI/q04l4dlHBgD/up7 L1QLzrKWMOMZ5ufWAGhmBA7uRsRRxmcNXvJ1DbRBwoajshjELDoMlpfVCeQGL25sTdpx tkdy91GK9wo9p/img+18H/P9JY+i1/sK4lOZKK5sc69utxInNV0rvEGNnjbXlpRd3+Bj lyVCBKHxKlkYE0SIVDOLn5caRhU1Cnvyny0poZy2R6fnmmc+ZPo1PG/SRFKiXPr+dBKf PeeidlUkGmpSSIWLfiOL3w9TLpmqYwMP+1TaOGg9UkqWhyMCxkHZyhnbJYAWIW/eFuEY RvCQ== X-Gm-Message-State: AG10YORpfo23InJ5Bpr0LmJY4LbOIP6Ln5txMfM8xZxYQ+LmWZdTvpxMrHfbVu/wYl033TvM X-Received: by 10.66.62.226 with SMTP id b2mr51950239pas.94.1455131585348; Wed, 10 Feb 2016 11:13:05 -0800 (PST) Received: from rlane-work.eng.bigswitch.com (c-67-188-28-208.hsd1.ca.comcast.net. [67.188.28.208]) by smtp.gmail.com with ESMTPSA id xz6sm6909810pab.42.2016.02.10.11.13.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 10 Feb 2016 11:13:04 -0800 (PST) From: Rich Lane X-Google-Original-From: Rich Lane To: dev@dpdk.org Date: Wed, 10 Feb 2016 11:12:16 -0800 Message-Id: <1455131536-46285-1-git-send-email-rlane@bigswitch.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453178510-113435-1-git-send-email-rlane@bigswitch.com> References: <1453178510-113435-1-git-send-email-rlane@bigswitch.com> Subject: [dpdk-dev] [PATCH v3] cfgfile: support looking up sections by index X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Feb 2016 19:13:06 -0000 This is useful when sections have duplicate names. Signed-off-by: Rich Lane --- v2->v3 - Added check for index < 0. v1->v2: - Added new symbol to version script. lib/librte_cfgfile/rte_cfgfile.c | 16 ++++++++++++++++ lib/librte_cfgfile/rte_cfgfile.h | 23 +++++++++++++++++++++++ lib/librte_cfgfile/rte_cfgfile_version.map | 6 ++++++ 3 files changed, 45 insertions(+) diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index a677dad..eba0713 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -333,6 +333,22 @@ rte_cfgfile_section_entries(struct rte_cfgfile *cfg, const char *sectionname, return i; } +int +rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, int index, + struct rte_cfgfile_entry *entries, int max_entries) +{ + int i; + const struct rte_cfgfile_section *sect; + + if (index < 0 || index >= cfg->num_sections) + return -1; + + sect = cfg->sections[index]; + for (i = 0; i < max_entries && i < sect->num_entries; i++) + entries[i] = *sect->entries[i]; + return i; +} + const char * rte_cfgfile_get_entry(struct rte_cfgfile *cfg, const char *sectionname, const char *entryname) diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h index d443782..8e69971 100644 --- a/lib/librte_cfgfile/rte_cfgfile.h +++ b/lib/librte_cfgfile/rte_cfgfile.h @@ -155,6 +155,29 @@ int rte_cfgfile_section_entries(struct rte_cfgfile *cfg, struct rte_cfgfile_entry *entries, int max_entries); +/** Get section entries as key-value pairs +* +* The index of a section is the same as the index of its name in the +* result of rte_cfgfile_sections. This API can be used when there are +* multiple sections with the same name. +* +* @param cfg +* Config file +* @param index +* Section index +* @param entries +* Pre-allocated array of at least max_entries entries where the section +* entries are stored as key-value pair after successful invocation +* @param max_entries +* Maximum number of section entries to be stored in entries array +* @return +* Number of entries populated on success, negative error code otherwise +*/ +int rte_cfgfile_section_entries_by_index(struct rte_cfgfile *cfg, + int index, + struct rte_cfgfile_entry *entries, + int max_entries); + /** Get value of the named entry in named config file section * * @param cfg diff --git a/lib/librte_cfgfile/rte_cfgfile_version.map b/lib/librte_cfgfile/rte_cfgfile_version.map index bf6c6fd..f6a27a9 100644 --- a/lib/librte_cfgfile/rte_cfgfile_version.map +++ b/lib/librte_cfgfile/rte_cfgfile_version.map @@ -13,3 +13,9 @@ DPDK_2.0 { local: *; }; + +DPDK_2.3 { + global: + + rte_cfgfile_section_entries_by_index; +} DPDK_2.0; -- 1.9.1