Skip to contentSkip to conversation

shared/shell: Fix hidden default menu if no submenu

PATCH Applied ERAMOTO Masaya 2 participants 5 messages Dec 11, 2017 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/4 shared/shell: Fix hidden default menu if no submenu

Also fixes the output of the default menu in the help command of obexctl.

---
 src/shared/shell.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
src/shared/shell.c +3 -2
index a4be844b7..f9dbdb194 100644
@@ -198,8 +198,9 @@ static void shell_print_menu(void)
 		/* Skip menu command if not on main menu or if there are no
 		 * submenus.
 		 */
-		if ((data.menu != data.main && !strcmp(entry->cmd, "menu")) ||
-					queue_isempty(data.submenus))
+		if (!strcmp(entry->cmd, "menu") &&
+			(data.menu != data.main ||
+				queue_isempty(data.submenus)))
 			continue;
 
 		/* Skip back command if on main menu */
Signature · 1 line
2.14.1
#1 lore raw

PATCH 2/4 toosl/bluetooth-player: Remove extra commands

Removes the output of redundant commands in bluetooth-player since the previous patch ("shared/shell: Fix hidden default menu if no submenu") made bluetooth-player output the default menu.

---
 tools/bluetooth-player.c | 9 ---------
 1 file changed, 9 deletions(-)
tools/bluetooth-player.c +0 -9
index f819488f3..b22de2775 100644
@@ -49,7 +49,6 @@
 #define BLUEZ_MEDIA_FOLDER_INTERFACE "org.bluez.MediaFolder1"
 #define BLUEZ_MEDIA_ITEM_INTERFACE "org.bluez.MediaItem1"
 
-static GMainLoop *main_loop;
 static DBusConnection *dbus_conn;
 static GDBusProxy *default_player;
 static GSList *players = NULL;
@@ -66,11 +65,6 @@ static void disconnect_handler(DBusConnection *connection, void *user_data)
 	bt_shell_set_prompt(PROMPT_OFF);
 }
 
-static void cmd_quit(int argc, char *argv[])
-{
-	g_main_loop_quit(main_loop);
-}
-
 static bool check_default_player(void)
 {
 	if (!default_player) {
@@ -971,9 +965,6 @@ static const struct bt_shell_menu main_menu = {
 					"Search items containing string" },
 	{ "queue",       "<item>",    cmd_queue, "Add item to playlist queue" },
 	{ "show-item",   "<item>",    cmd_show_item, "Show item information" },
-	{ "quit",         NULL,       cmd_quit, "Quit program" },
-	{ "exit",         NULL,       cmd_quit },
-	{ "help" },
 	{} },
 };
 
Signature · 1 line
2.14.1
#2 lore raw

PATCH 3/4 shared/shell: Create command_isskipped()

In reply to ERAMOTO Masaya
---
 src/shared/shell.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)
src/shared/shell.c +17 -10
index f9dbdb194..26194f758 100644
@@ -169,6 +169,22 @@ static const struct bt_shell_menu_entry default_menu[] = {
 	{ }
 };
 
+static bool command_isskipped(const char *cmd)
+{
+	/* Skip menu command if not on main menu or if there are no
+	 * submenus.
+	 */
+	if (!strcmp(cmd, "menu") &&
+		(data.menu != data.main || queue_isempty(data.submenus)))
+		return true;
+
+	/* Skip back command if on main menu */
+	if (data.menu == data.main && !strcmp(cmd, "back"))
+		return true;
+
+	return false;
+}
+
 static void shell_print_menu(void)
 {
 	const struct bt_shell_menu_entry *entry;
@@ -195,16 +211,7 @@ static void shell_print_menu(void)
 	}
 
 	for (entry = default_menu; entry->cmd; entry++) {
-		/* Skip menu command if not on main menu or if there are no
-		 * submenus.
-		 */
-		if (!strcmp(entry->cmd, "menu") &&
-			(data.menu != data.main ||
-				queue_isempty(data.submenus)))
-			continue;
-
-		/* Skip back command if on main menu */
-		if (data.menu == data.main && !strcmp(entry->cmd, "back"))
+		if (command_isskipped(entry->cmd))
 			continue;
 
 		print_menu(entry->cmd, entry->arg ? : "", entry->desc ? : "");
Signature · 1 line
2.14.1
#3 lore raw

PATCH 4/4 shared/shell: Fix auto-completion of invalid commands

In reply to ERAMOTO Masaya

bt_shell always complements the invalid commands, which are the menu/back command.

---
 src/shared/shell.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/shared/shell.c +1 -1
index 26194f758..f20c74901 100644
@@ -498,7 +498,7 @@ static char *find_cmd(const char *text,
 	while ((cmd = entry[*index].cmd)) {
 		(*index)++;
 
-		if (!strncmp(cmd, text, len))
+		if (!strncmp(cmd, text, len) && !command_isskipped(cmd))
 			return strdup(cmd);
 	}
 
Signature · 1 line
2.14.1
maintainer Applied
#4 lore raw
In reply to ERAMOTO Masaya

Hi Eramoto,

Quoted 22 lines · ERAMOTO Masaya

Also fixes the output of the default menu in the help command of obexctl.

---
 src/shared/shell.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
src/shared/shell.c +3 -3
index a4be844b7..f9dbdb194 100644
@@ -198,8 +198,9 @@ static void shell_print_menu(void)
                /* Skip menu command if not on main menu or if there are no
                 * submenus.
                 */
-               if ((data.menu != data.main && !strcmp(entry->cmd, "menu")) ||
-                                       queue_isempty(data.submenus))
+               if (!strcmp(entry->cmd, "menu") &&
+                       (data.menu != data.main ||
+                               queue_isempty(data.submenus)))
                        continue;
 
                /* Skip back command if on main menu */
--
Quoted 1 line

2.14.1

Applied, thanks.

Signature · 1 line
Luiz Augusto von Dentz