linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jefferson Delfes <jefferson.delfes@openbossa.org>
To: linux-bluetooth@vger.kernel.org
Cc: Jefferson Delfes <jefferson.delfes@openbossa.org>
Subject: [PATCH BlueZ] gatttool: Add command completion for interactive mode
Date: Wed, 29 Feb 2012 16:17:31 -0400	[thread overview]
Message-ID: <1330546651-6695-1-git-send-email-jefferson.delfes@openbossa.org> (raw)

---
 attrib/interactive.c |   28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/attrib/interactive.c b/attrib/interactive.c
index a772362..be81424 100644
--- a/attrib/interactive.c
+++ b/attrib/interactive.c
@@ -800,6 +800,33 @@ static gboolean prompt_read(GIOChannel *chan, GIOCondition cond,
 	return TRUE;
 }
 
+static char *completion_generator(const char *text, int state)
+{
+	static int index = 0, len = 0;
+	const char *cmd = NULL;
+
+	if (state == 0) {
+		index = 0;
+		len = strlen(text);
+	}
+
+	while ((cmd = commands[index].cmd) != NULL) {
+		index++;
+		if (strncmp(cmd, text, len) == 0)
+			return strdup(cmd);
+	}
+
+	return NULL;
+}
+
+static char **commands_completion(const char *text, int start, int end)
+{
+	if (start == 0)
+		return rl_completion_matches(text, &completion_generator);
+	else
+		return NULL;
+}
+
 int interactive(const gchar *src, const gchar *dst, int psm)
 {
 	GIOChannel *pchan;
@@ -820,6 +847,7 @@ int interactive(const gchar *src, const gchar *dst, int psm)
 	events = G_IO_IN | G_IO_ERR | G_IO_HUP | G_IO_NVAL;
 	g_io_add_watch(pchan, events, prompt_read, NULL);
 
+	rl_attempted_completion_function = commands_completion;
 	rl_callback_handler_install(get_prompt(), parse_line);
 
 	g_main_loop_run(event_loop);
-- 
1.7.9.2


             reply	other threads:[~2012-02-29 20:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-29 20:17 Jefferson Delfes [this message]
2012-03-01  2:10 ` [PATCH BlueZ] gatttool: Add command completion for interactive mode Johan Hedberg

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=1330546651-6695-1-git-send-email-jefferson.delfes@openbossa.org \
    --to=jefferson.delfes@openbossa.org \
    --cc=linux-bluetooth@vger.kernel.org \
    /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).