linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: Marcin Kraglak <marcin.kraglak@tieto.com>
Cc: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: Re: [PATCH 4/4] client: Use bt_shell_completion
Date: Fri, 22 Sep 2017 11:09:19 +0300	[thread overview]
Message-ID: <CABBYNZLgGqV8ZJY740wXncFOROAMiR8LqLLh2qeiDoB-Na5AxA@mail.gmail.com> (raw)
In-Reply-To: <CABD6X-LAqGH6r5-OnSmGSxEi=fP-YFU9ssHYb0vO=v+mGdGo8A@mail.gmail.com>

Hi Marcin,

On Fri, Sep 22, 2017 at 11:00 AM, Marcin Kraglak
<marcin.kraglak@tieto.com> wrote:
> Hi Luiz,
>
> On 22 September 2017 at 03:47, Luiz Augusto von Dentz
> <luiz.dentz@gmail.com> wrote:
>> Hi Marcin,
>>
>> On Fri, Sep 22, 2017 at 8:00 AM, Marcin Kraglak
>> <marcin.kraglak@tieto.com> wrote:
>>> ---
>>>  client/main.c | 49 +------------------------------------------------
>>>  1 file changed, 1 insertion(+), 48 deletions(-)
>>>
>>> diff --git a/client/main.c b/client/main.c
>>> index 87019b463..86514f67e 100644
>>> --- a/client/main.c
>>> +++ b/client/main.c
>>> @@ -2564,61 +2564,14 @@ static const struct bt_shell_menu_entry cmd_table[] = {
>>>         { }
>>>  };
>>>
>>> -static char *cmd_generator(const char *text, int state)
>>> -{
>>> -       static int index, len;
>>> -       const char *cmd;
>>> -
>>> -       if (!state) {
>>> -               index = 0;
>>> -               len = strlen(text);
>>> -       }
>>> -
>>> -       while ((cmd = cmd_table[index].cmd)) {
>>> -               index++;
>>> -
>>> -               if (!strncmp(cmd, text, len))
>>> -                       return strdup(cmd);
>>> -       }
>>> -
>>> -       return NULL;
>>> -}
>>> -
>>>  static char **cmd_completion(const char *text, int start, int end)
>>>  {
>>> -       char **matches = NULL;
>>> -
>>>         if (agent_completion() == TRUE) {
>>>                 rl_attempted_completion_over = 1;
>>>                 return NULL;
>>>         }
>>>
>>> -       if (start > 0) {
>>> -               int i;
>>> -               char *input_cmd;
>>> -
>>> -               input_cmd = g_strndup(rl_line_buffer, start -1);
>>> -               for (i = 0; cmd_table[i].cmd; i++) {
>>> -                       if (strcmp(cmd_table[i].cmd, input_cmd))
>>> -                               continue;
>>> -
>>> -                       if (!cmd_table[i].gen)
>>> -                               continue;
>>> -
>>> -                       rl_completion_display_matches_hook = cmd_table[i].disp;
>>> -                       matches = rl_completion_matches(text, cmd_table[i].gen);
>>> -                       break;
>>> -               }
>>> -               g_free(input_cmd);
>>> -       } else {
>>> -               rl_completion_display_matches_hook = NULL;
>>> -               matches = rl_completion_matches(text, cmd_generator);
>>> -       }
>>> -
>>> -       if (!matches)
>>> -               rl_attempted_completion_over = 1;
>>> -
>>> -       return matches;
>>> +       return bt_shell_completion(text, start, end);
>>>  }
>>
>> While this is great as we reuse more code I think we better move the
>> whole input handling into the bt_shell so the application don't even
>> need to call bt_shell_completion, etc.

Not only that but the entire readline setup including
rl_callback_handler_install which means the tools don't really need to
use readline functions just bt_shell.
>> --
>> Luiz Augusto von Dentz
>
> You mean bt_shell should set rl_attempted_completion_function in
> bt_shell_init() (then bt_shell_completion is not exposed)?
>
>
>
> --
> BR
> Marcin Kraglak



-- 
Luiz Augusto von Dentz

  reply	other threads:[~2017-09-22  8:09 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-22  4:59 [PATCH 0/4] Move common client code to bt_shell Marcin Kraglak
2017-09-22  4:59 ` [PATCH 1/4] shared/bt_shell: Add initial implementation Marcin Kraglak
2017-09-22  6:27   ` ERAMOTO Masaya
2017-09-22  7:42     ` Luiz Augusto von Dentz
2017-09-22  7:52       ` Marcin Kraglak
2017-10-23 11:42         ` Luiz Augusto von Dentz
2017-11-06 13:24           ` Marcin Kraglak
2017-11-06 13:25             ` Luiz Augusto von Dentz
2017-11-06 13:52               ` Marcel Holtmann
2017-11-06 13:59                 ` Luiz Augusto von Dentz
2017-09-22  5:00 ` [PATCH 2/4] client: Use bt_shell to process commands Marcin Kraglak
2017-09-22  5:00 ` [PATCH 3/4] shared/bt_shell: Add bt_shell_completion Marcin Kraglak
2017-09-22  5:00 ` [PATCH 4/4] client: Use bt_shell_completion Marcin Kraglak
2017-09-22  7:47   ` Luiz Augusto von Dentz
2017-09-22  8:00     ` Marcin Kraglak
2017-09-22  8:09       ` Luiz Augusto von Dentz [this message]
2017-11-06 12:34 ` [PATCH 0/4] Move common client code to bt_shell Luiz Augusto von Dentz
  -- strict thread matches above, loose matches on Subject: below --
2017-09-21 17:40 Marcin Kraglak
2017-09-21 17:40 ` [PATCH 4/4] client: Use bt_shell_completion Marcin Kraglak

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=CABBYNZLgGqV8ZJY740wXncFOROAMiR8LqLLh2qeiDoB-Na5AxA@mail.gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=marcin.kraglak@tieto.com \
    /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;
as well as URLs for NNTP newsgroup(s).