DPDK patches and discussions
 help / color / mirror / Atom feed
From: Guduri Prathyusha <gprathyusha@caviumnetworks.com>
To: cristian.dumitrescu@intel.com
Cc: dev@dpdk.org, Guduri Prathyusha <gprathyusha@caviumnetworks.com>
Subject: [dpdk-dev] [PATCH] librte_cfgfile: add section num entries by index
Date: Thu, 27 Apr 2017 12:21:40 +0530	[thread overview]
Message-ID: <1493275900-4728-1-git-send-email-gprathyusha@caviumnetworks.com> (raw)

rte_cfgfile_section_num_entries_by_index() is added to get the number of
entries of a section when multiple sections of the same name are
present.

Signed-off-by: Guduri Prathyusha <gprathyusha@caviumnetworks.com>
---
 lib/librte_cfgfile/rte_cfgfile.c |   13 +++++++++++++
 lib/librte_cfgfile/rte_cfgfile.h |   20 ++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c
index b54a523..2588093 100644
--- a/lib/librte_cfgfile/rte_cfgfile.c
+++ b/lib/librte_cfgfile/rte_cfgfile.c
@@ -408,7 +408,20 @@ int rte_cfgfile_close(struct rte_cfgfile *cfg)
 	return s->num_entries;
 }
 
+int
+rte_cfgfile_section_num_entries_by_index(struct rte_cfgfile *cfg,
+	char *sectionname, int index)
+{
+	const struct rte_cfgfile_section *sect;
+
+	if (index < 0 || index >= cfg->num_sections)
+		return -1;
 
+	sect = cfg->sections[index];
+	snprintf(sectionname, CFG_NAME_LEN, "%s", sect->name);
+
+	return sect->num_entries;
+}
 int
 rte_cfgfile_section_entries(struct rte_cfgfile *cfg, const char *sectionname,
 		struct rte_cfgfile_entry *entries, int max_entries)
diff --git a/lib/librte_cfgfile/rte_cfgfile.h b/lib/librte_cfgfile/rte_cfgfile.h
index fa10d40..35dc419 100644
--- a/lib/librte_cfgfile/rte_cfgfile.h
+++ b/lib/librte_cfgfile/rte_cfgfile.h
@@ -184,6 +184,26 @@ int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg,
 	const char *sectionname);
 
 /**
+* Get number of entries in given config file section
+*
+* 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 sectionname
+*   Section name
+* @param index
+*   Section index
+* @return
+*   Number of entries in section on success, -1 otherwise
+*/
+int rte_cfgfile_section_num_entries_by_index(struct rte_cfgfile *cfg,
+	char *sectionname,
+	int index);
+
+/**
 * Get section entries as key-value pairs
 *
 * If multiple sections have the given name this function operates on the
-- 
1.7.9.5

             reply	other threads:[~2017-04-27  6:52 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-27  6:51 Guduri Prathyusha [this message]
2017-07-31 21:10 ` Thomas Monjalon
2017-08-01 12:36   ` Dumitrescu, Cristian
2017-08-01 12:42     ` Thomas Monjalon
2017-09-04  6:12       ` Prathyusha, Guduri
2017-09-04 10:58 ` Bruce Richardson
2017-09-04 11:28   ` Guduri Prathyusha
2017-09-15 13:59   ` Thomas Monjalon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1493275900-4728-1-git-send-email-gprathyusha@caviumnetworks.com \
    --to=gprathyusha@caviumnetworks.com \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).