Skip to contentSkip to conversation

kconfig: Create links to main menu items in search

PATCH Superseded Ariel Marcovitch 2 participants 4 messages Sep 1, 2021 – Sep 12, 2021

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kconfig: Create links to main menu items in search

When one searches for a main menu item, links aren't created for it like with the rest of the symbols.

This happens because we trace the item until we get to the rootmenu, but we don't include it in the path of the item. The rationale was probably that we don't want to show the main menu in the path of all items, because it is redundant.

However, when an item has only the rootmenu in its path it should be included, because this way the user can jump to its location.

In case the item is a direct child of the rootmenu, show it in the 'Location:' section as 'Main Menu'.

This makes the 'if (i > 0)' superfluous because each item with prompt will have at least one menu in its path.

---
 scripts/kconfig/menu.c | 40 ++++++++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 14 deletions(-)
scripts/kconfig/menu.c +26 -14
index 606ba8a63c24..8d7e3b07bf93 100644
@@ -712,6 +712,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
 	int i, j;
 	struct menu *submenu[8], *menu, *location = NULL;
 	struct jump_key *jump = NULL;
+	const char *prompt = NULL;
 
 	str_printf(r, "  Prompt: %s\n", prop->text);
 
@@ -735,6 +736,13 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
 		if (location == NULL && accessible)
 			location = menu;
 	}
+
+	/* If we have only the root menu, show it */
+	if (i == 0) {
+		location = &rootmenu;
+		submenu[i++] = location;
+	}
+
 	if (head && location) {
 		jump = xmalloc(sizeof(struct jump_key));
 
@@ -758,21 +766,25 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
 		list_add_tail(&jump->entries, head);
 	}
 
-	if (i > 0) {
-		str_printf(r, "  Location:\n");
-		for (j = 4; --i >= 0; j += 2) {
-			menu = submenu[i];
-			if (jump && menu == location)
-				jump->offset = strlen(r->s);
-			str_printf(r, "%*c-> %s", j, ' ',
-				   menu_get_prompt(menu));
-			if (menu->sym) {
-				str_printf(r, " (%s [=%s])", menu->sym->name ?
-					menu->sym->name : "<choice>",
-					sym_get_string_value(menu->sym));
-			}
-			str_append(r, "\n");
+	str_printf(r, "  Location:\n");
+	for (j = 4; --i >= 0; j += 2) {
+		menu = submenu[i];
+		if (jump && menu == location)
+			jump->offset = strlen(r->s);
+
+		/* The real rootmenu prompt is ugly */
+		if (menu == &rootmenu)
+			prompt = "Main Menu";
+		else
+			prompt = menu_get_prompt(menu);
+
+		str_printf(r, "%*c-> %s", j, ' ', prompt);
+		if (menu->sym) {
+			str_printf(r, " (%s [=%s])", menu->sym->name ?
+				menu->sym->name : "<choice>",
+				sym_get_string_value(menu->sym));
 		}
+		str_append(r, "\n");
 	}
 }
 

base-commit: 087e856cfb76e9eef9a3a6e000854794f3c36e24

Signature · 1 line
2.25.1
#1 lore raw
Quoted 28 lines · Ariel Marcovitch

When one searches for a main menu item, links aren't created for it like with the rest of the symbols.

This happens because we trace the item until we get to the rootmenu, but we don't include it in the path of the item. The rationale was probably that we don't want to show the main menu in the path of all items, because it is redundant.

However, when an item has only the rootmenu in its path it should be included, because this way the user can jump to its location.

In case the item is a direct child of the rootmenu, show it in the 'Location:' section as 'Main Menu'.

This makes the 'if (i > 0)' superfluous because each item with prompt will have at least one menu in its path.

---
 scripts/kconfig/menu.c | 40 ++++++++++++++++++++++++++--------------
 1 file changed, 26 insertions(+), 14 deletions(-)
scripts/kconfig/menu.c +0 -0
index 606ba8a63c24..8d7e3b07bf93 100644

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct property *prop, · line 715

Quoted 4 lines
scripts/kconfig/menu.c +1 -0
@@ -712,6 +712,7 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
        int i, j;
        struct menu *submenu[8], *menu, *location = NULL;
        struct jump_key *jump = NULL;
+       const char *prompt = NULL;

Can you move this to the for-loop ?

The initializer is unneeded.

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct property *prop, · line 744

Quoted 13 lines
scripts/kconfig/menu.c +6 -0
        str_printf(r, "  Prompt: %s\n", prop->text);
 
@@ -735,6 +736,13 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
                if (location == NULL && accessible)
                        location = menu;
        }
+
+       /* If we have only the root menu, show it */
+       if (i == 0) {
+               location = &rootmenu;
+               submenu[i++] = location;
+       }

Instead of handling this as a special case,
can we include the rootmenu all the time?

We can change the for-loop condition to:

        for (i = 0; menu && i < 8; menu = menu->parent) {
Quoted 20 lines
scripts/kconfig/menu.c +0 -13
        if (head && location) {
                jump = xmalloc(sizeof(struct jump_key));
 
@@ -758,21 +766,25 @@ static void get_prompt_str(struct gstr *r, struct property *prop,
                list_add_tail(&jump->entries, head);
        }
 
-       if (i > 0) {
-               str_printf(r, "  Location:\n");
-               for (j = 4; --i >= 0; j += 2) {
-                       menu = submenu[i];
-                       if (jump && menu == location)
-                               jump->offset = strlen(r->s);
-                       str_printf(r, "%*c-> %s", j, ' ',
-                                  menu_get_prompt(menu));
-                       if (menu->sym) {
-                               str_printf(r, " (%s [=%s])", menu->sym->name ?
-                                       menu->sym->name : "<choice>",
-                                       sym_get_string_value(menu->sym));
-                       }

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct property *prop, · line 777

Quoted 10 lines
scripts/kconfig/menu.c +9 -1
-                       str_append(r, "\n");
+       str_printf(r, "  Location:\n");
+       for (j = 4; --i >= 0; j += 2) {
+               menu = submenu[i];
+               if (jump && menu == location)
+                       jump->offset = strlen(r->s);
+
+               /* The real rootmenu prompt is ugly */
+               if (menu == &rootmenu)
+                       prompt = "Main Menu";

Can you use "Main menu" for the consistency
with scripts/kconfig/parser.y line 501?

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct property *prop, · line 779

Quoted 2 lines
scripts/kconfig/menu.c +2 -0
+               else
+                       prompt = menu_get_prompt(menu);

I think it is better to omit '->' for the rootmenu.

               if (menu == &rootmenu) {
                       prompt = "Main menu";
                       marker = "";
               } else {
                       prompt = menu_get_prompt(menu);
                       marker = "->";
               }

               str_printf(r, "%*c%s %s", j, ' ', marker, prompt);

Maybe, this will make the help look cleaner.

Quoted 11 lines
scripts/kconfig/menu.c +6 -0
+               str_printf(r, "%*c-> %s", j, ' ', prompt);
+               if (menu->sym) {
+                       str_printf(r, " (%s [=%s])", menu->sym->name ?
+                               menu->sym->name : "<choice>",
+                               sym_get_string_value(menu->sym));
                }
+               str_append(r, "\n");
        }
 }
 
Quoted 4 lines

base-commit: 087e856cfb76e9eef9a3a6e000854794f3c36e24 --
2.25.1

--
Best Regards

Masahiro Yamada

#2 lore raw
Quoted 25 lines · Masahiro Yamada
Quoted 23 lines · Ariel Marcovitch

When one searches for a main menu item, links aren't created for it like with the rest of the symbols.

This happens because we trace the item until we get to the rootmenu, but we don't include it in the path of the item. The rationale was probably that we don't want to show the main menu in the path of all items, because it is redundant.

However, when an item has only the rootmenu in its path it should be included, because this way the user can jump to its location.

In case the item is a direct child of the rootmenu, show it in the 'Location:' section as 'Main Menu'.

This makes the 'if (i > 0)' superfluous because each item with prompt will have at least one menu in its path.

---
scripts/kconfig/menu.c | 40 ++++++++++++++++++++++++++--------------

1 file changed, 26 insertions(+), 14 deletions(-)
Quoted 5 lines

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct

Quoted 5 lines
scripts/kconfig/menu.c +0 -0
index 606ba8a63c24..8d7e3b07bf93 100644
@@ -712,6 +712,7 @@ static void get_prompt_str(struct gstr *r, struct 

property *prop,

Quoted 8 lines

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct property *prop, · line 715

Quoted 4 lines
scripts/kconfig/menu.c +1 -0
 int i, j;
 struct menu *submenu[8], *menu, *location = NULL;
 struct jump_key *jump = NULL;
+const char *prompt = NULL;

Can you move this to the for-loop ?

Quoted 7 lines

The initializer is unneeded.

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct

Quoted 4 lines
scripts/kconfig/menu.c +0 -0
 str_printf(r, " Prompt: %s\n", prop->text);
 
@@ -735,6 +736,13 @@ static void get_prompt_str(struct gstr *r, struct 

property *prop,

Quoted 14 lines

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct property *prop, · line 744

Quoted 9 lines
scripts/kconfig/menu.c +6 -0
 if (location == NULL && accessible)
 location = menu;
 }
+
+/* If we have only the root menu, show it */
+if (i == 0) {
+location = &rootmenu;
+submenu[i++] = location;
+}

Instead of handling this as a special case, can we include the rootmenu all the time?

Quoted 3 lines

We can change the for-loop condition to:

for (i = 0; menu && i < 8; menu = menu->parent) {

Of course.
However, it means search entries will get a bit larger. I guess it is worth it?

Quoted 11 lines

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct

Quoted 11 lines
scripts/kconfig/menu.c +0 -0
 if (head && location) {
 jump = xmalloc(sizeof(struct jump_key));
 
@@ -758,21 +766,25 @@ static void get_prompt_str(struct gstr *r, struct 

property *prop,

Quoted 21 lines
Quoted 21 lines
scripts/kconfig/menu.c +4 -14
 list_add_tail(&jump->entries, head);
 }
 
-if (i > 0) {
-str_printf(r, " Location:\n");
-for (j = 4; --i >= 0; j += 2) {
-menu = submenu[i];
-if (jump && menu == location)
-jump->offset = strlen(r->s);
-str_printf(r, "%*c-> %s", j, ' ',
-menu_get_prompt(menu));
-if (menu->sym) {
-str_printf(r, " (%s [=%s])", menu->sym->name ?
-menu->sym->name : "<choice>",
-sym_get_string_value(menu->sym));
-}
-str_append(r, "\n");
+str_printf(r, " Location:\n");
+for (j = 4; --i >= 0; j += 2) {
+menu = submenu[i];
+if (jump && menu == location)
Quoted 9 lines

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct property *prop, · line 777

Quoted 5 lines
scripts/kconfig/menu.c +5 -0
+jump->offset = strlen(r->s);
+
+/* The real rootmenu prompt is ugly */
+if (menu == &rootmenu)
+prompt = "Main Menu";

Can you use "Main menu" for the consistency with scripts/kconfig/parser.y line 501?

Seems reasonable. Just to clarify, the prompt there is not relevant for linux's Kconfig right?

Quoted 16 lines

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct property *prop, · line 779

Quoted 3 lines
scripts/kconfig/menu.c +2 -0
+else
+prompt = menu_get_prompt(menu);

I think it is better to omit '->' for the rootmenu.

if (menu == &rootmenu) {
prompt = "Main menu";
marker = "";
} else {
prompt = menu_get_prompt(menu); marker = "->";
}

Quoted 2 lines

str_printf(r, "%*c%s %s", j, ' ', marker, prompt);

Perhaps it will be better to split to separate printfs? I think it will be cleaner. It will make the extra vars unneeded as well. Also, the results look a bit weird... maybe we should use a different marker for rootmenu, like '--' or something?

Quoted 28 lines

Maybe, this will make the help look cleaner.

Quoted 11 lines
scripts/kconfig/menu.c +6 -0
+str_printf(r, "%*c-> %s", j, ' ', prompt);
+if (menu->sym) {
+str_printf(r, " (%s [=%s])", menu->sym->name ?
+menu->sym->name : "<choice>",
+sym_get_string_value(menu->sym));
 }
+str_append(r, "\n");
 }
 }
 
Quoted 4 lines

base-commit: 087e856cfb76e9eef9a3a6e000854794f3c36e24 --
2.25.1

--
Best Regards

Quoted 1 line

Masahiro Yamada

Thanks for the comments :)
Ariel Marcovitch

#3 lore raw
Quoted 63 lines · Ariel Marcovitch
Quoted 25 lines · Masahiro Yamada
Quoted 23 lines · Ariel Marcovitch

When one searches for a main menu item, links aren't created for it like with the rest of the symbols.

This happens because we trace the item until we get to the rootmenu, but we don't include it in the path of the item. The rationale was probably that we don't want to show the main menu in the path of all items, because it is redundant.

However, when an item has only the rootmenu in its path it should be included, because this way the user can jump to its location.

In case the item is a direct child of the rootmenu, show it in the 'Location:' section as 'Main Menu'.

This makes the 'if (i > 0)' superfluous because each item with prompt will have at least one menu in its path.

---
scripts/kconfig/menu.c | 40 ++++++++++++++++++++++++++--------------

1 file changed, 26 insertions(+), 14 deletions(-)
Quoted 5 lines

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct

Quoted 5 lines
scripts/kconfig/menu.c +0 -0
index 606ba8a63c24..8d7e3b07bf93 100644
@@ -712,6 +712,7 @@ static void get_prompt_str(struct gstr *r, struct

property *prop,

Quoted 8 lines

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct property *prop, · line 715

Quoted 4 lines
scripts/kconfig/menu.c +1 -0
 int i, j;
 struct menu *submenu[8], *menu, *location = NULL;
 struct jump_key *jump = NULL;
+const char *prompt = NULL;

Can you move this to the for-loop ?

Quoted 7 lines

The initializer is unneeded.

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct

Quoted 4 lines
scripts/kconfig/menu.c +0 -0
 str_printf(r, " Prompt: %s\n", prop->text);
 
@@ -735,6 +736,13 @@ static void get_prompt_str(struct gstr *r, struct

property *prop,

Quoted 14 lines

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct property *prop, · line 744

Quoted 9 lines
scripts/kconfig/menu.c +6 -0
 if (location == NULL && accessible)
 location = menu;
 }
+
+/* If we have only the root menu, show it */
+if (i == 0) {
+location = &rootmenu;
+submenu[i++] = location;
+}

Instead of handling this as a special case, can we include the rootmenu all the time?

Quoted 6 lines
Quoted 3 lines

We can change the for-loop condition to:

for (i = 0; menu && i < 8; menu = menu->parent) {

Of course.
However, it means search entries will get a bit larger. I guess it is worth it?

I think so.
The result is more consistent.

Quoted 60 lines
Quoted 11 lines

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct

Quoted 11 lines
scripts/kconfig/menu.c +0 -0
 if (head && location) {
 jump = xmalloc(sizeof(struct jump_key));
 
@@ -758,21 +766,25 @@ static void get_prompt_str(struct gstr *r, struct

property *prop,

Quoted 21 lines
Quoted 21 lines
scripts/kconfig/menu.c +4 -14
 list_add_tail(&jump->entries, head);
 }
 
-if (i > 0) {
-str_printf(r, " Location:\n");
-for (j = 4; --i >= 0; j += 2) {
-menu = submenu[i];
-if (jump && menu == location)
-jump->offset = strlen(r->s);
-str_printf(r, "%*c-> %s", j, ' ',
-menu_get_prompt(menu));
-if (menu->sym) {
-str_printf(r, " (%s [=%s])", menu->sym->name ?
-menu->sym->name : "<choice>",
-sym_get_string_value(menu->sym));
-}
-str_append(r, "\n");
+str_printf(r, " Location:\n");
+for (j = 4; --i >= 0; j += 2) {
+menu = submenu[i];
+if (jump && menu == location)
Quoted 9 lines

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct property *prop, · line 777

Quoted 5 lines
scripts/kconfig/menu.c +5 -0
+jump->offset = strlen(r->s);
+
+/* The real rootmenu prompt is ugly */
+if (menu == &rootmenu)
+prompt = "Main Menu";

Can you use "Main menu" for the consistency with scripts/kconfig/parser.y line 501?

Seems reasonable. Just to clarify, the prompt there is not relevant for linux's Kconfig right?

Quoted 16 lines

scripts/kconfig/menu.c static void get_prompt_str(struct gstr *r, struct property *prop, · line 779

Quoted 3 lines
scripts/kconfig/menu.c +2 -0
+else
+prompt = menu_get_prompt(menu);

I think it is better to omit '->' for the rootmenu.

if (menu == &rootmenu) {
prompt = "Main menu";
marker = "";
} else {
prompt = menu_get_prompt(menu); marker = "->";
}

Quoted 4 lines
Quoted 2 lines

str_printf(r, "%*c%s %s", j, ' ', marker, prompt);

Perhaps it will be better to split to separate printfs? I think it will be cleaner. It will make the extra vars unneeded as well.

I am fine with it.

Quoted 2 lines

Also, the results look a bit weird... maybe we should use a different marker for rootmenu, like '--' or something?

How does it look weird?

Quoted 31 lines
Quoted 28 lines

Maybe, this will make the help look cleaner.

Quoted 11 lines
scripts/kconfig/menu.c +6 -0
+str_printf(r, "%*c-> %s", j, ' ', prompt);
+if (menu->sym) {
+str_printf(r, " (%s [=%s])", menu->sym->name ?
+menu->sym->name : "<choice>",
+sym_get_string_value(menu->sym));
 }
+str_append(r, "\n");
 }
 }
 
Quoted 4 lines

base-commit: 087e856cfb76e9eef9a3a6e000854794f3c36e24 --
2.25.1

--
Best Regards

Quoted 1 line

Masahiro Yamada

Thanks for the comments :)
Ariel Marcovitch

Signature · 2 lines
Best Regards
Masahiro Yamada