From: Masahiro Yamada <masahiroy@kernel.org>
To: linux-kbuild@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Masahiro Yamada <masahiroy@kernel.org>
Subject: [PATCH 2/3] kconfig: add menu_next() function and menu_for_each(_sub)_entry macros
Date: Sun, 10 Mar 2024 23:16:18 +0900 [thread overview]
Message-ID: <20240310141619.606415-2-masahiroy@kernel.org> (raw)
In-Reply-To: <20240310141619.606415-1-masahiroy@kernel.org>
Several functions require traversing menu entries sequentially. This
commit introduces some helpers to simplify such operations.
The menu_next() function facilitates depth-first traversal:
1. Descend to the child level if the current menu has one
2. Move to the next sibling at the same level if available
3. Ascend to the parent level if there is no more child or sibling
The menu_for_each_sub_entry() macro iterates over all submenu entries
using depth-first traverse.
The menu_for_each_entry() macro is the same, but over all menu entries.
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---
scripts/kconfig/lkc.h | 5 +++++
| 15 +++++++++++++++
2 files changed, 20 insertions(+)
diff --git a/scripts/kconfig/lkc.h b/scripts/kconfig/lkc.h
index e69d7c59d930..5241dccd559e 100644
--- a/scripts/kconfig/lkc.h
+++ b/scripts/kconfig/lkc.h
@@ -79,6 +79,11 @@ void str_printf(struct gstr *gs, const char *fmt, ...);
char *str_get(struct gstr *gs);
/* menu.c */
+struct menu *menu_next(struct menu *menu);
+#define menu_for_each_sub_entry(menu, root) \
+ for (struct menu *menu = (root)->list; menu != (root)->next && menu != (root)->parent; menu = menu_next(menu))
+#define menu_for_each_entry(menu) \
+ menu_for_each_sub_entry(menu, &rootmenu)
void _menu_init(void);
void menu_warn(struct menu *menu, const char *fmt, ...);
struct menu *menu_add_menu(void);
--git a/scripts/kconfig/menu.c b/scripts/kconfig/menu.c
index 8498481e6afe..417dc01ac412 100644
--- a/scripts/kconfig/menu.c
+++ b/scripts/kconfig/menu.c
@@ -17,6 +17,21 @@ static const char nohelp_text[] = "There is no help available for this option.";
struct menu rootmenu;
static struct menu **last_entry_ptr;
+/**
+ * menu_next - return the next menu entry with depth-first traversal
+ * @menu: the pointer to the current menu
+ */
+struct menu *menu_next(struct menu *menu)
+{
+ if (menu->list)
+ return menu->list;
+
+ while (!menu->next && menu->parent)
+ menu = menu->parent;
+
+ return menu->next;
+}
+
void menu_warn(struct menu *menu, const char *fmt, ...)
{
va_list ap;
--
2.40.1
next prev parent reply other threads:[~2024-03-10 14:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-10 14:16 [PATCH 1/3] kconfig: remove unneeded menu_is_visible() call in conf_write_defconfig() Masahiro Yamada
2024-03-10 14:16 ` Masahiro Yamada [this message]
2024-03-10 14:16 ` [PATCH 3/3] kconfig: use menu_for_each_entry() to traverse menu tree Masahiro Yamada
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=20240310141619.606415-2-masahiroy@kernel.org \
--to=masahiroy@kernel.org \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.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