From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f43.google.com (mail-pa0-f43.google.com [209.85.220.43]) by dpdk.org (Postfix) with ESMTP id EDAA72B9C for ; Thu, 25 Feb 2016 21:43:18 +0100 (CET) Received: by mail-pa0-f43.google.com with SMTP id fl4so37929768pad.0 for ; Thu, 25 Feb 2016 12:43:18 -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=C9UrfrDw3m9MWshhFbs/V2uqyt2i4XScVQgoPei0qU8=; b=I20aGmi+FLFZCftzspxO8JTeG9KABzQ8EG4HAukgL0n9xv8pHNvqhrtXq/+sTFLIyN 6iTYl4TdyjmXYWehTXG5cO1icuRPSWmSzcHonlDbKrEeyTj+mLgO68hEE5Uh+w4J83Ru RiqRPtYpZwB5g5x1fjfXB3jMiz6XUEuTepL+/EWniGNirnW7NyP1w2jE4DHt7J/U5/CF ZqQjsHsik/myzzqBmbacubzlTrOKg4u0xL4jsIvI6qwIEmhbUGg4plitpo2yUoiTtoLt xYcXqFuPnLOL5zJd7rYHo05sTejDvN75Pvcz5P8YhweVzE1Uv/vy6vMwvxGOH2Faw8gy hvSg== 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=C9UrfrDw3m9MWshhFbs/V2uqyt2i4XScVQgoPei0qU8=; b=RXw88SwETIZPw6BfCtIG17BzZobVEPLUF6w2stZCApfB0g2f/7/Q9vlUWWF3ABd7Gi TwXPc/2WeScyIfd1X6Y/tDYwPLxYoXGmDMrGd+sb+7iTFpguHv+9psH1phNcEDo4MdWh weKe0R9ZEzFjMpw3D0XMdlren+mvvKpJM9lQlr2pya6YqcI7zAAxVWUixQlZ1jdTyCSV qwazfumwePCa0GqDn7Wc0NfqcV8FIBzmx4FqzVFRSEpePKewzsp50oXYB1eZnfJwZwXd Bn2uS7X8bpcOPK4quVRuwm01djf/Jqn6kgU1tlQecOvwUj04KmuSDer2X8E5P3Hd8P6j 7C7Q== X-Gm-Message-State: AG10YOT2ZRTaXfVsGpCRXHJyxIcchZTPJwIwe/moZ73T9QpgSwSqq0Pkpqb9Rja+OYxft1e7 X-Received: by 10.66.124.170 with SMTP id mj10mr65958335pab.92.1456432998212; Thu, 25 Feb 2016 12:43:18 -0800 (PST) Received: from rlane-work.eng.bigswitch.com ([173.227.38.50]) by smtp.gmail.com with ESMTPSA id 144sm14161594pfa.83.2016.02.25.12.43.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Feb 2016 12:43:17 -0800 (PST) From: Rich Lane X-Google-Original-From: Rich Lane To: dev@dpdk.org Date: Thu, 25 Feb 2016 12:43:03 -0800 Message-Id: <1456432983-2152-1-git-send-email-rlane@bigswitch.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1456173039-23175-1-git-send-email-rlane@bigswitch.com> References: <1456173039-23175-1-git-send-email-rlane@bigswitch.com> Subject: [dpdk-dev] [PATCH v6] 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: Thu, 25 Feb 2016 20:43:19 -0000 This is useful when sections have duplicate names. Signed-off-by: Rich Lane --- v5->v6: - Reordered sectionname argument in comment. v4->v5: - Reordered sectionname argument. v3->v4: - Added section name return value. - Updated API docs for other functions. v2->v3 - Added check for index < 0. v1->v2: - Added new symbol to version script. lib/librte_cfgfile/rte_cfgfile.c | 18 ++++++++++++++ lib/librte_cfgfile/rte_cfgfile.h | 39 ++++++++++++++++++++++++++++++ lib/librte_cfgfile/rte_cfgfile_version.map | 6 +++++ 3 files changed, 63 insertions(+) diff --git a/lib/librte_cfgfile/rte_cfgfile.c b/lib/librte_cfgfile/rte_cfgfile.c index 1cd523f..75625a2 100644 --- a/lib/librte_cfgfile/rte_cfgfile.c +++ b/lib/librte_cfgfile/rte_cfgfile.c @@ -333,6 +333,24 @@ 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, + char *sectionname, + 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]; + snprintf(sectionname, CFG_NAME_LEN, "%s", sect->name); + 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..834f828 100644 --- a/lib/librte_cfgfile/rte_cfgfile.h +++ b/lib/librte_cfgfile/rte_cfgfile.h @@ -126,6 +126,9 @@ int rte_cfgfile_has_section(struct rte_cfgfile *cfg, const char *sectionname); /** * Get number of entries in given config file section * +* If multiple sections have the given name this function operates on the +* first one. +* * @param cfg * Config file * @param sectionname @@ -138,6 +141,9 @@ int rte_cfgfile_section_num_entries(struct rte_cfgfile *cfg, /** Get section entries as key-value pairs * +* If multiple sections have the given name this function operates on the +* first one. +* * @param cfg * Config file * @param sectionname @@ -155,8 +161,38 @@ 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 sectionname +* Pre-allocated string of at least CFG_NAME_LEN characters where the +* section name is stored after successful invocation. +* @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, + char *sectionname, + struct rte_cfgfile_entry *entries, + int max_entries); + /** Get value of the named entry in named config file section * +* If multiple sections have the given name this function operates on the +* first one. +* * @param cfg * Config file * @param sectionname @@ -172,6 +208,9 @@ const char *rte_cfgfile_get_entry(struct rte_cfgfile *cfg, /** Check if given entry exists in named config file section * +* If multiple sections have the given name this function operates on the +* first one. +* * @param cfg * Config file * @param sectionname 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