From patchwork Thu Apr 7 23:59:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 558920 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 72723C433F5 for ; Thu, 7 Apr 2022 23:59:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232673AbiDHABy (ORCPT ); Thu, 7 Apr 2022 20:01:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58574 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232626AbiDHABx (ORCPT ); Thu, 7 Apr 2022 20:01:53 -0400 Received: from mail-pl1-x62f.google.com (mail-pl1-x62f.google.com [IPv6:2607:f8b0:4864:20::62f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA70619853C for ; Thu, 7 Apr 2022 16:59:51 -0700 (PDT) Received: by mail-pl1-x62f.google.com with SMTP id m16so6472378plx.3 for ; Thu, 07 Apr 2022 16:59:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=aUcOW+b/B0sVL/nrOuOnCZl8YB85FuSY2th6iPJ2wGo=; b=CuKGtU1MeOjeUrKUd9/erYqfDFC8eyDWORurJ7yyd4oZugMT6PZItYtqswE5VptHBn XLkgwzxJPraC/DmnZMpOirUzwQDlQLi9jwojSZBCyE1sHit4wFrRpWSY8ZDe3/cjfMOM rcOuH7m/4cBJmo7itMZRtaJ60BcYWge+DrLJcidxu42Sf4bOLkuE6Z5w4N11zaz6GA2g UiO1hejfMW5sFvjEwoC2DsewcEDbesIfrn+qao3CFMG8pJiCM+C9FTBqBRdXPmG6Zf0H fbT9IDqr8PmkH5H2DMQQ7YxIGetCYdVtpzuDqI+qMhzrHopBwJVVyXNRO00jGQM1nA0t gHDA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=aUcOW+b/B0sVL/nrOuOnCZl8YB85FuSY2th6iPJ2wGo=; b=iZ1qLNLwtyUHlxERB5cvVnwXm28xTgKShbTIfBqVFbClN/MSu511CaOdddTm4fPvJp p3EESqxvaTXkiUjxtqfDQBFmi6W4Mu8PWJUTJBcIxIx96yJpfaYe05op746YvwmQxjuT vF+EMB+puB5YYoITtf4Gro2myU9GzXN8IhJld6GiXEbrnQ51VnUKFCEDvMBoOJesUGR2 RuDD55t+zAAvUtPdBCOrV0Od6nfErquVUGJ9zHw72Wrwu3J/WoeRhg6qiVwKWbLtkOxz GUB/Ygk9pj0jawx8gO8EbzHb8+bg5x3k0BJnHifN7u5zBbF/ausFectTa0aZgoFVs0pN kwYg== X-Gm-Message-State: AOAM532WwC1i1b26UZCODVboxv+wbG0nwK6LSsz/t16k1YdXAUMrVHD2 S7bmpBVtoY9dTKplaqTFLE2Jx3oDWBE= X-Google-Smtp-Source: ABdhPJz8dG0Hjwlc40tgEmXpcS9sp9YNeQTlu2UjURsSxuayX07r852bLQtrzQ4AE80QMrjd+ZpGcA== X-Received: by 2002:a17:902:e84d:b0:156:bf35:6449 with SMTP id t13-20020a170902e84d00b00156bf356449mr16517980plg.26.1649375991064; Thu, 07 Apr 2022 16:59:51 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id bg13-20020a17090b0d8d00b001caa8f51098sm9770532pjb.9.2022.04.07.16.59.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 16:59:50 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/2] shell: Fix not being able to auto complete submenus Date: Thu, 7 Apr 2022 16:59:48 -0700 Message-Id: <20220407235949.2428708-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz submenus should be part of the list of possible auto completes just as other commands. --- src/shared/shell.c | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/src/shared/shell.c b/src/shared/shell.c index 7ba264b99..72232f7c0 100644 --- a/src/shared/shell.c +++ b/src/shared/shell.c @@ -139,14 +139,22 @@ static void cmd_help(int argc, char *argv[]) return bt_shell_noninteractive_quit(EXIT_SUCCESS); } -static const struct bt_shell_menu *find_menu(const char *name, size_t len) +static const struct bt_shell_menu *find_menu(const char *name, size_t len, + int *index) { const struct queue_entry *entry; + int i; - for (entry = queue_get_entries(data.submenus); entry; - entry = entry->next) { + for (i = 0, entry = queue_get_entries(data.submenus); entry; + entry = entry->next, i++) { struct bt_shell_menu *menu = entry->data; + if (index) { + if (i < *index) + continue; + (*index)++; + } + if (!strncmp(menu->name, name, len)) return menu; } @@ -188,7 +196,7 @@ static void cmd_menu(int argc, char *argv[]) return bt_shell_noninteractive_quit(EXIT_FAILURE); } - menu = find_menu(argv[1], strlen(argv[1])); + menu = find_menu(argv[1], strlen(argv[1]), NULL); if (!menu) { bt_shell_printf("Unable find menu with name: %s\n", argv[1]); return bt_shell_noninteractive_quit(EXIT_FAILURE); @@ -485,7 +493,7 @@ static int submenu_exec(int argc, char *argv[]) len = name - argv[0]; name[0] = '\0'; - submenu = find_menu(argv[0], strlen(argv[0])); + submenu = find_menu(argv[0], strlen(argv[0]), NULL); if (!submenu) return -ENOENT; @@ -735,7 +743,7 @@ static char *find_cmd(const char *text, static char *cmd_generator(const char *text, int state) { static int index; - static bool default_menu_enabled, submenu_enabled; + static bool default_menu_enabled, menu_enabled, submenu_enabled; static const struct bt_shell_menu *menu; char *cmd; @@ -754,9 +762,22 @@ static char *cmd_generator(const char *text, int state) index = 0; menu = data.menu; default_menu_enabled = false; + + if (data.main == data.menu) + menu_enabled = true; } } + if (menu_enabled) { + menu = find_menu(text, strlen(text), &index); + if (menu) + return strdup(menu->name); + + index = 0; + menu = data.menu; + menu_enabled = false; + } + if (!submenu_enabled) { cmd = find_cmd(text, menu->entries, &index); if (cmd || menu != data.main) @@ -766,7 +787,7 @@ static char *cmd_generator(const char *text, int state) if (!cmd) return NULL; - menu = find_menu(text, cmd - text); + menu = find_menu(text, cmd - text, NULL); if (!menu) return NULL; From patchwork Thu Apr 7 23:59:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 558591 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2CCD7C433EF for ; Thu, 7 Apr 2022 23:59:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232677AbiDHABy (ORCPT ); Thu, 7 Apr 2022 20:01:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232660AbiDHABx (ORCPT ); Thu, 7 Apr 2022 20:01:53 -0400 Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A731519A546 for ; Thu, 7 Apr 2022 16:59:52 -0700 (PDT) Received: by mail-pl1-x636.google.com with SMTP id n18so6456877plg.5 for ; Thu, 07 Apr 2022 16:59:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=zTCuH7DRWeA6y3m792VByCbnJCSD5d8sPofyL9x7kQk=; b=jJlMefiwH9XgG6NLbjd89JJtvufWluZRXvvlazq9GvdKI6O6a9lz7943d9lgqklf0N /9ly+qeTAsWGUFEZDzraRV5SUNUohgG07btIL/vpC3RVtCzb6YYFlUOGsYuVj4hiqsTg ij8o4B51z8gse8Hu/aMz/PbhKhQKsfMWQvNBSmy9N7g/91N0ISnsih2CGABcCYfGtd4/ 2G0DRlQc9WbjU/hmRgnGq2Qzv4cTexassnb8jluNUY6SoKou2ZJQhQzSwGCEORJF73pt MFGvCyRj6SrzEBznx+9GH3d4bQM8ST2ArRXVCsxRpBc3fr544iu+SJSl4LCiP6hc4aqx ImOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zTCuH7DRWeA6y3m792VByCbnJCSD5d8sPofyL9x7kQk=; b=hYLax5OmW3y/3UHRQy/5Tiobxh++B9Kqm6URmENL49+ECQ/1/FCbOWn2YMHrcVEOGs N3ivMt4HdrGN1Be0F26uED44HltCzh7QL5vEkzhAbJxFkLV669QcFliupj2NrGz49Ach TP9IfAwjSTOElfNuFiQRwXmrLnRy4dhVzGJVtbKczBaasK978Q6M21xEhGk1I7Xi4rSR 47mlo0lKLxUYX6f3VyeEPWcg+XQIA0QbcR1vMwb6ZZBHiQHQXvXV9KeLAoZjRdVaS+5M CrzH5IZkERte2s4npCNU2FbCldmHxY9Dv3OMZWj///tyUBlpqsQSoWM+ZNx1o0rRrCtt ObbA== X-Gm-Message-State: AOAM530T1Lq5Jr+wZgqylixfaNzLgAkespou+bj75v+BAXUYBCc+fhDU wePB4yX9kdRVimzW15C+ns086y+B6EA= X-Google-Smtp-Source: ABdhPJwbci7dgNjYet1+vQ59lGJg2xtf7fy/Fj7f8jR8vIY6KaZQJ99LGaUc2Y+FPw8Yap5BIbLXqg== X-Received: by 2002:a17:902:ce04:b0:156:3be:8a7f with SMTP id k4-20020a170902ce0400b0015603be8a7fmr16029825plg.149.1649375991962; Thu, 07 Apr 2022 16:59:51 -0700 (PDT) Received: from lvondent-mobl4.intel.com (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id bg13-20020a17090b0d8d00b001caa8f51098sm9770532pjb.9.2022.04.07.16.59.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Apr 2022 16:59:51 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/2] shell: Fix not able to auto complete commands with submenu prefix Date: Thu, 7 Apr 2022 16:59:49 -0700 Message-Id: <20220407235949.2428708-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220407235949.2428708-1-luiz.dentz@gmail.com> References: <20220407235949.2428708-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz If the command was given with submenu prefix the code wasn't able to detect the command to be able to generate the auto complete for its arguments. --- src/shared/shell.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/src/shared/shell.c b/src/shared/shell.c index 72232f7c0..dfda8128a 100644 --- a/src/shared/shell.c +++ b/src/shared/shell.c @@ -911,6 +911,26 @@ static char **menu_completion(const struct bt_shell_menu_entry *entry, return matches; } +static char **submenu_completion(const char *text, int argc, char *input_cmd) +{ + const struct bt_shell_menu *menu; + char *cmd; + + if (data.main != data.menu) + return NULL; + + cmd = strrchr(input_cmd, '.'); + if (!cmd) + return NULL; + + menu = find_menu(input_cmd, cmd - input_cmd, NULL); + if (!menu) + return NULL; + + return menu_completion(menu->entries, text, argc, + input_cmd + strlen(menu->name) + 1); +} + static char **shell_completion(const char *text, int start, int end) { char **matches = NULL; @@ -928,10 +948,14 @@ static char **shell_completion(const char *text, int start, int end) matches = menu_completion(default_menu, text, w.we_wordc, w.we_wordv[0]); - if (!matches) + if (!matches) { matches = menu_completion(data.menu->entries, text, w.we_wordc, w.we_wordv[0]); + if (!matches) + matches = submenu_completion(text, w.we_wordc, + w.we_wordv[0]); + } wordfree(&w); } else {