Re: [PATCH BlueZ] shared/shell: Fix command completion without character

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Eramoto,

On Tue, Nov 21, 2017 at 9:14 AM, ERAMOTO Masaya
<eramoto.masaya@xxxxxxxxxxxxxx> wrote:
> If the command completion without any character is run, then only returns
> the commands of default menu since readline increases the variable state
> during each matching and tools specific menu is not compared.
> ---
>  src/shared/shell.c | 44 +++++++++++++++++++++++++++++---------------
>  1 file changed, 29 insertions(+), 15 deletions(-)
>
> diff --git a/src/shared/shell.c b/src/shared/shell.c
> index 378c0c029..c271a53ee 100644
> --- a/src/shared/shell.c
> +++ b/src/shared/shell.c
> @@ -390,32 +390,46 @@ done:
>         free(input);
>  }
>
> -static char *cmd_generator(const char *text, int state)
> +static char *find_cmd(const char *text,
> +                       const struct bt_shell_menu_entry *entry, int *index)
>  {
> -       static const struct bt_shell_menu_entry *entry;
> -       static int index, len;
>         const char *cmd;
> +       int len;
>
> -       if (!state) {
> -               entry = default_menu;
> -               index = 0;
> -               len = strlen(text);
> -       }
> +       len = strlen(text);
>
> -       while ((cmd = entry[index].cmd)) {
> -               index++;
> +       while ((cmd = entry[*index].cmd)) {
> +               (*index)++;
>
>                 if (!strncmp(cmd, text, len))
>                         return strdup(cmd);
>         }
>
> -       if (state)
> -               return NULL;
> +       return NULL;
> +}
>
> -       entry = data.menu->entries;
> -       index = 0;
> +static char *cmd_generator(const char *text, int state)
> +{
> +       static int index;
> +       static bool default_menu_enabled;
> +       char *cmd;
> +
> +       if (!state) {
> +               index = 0;
> +               default_menu_enabled = true;
> +       }
> +
> +       if (default_menu_enabled) {
> +               cmd = find_cmd(text, default_menu, &index);
> +               if (cmd) {
> +                       return cmd;
> +               } else {
> +                       index = 0;
> +                       default_menu_enabled = false;
> +               }
> +       }
>
> -       return cmd_generator(text, 1);
> +       return find_cmd(text, data.menu->entries, &index);
>  }
>
>  static char **menu_completion(const struct bt_shell_menu_entry *entry,
> --
> 2.14.1

Applied, thanks.

-- 
Luiz Augusto von Dentz
--
To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux