From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f52.google.com (mail-pa0-f52.google.com [209.85.220.52]) by dpdk.org (Postfix) with ESMTP id 1648258E4 for ; Tue, 19 Jan 2016 05:42:03 +0100 (CET) Received: by mail-pa0-f52.google.com with SMTP id ho8so183818798pac.2 for ; Mon, 18 Jan 2016 20:42:03 -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=6QEoNbHZzfyLFzCZ+JS+jztMxj403fFMw9M0l16xEEo=; b=0mSSsITZe8gy22eAE8wViFGgagmzspdVa5/LAFAg3rGzenFD6tjRegoQiWNiBOmJLa 4Ch8GJoo82S1hLUom4UeZcZgn7xwJ+ANedmXU4VKOiTnKNAhU8mNhGWqtMo9jbwkY3XM /0SM48a7ox757py7jRwVHWCNEG1PukY3i/F5ZuBx+1pof/DJqRN9Pl1bXgxdK95Zou4G mMcTfqXX2IJbYWvzrWXNd4l41Gnl9WRhn1Wx0cgqfFbvQwcY5948V1b7wXK1odjvwxj2 oUgk4q1dsgr8YUiVdyC159rRE9W2wJpIy13xkA18tb+bf8v0eMEd8d4WuKdEAeN3XpRJ dD+g== 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=6QEoNbHZzfyLFzCZ+JS+jztMxj403fFMw9M0l16xEEo=; b=Xt+Tj1OfAGwgm8wjeXbXCMTNocdYrOiJZJ7HwNowYlUkuLXEC8KzS+M2URMp7Fqitg PpHey6aeOZSXaOyfEYtI8BhdJmGNwEWCiJN4zyhD3UWwBaUYtPMPbQ6YMi1PD9230yzv IWlc+kHncxo6nZG30idjIO2hXw4Su3U3Gan1CYTlaJgZyjJCU9wV9wecba8Lu2KFVSnh FlrNznV21BKTm+ndxzReHruorHJO+gsWvWa59BnY9F+t8Lbhd29rrpC8T44xdY6Z98wr svtBq8LF2nIMQKPspAUDK2KUresiN5SfprKAW4RRvvJMklMc0JPLAUls654C4ig6fb9k 4VYA== X-Gm-Message-State: ALoCoQk0Y7eEjuON86JjrhEJRdDdzbxh0kMngVaj7dNgrGOO1n+O2rlLrpz+DoNEMs9PN7gSbXiV/rMsBOrQyopQwLFyBDu0BA== X-Received: by 10.66.187.145 with SMTP id fs17mr41463342pac.81.1453178522291; Mon, 18 Jan 2016 20:42:02 -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 ah10sm37709089pad.23.2016.01.18.20.42.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 18 Jan 2016 20:42:01 -0800 (PST) From: Rich Lane X-Google-Original-From: Rich Lane To: dev@dpdk.org Date: Mon, 18 Jan 2016 20:41:50 -0800 Message-Id: <1453178510-113435-1-git-send-email-rlane@bigswitch.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453003104-19107-1-git-send-email-rlane@bigswitch.com> References: <1453003104-19107-1-git-send-email-rlane@bigswitch.com> Subject: [dpdk-dev] [PATCH v2] 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: Tue, 19 Jan 2016 04:42:03 -0000 This is useful when sections have duplicate names. Signed-off-by: Rich Lane --- 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..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 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