DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] cfgfile: support looking up sections by index
@ 2016-01-17  3:58 Rich Lane
  2016-01-18 12:58 ` Panu Matilainen
  2016-01-19  4:41 ` [dpdk-dev] [PATCH v2] " Rich Lane
  0 siblings, 2 replies; 15+ messages in thread
From: Rich Lane @ 2016-01-17  3:58 UTC (permalink / raw)
  To: dev

This is useful when sections have duplicate names.

Signed-off-by: Rich Lane <rlane@bigswitch.com>
---
 lib/librte_cfgfile/rte_cfgfile.c | 16 ++++++++++++++++
 lib/librte_cfgfile/rte_cfgfile.h | 23 +++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index a677dad..0bb40a4 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 >= 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
-- 
1.9.1

^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2016-02-29 10:30 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-17  3:58 [dpdk-dev] [PATCH] cfgfile: support looking up sections by index Rich Lane
2016-01-18 12:58 ` Panu Matilainen
2016-01-19  4:41 ` [dpdk-dev] [PATCH v2] " Rich Lane
2016-01-21  7:42   ` Panu Matilainen
2016-02-02 15:10   ` Dumitrescu, Cristian
2016-02-10 19:13     ` Rich Lane
2016-02-10 19:12   ` [dpdk-dev] [PATCH v3] " Rich Lane
2016-02-16 20:48     ` Dumitrescu, Cristian
2016-02-16 22:58     ` [dpdk-dev] [PATCH v4] " Rich Lane
2016-02-19 15:18       ` Dumitrescu, Cristian
2016-02-22 20:30       ` [dpdk-dev] [PATCH v5] " Rich Lane
2016-02-23  0:12         ` Dumitrescu, Cristian
2016-02-25 20:43         ` [dpdk-dev] [PATCH v6] " Rich Lane
2016-02-25 20:49           ` Dumitrescu, Cristian
2016-02-29 10:29             ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).