From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pa0-f51.google.com (mail-pa0-f51.google.com [209.85.220.51]) by dpdk.org (Postfix) with ESMTP id BBD8B8D93 for ; Sun, 17 Jan 2016 04:58:59 +0100 (CET) Received: by mail-pa0-f51.google.com with SMTP id uo6so400732227pac.1 for ; Sat, 16 Jan 2016 19:58:59 -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; bh=xTO3rTva7N07rYVxgqnyrQfSBfIDbDkM6iU9sm3p2IM=; b=MBt+cBqLZQEYKoB1Ahw/SzZyEyVo1NgbZJduYuRhHt7gaN98YlqwOIrEywptHMk9Ok uaFSl1E6uJISckMdceKdylfgnAi6EIPGlFr6xx3PdlVn/xa/+uWL/cG04iYmBarZze5G 22wmTepZRzmqcSeXLap6hgOtNy7J9tr8v9IJspGfg4Y8leaTOFNV3roNxESb43wFZDYp KCS/qRVjyetZ8rvgGn0OST5Zpjd/cRJYAxOilzXxXDbkwbzoo0+6vTn3qxBhQ1C/2GQp C3wecp2hYjVWSYj+4NOE1h7ym7JXsr76YrDti+5iWNmdIzGCT2l63qKlt/faho2SFJE9 YSpQ== 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; bh=xTO3rTva7N07rYVxgqnyrQfSBfIDbDkM6iU9sm3p2IM=; b=l6fOdKk9P9mdXxqouiEMFVa4W3TJOI4oM5KHf9BhLyehtgv6Cw/0cFcPTCokgveQf9 2D6V6yTP2YZMtKeJLWMwf5MeLpqg5+jt7EcGTJEtLMWW40sHeN7RgaZ//uKUogj7nkd2 68WbYefUgECE5/z0eTAfD361x0QZtiCiiMkBbNgedlgJYM9iKKCTBOWB87MvK3lSW0DM 3w05/1TGCFuKOjki076c7ADVLJVLJ7nBOgETUs4tLU8dCcF/Qk46RU19PsNu5VBWNBqp bpDogfpTHzTVxZ7IY++yzVrit5vSzX6UpZUPHWZOZydTPAsyIKVWEVnr/OOab2FTEf89 O0zQ== X-Gm-Message-State: ALoCoQnD06nlDxQR1Z8nv6mXNMrB3dSw8YPYBWDcwFpWXud+T/08mx+LvFh5Jdun9naVXpo++CNa+b6XukPBxhVC2pl6wfqR/Q== X-Received: by 10.66.234.8 with SMTP id ua8mr26810316pac.45.1453003139099; Sat, 16 Jan 2016 19:58:59 -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 v71sm24708691pfi.91.2016.01.16.19.58.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 16 Jan 2016 19:58:58 -0800 (PST) From: Rich Lane X-Google-Original-From: Rich Lane To: dev@dpdk.org Date: Sat, 16 Jan 2016 19:58:24 -0800 Message-Id: <1453003104-19107-1-git-send-email-rlane@bigswitch.com> X-Mailer: git-send-email 1.9.1 Subject: [dpdk-dev] [PATCH] 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: Sun, 17 Jan 2016 03:59:00 -0000 This is useful when sections have duplicate names. Signed-off-by: Rich Lane --- 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