mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 00/11 v3] improve complete support
@ 2012-04-30 12:23 Jean-Christophe PLAGNIOL-VILLARD
  2012-04-30 12:25 ` [PATCH 01/11] stringlist: use seperately allocated string Jean-Christophe PLAGNIOL-VILLARD
                   ` (11 more replies)
  0 siblings, 12 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-30 12:23 UTC (permalink / raw)
  To: barebox

Hi,

	the following patch serie improve the complete support
	by adding a complete framework to aalow commands complete support

	the add also car complete support for eval and setting and executable
	file support

	this also include an update of the stringlist API to support asprintf
	API

v3:

	add macro for complete state

The following changes since commit 6b489256ee1358973d536e723c77c2483e6b9f5b:

  Makefile: add barebox.srec to 'clean' (2012-04-30 14:01:34 +0200)

are available in the git repository at:

  git://git.jcrosoft.org/barebox.git tags/complete_update_support

for you to fetch changes up to 9492976bc88a9fe4633202681fcdc24ce1dab636:

  complete: add executable file support (2012-04-30 20:37:40 +0800)

----------------------------------------------------------------
improve complete support

The following patch serie improve the complete support
by adding a complete framework to aalow commands complete support.

The add also car complete support for eval and setting and executable
file support

This also include an update of the stringlist API to support asprintf
API

----------------------------------------------------------------
Jean-Christophe PLAGNIOL-VILLARD (9):
      complete: add var and device param complete support
      complete: add generic command complete framework
      complete: add device name complete support for devinfo
      complete: add help complete support
      complete: add empty complete support
      complete: add eth interface complete support
      complete: add go and sleep support
      complete: add delpart complete support
      complete: add executable file support

Sascha Hauer (2):
      stringlist: use seperately allocated string
      stringlist: implement string_list_add_asprintf

 arch/arm/cpu/cpuinfo.c        |    2 +
 arch/arm/mach-imx/speed.c     |    2 +
 arch/arm/mach-mxs/imx.c       |    2 +
 commands/clear.c              |    2 +
 commands/false.c              |    2 +
 commands/go.c                 |    2 +
 commands/help.c               |    2 +
 commands/login.c              |    2 +
 commands/lsmod.c              |    2 +
 commands/meminfo.c            |    2 +
 commands/net.c                |    2 +
 commands/partition.c          |    2 +
 commands/passwd.c             |    2 +
 commands/pwd.c                |    2 +
 commands/reginfo.c            |    2 +
 commands/reset.c              |    2 +
 commands/sleep.c              |    2 +
 commands/true.c               |    2 +
 commands/usb.c                |    2 +
 commands/version.c            |    2 +
 common/complete.c             |  201 +++++++++++++++++++++++++++++++++++------
 drivers/base/driver.c         |    2 +
 drivers/usb/gadget/u_serial.c |    2 +
 fs/devfs-core.c               |   19 ++++
 include/command.h             |    8 ++
 include/complete.h            |   12 +++
 include/stringlist.h          |    7 +-
 lib/stringlist.c              |   32 ++++++-
 net/dhcp.c                    |    2 +
 net/eth.c                     |   21 +++++
 30 files changed, 312 insertions(+), 34 deletions(-)

Best Regards,
J.

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 01/11] stringlist: use seperately allocated string
  2012-04-30 12:23 [PATCH 00/11 v3] improve complete support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-30 12:25 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-30 12:25 ` [PATCH 02/11] stringlist: implement string_list_add_asprintf Jean-Christophe PLAGNIOL-VILLARD
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-30 12:25 UTC (permalink / raw)
  To: barebox

From: Sascha Hauer <s.hauer@pengutronix.de>

Allocate the string in string list seperately instead of
embedding a zero length string into struct stringlist.
Besides looking cleaner this allows us to implement a
string_list_asprintf.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 include/stringlist.h |    6 ++++--
 lib/stringlist.c     |   10 ++++------
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/include/stringlist.h b/include/stringlist.h
index c923542..4b3cbf3 100644
--- a/include/stringlist.h
+++ b/include/stringlist.h
@@ -5,7 +5,7 @@
 
 struct string_list {
 	struct list_head list;
-	char str[0];
+	char *str;
 };
 
 int string_list_add(struct string_list *sl, char *str);
@@ -22,8 +22,10 @@ static inline void string_list_free(struct string_list *sl)
 {
 	struct string_list *entry, *safe;
 
-	list_for_each_entry_safe(entry, safe, &sl->list, list)
+	list_for_each_entry_safe(entry, safe, &sl->list, list) {
+		free(entry->str);
 		free(entry);
+	}
 }
 
 #endif /* __STRING_H */
diff --git a/lib/stringlist.c b/lib/stringlist.c
index a8ff979..c8b835e 100644
--- a/lib/stringlist.c
+++ b/lib/stringlist.c
@@ -16,9 +16,8 @@ int string_list_add(struct string_list *sl, char *str)
 {
 	struct string_list *new;
 
-	new = xmalloc(sizeof(struct string_list) + strlen(str) + 1);
-
-	strcpy(new->str, str);
+	new = xmalloc(sizeof(*new));
+	new->str = xstrdup(str);
 
 	list_add_tail(&new->list, &sl->list);
 
@@ -29,9 +28,8 @@ int string_list_add_sorted(struct string_list *sl, char *str)
 {
 	struct string_list *new;
 
-	new = xmalloc(sizeof(struct string_list) + strlen(str) + 1);
-
-	strcpy(new->str, str);
+	new = xmalloc(sizeof(*new));
+	new->str = xstrdup(str);
 
 	list_add_sort(&new->list, &sl->list, string_list_compare);
 
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 02/11] stringlist: implement string_list_add_asprintf
  2012-04-30 12:23 [PATCH 00/11 v3] improve complete support Jean-Christophe PLAGNIOL-VILLARD
  2012-04-30 12:25 ` [PATCH 01/11] stringlist: use seperately allocated string Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-30 12:25 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-30 12:25 ` [PATCH 03/11] complete: add var and device param complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-30 12:25 UTC (permalink / raw)
  To: barebox

From: Sascha Hauer <s.hauer@pengutronix.de>

Useful for allocating a string list entry on the fly.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 include/stringlist.h |    1 +
 lib/stringlist.c     |   24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/include/stringlist.h b/include/stringlist.h
index 4b3cbf3..dd3f623 100644
--- a/include/stringlist.h
+++ b/include/stringlist.h
@@ -9,6 +9,7 @@ struct string_list {
 };
 
 int string_list_add(struct string_list *sl, char *str);
+int string_list_add_asprintf(struct string_list *sl, const char *fmt, ...);
 int string_list_add_sorted(struct string_list *sl, char *str);
 int string_list_contains(struct string_list *sl, char *str);
 void string_list_print_by_column(struct string_list *sl);
diff --git a/lib/stringlist.c b/lib/stringlist.c
index c8b835e..b965aa0 100644
--- a/lib/stringlist.c
+++ b/lib/stringlist.c
@@ -1,6 +1,7 @@
 #include <common.h>
 #include <xfuncs.h>
 #include <malloc.h>
+#include <errno.h>
 #include <stringlist.h>
 
 static int string_list_compare(struct list_head *a, struct list_head *b)
@@ -24,6 +25,29 @@ int string_list_add(struct string_list *sl, char *str)
 	return 0;
 }
 
+int string_list_add_asprintf(struct string_list *sl, const char *fmt, ...)
+{
+	struct string_list *new;
+	va_list args;
+
+	new = xmalloc(sizeof(*new));
+
+	va_start(args, fmt);
+
+	new->str = vasprintf(fmt, args);
+
+	va_end(args);
+
+	if (!new->str) {
+		free(new);
+		return -ENOMEM;
+	}
+
+	list_add_tail(&new->list, &sl->list);
+
+	return 0;
+}
+
 int string_list_add_sorted(struct string_list *sl, char *str)
 {
 	struct string_list *new;
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 03/11] complete: add var and device param complete support
  2012-04-30 12:23 [PATCH 00/11 v3] improve complete support Jean-Christophe PLAGNIOL-VILLARD
  2012-04-30 12:25 ` [PATCH 01/11] stringlist: use seperately allocated string Jean-Christophe PLAGNIOL-VILLARD
  2012-04-30 12:25 ` [PATCH 02/11] stringlist: implement string_list_add_asprintf Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-30 12:25 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-30 12:25 ` [PATCH 04/11] complete: add generic command complete framework Jean-Christophe PLAGNIOL-VILLARD
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-30 12:25 UTC (permalink / raw)
  To: barebox

with $xx or xx= or if device $xx.yy or xx.yy=

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/complete.c |   96 +++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 90 insertions(+), 6 deletions(-)

diff --git a/common/complete.c b/common/complete.c
index 6d5349b..9d749e0 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -134,14 +134,95 @@ static int path_command_complete(struct string_list *sl, char *instr)
 static int command_complete(struct string_list *sl, char *instr)
 {
 	struct command *cmdtp;
-	char cmd[128];
+
+	if (!instr)
+		instr = "";
 
 	for_each_command(cmdtp) {
-		if (!strncmp(instr, cmdtp->name, strlen(instr))) {
-			strcpy(cmd, cmdtp->name);
-			cmd[strlen(cmdtp->name)] = ' ';
-			cmd[strlen(cmdtp->name) + 1] = 0;
-			string_list_add(sl, cmd);
+		if (strncmp(instr, cmdtp->name, strlen(instr)))
+			continue;
+
+		string_list_add_asprintf(sl, "%s ", cmdtp->name);
+	}
+
+	return 0;
+}
+
+static int device_param_complete(char *begin, struct device_d *dev,
+				 struct string_list *sl, char *instr)
+{
+	struct param_d *param;
+	int len;
+
+	if (!instr)
+		instr = "";
+
+	len = strlen(instr);
+
+	list_for_each_entry(param, &dev->parameters, list) {
+		if (strncmp(instr, param->name, len))
+			continue;
+
+		string_list_add_asprintf(sl, "%s%s.%s%c",
+			begin ? begin : "", dev_name(dev), param->name,
+			begin ? ' ' : '=');
+	}
+
+	return 0;
+}
+
+static int env_param_complete(struct string_list *sl, char *instr, int eval)
+{
+	struct device_d *dev;
+	struct variable_d *var;
+	struct env_context *c, *current_c;
+	char *instr_param;
+	int len;
+	char end = '=';
+	char *begin = "";
+
+	if (!instr)
+		instr = "";
+
+	if (eval) {
+		begin = "$";
+		end = ' ';
+	}
+
+	instr_param = strrchr(instr, '.');
+	len = strlen(instr);
+
+	current_c = get_current_context();
+	for(var = current_c->local->next; var; var = var->next) {
+		if (strncmp(instr, var_name(var), len))
+			continue;
+		string_list_add_asprintf(sl, "%s%s%c",
+			begin, var_name(var), end);
+	}
+
+	for (c = get_current_context(); c; c = c->parent) {
+		for (var = c->global->next; var; var = var->next) {
+			if (strncmp(instr, var_name(var), len))
+				continue;
+			string_list_add_asprintf(sl, "%s%s%c",
+				begin, var_name(var), end);
+		}
+	}
+
+	if (instr_param) {
+		len = (instr_param - instr);
+		instr_param++;
+	} else {
+		len = strlen(instr);
+		instr_param = "";
+	}
+
+	for_each_device(dev) {
+		if (!strncmp(instr, dev_name(dev), len)) {
+			if (eval)
+				device_param_complete("$", dev, sl, instr_param);
+			else
+				device_param_complete(NULL, dev, sl, instr_param);
 		}
 	}
 
@@ -188,7 +269,10 @@ int complete(char *instr, char **outstr)
 	} else {
 		command_complete(&sl, instr);
 		path_command_complete(&sl, instr);
+		env_param_complete(&sl, instr, 0);
 	}
+	if (*instr == '$')
+		env_param_complete(&sl, instr + 1, 1);
 
 	pos = strlen(instr);
 
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 04/11] complete: add generic command complete framework
  2012-04-30 12:23 [PATCH 00/11 v3] improve complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (2 preceding siblings ...)
  2012-04-30 12:25 ` [PATCH 03/11] complete: add var and device param complete support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-30 12:25 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-30 12:25 ` [PATCH 05/11] complete: add device name complete support for devinfo Jean-Christophe PLAGNIOL-VILLARD
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-30 12:25 UTC (permalink / raw)
  To: barebox

introduce generic command specific complete callback

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/complete.c  |   55 +++++++++++++++++++++++++++++++++++++--------------
 include/command.h  |    8 +++++++
 include/complete.h |    7 ++++++
 3 files changed, 55 insertions(+), 15 deletions(-)

diff --git a/common/complete.c b/common/complete.c
index 9d749e0..d848396 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -20,13 +20,10 @@
 #include <common.h>
 #include <complete.h>
 #include <xfuncs.h>
-#include <linux/list.h>
-#include <malloc.h>
 #include <fs.h>
 #include <linux/stat.h>
 #include <libgen.h>
 #include <command.h>
-#include <stringlist.h>
 #include <environment.h>
 
 static int file_complete(struct string_list *sl, char *instr)
@@ -131,7 +128,7 @@ static int path_command_complete(struct string_list *sl, char *instr)
 	return 0;
 }
 
-static int command_complete(struct string_list *sl, char *instr)
+int command_complete(struct string_list *sl, char *instr)
 {
 	struct command *cmdtp;
 
@@ -236,6 +233,32 @@ void complete_reset(void)
 	tab_pressed = 0;
 }
 
+static char* cmd_complete_lookup(struct string_list *sl, char *instr)
+{
+	struct command *cmdtp;
+	int len;
+	int ret = 1;
+	char *res = NULL;
+
+	for_each_command(cmdtp) {
+		len = strlen(cmdtp->name);
+		if (!strncmp(instr, cmdtp->name, len) && instr[len] == ' ') {
+			instr += len + 1;
+			if (cmdtp->complete) {
+				ret = cmdtp->complete(sl, instr);
+				res = instr;
+			}
+			goto end;
+		}
+	}
+
+end:
+	if (ret == COMPLETE_CONTINUE && *instr == '$')
+		env_param_complete(sl, instr + 1, 1);
+
+	return res;
+}
+
 int complete(char *instr, char **outstr)
 {
 	struct string_list sl, *entry, *first_entry;
@@ -259,20 +282,22 @@ int complete(char *instr, char **outstr)
 	while (*t == ' ')
 		t++;
 
-	instr = t;
-
 	/* get the completion possibilities */
-	if ((t = strrchr(t, ' '))) {
-		t++;
-		file_complete(&sl, t);
+	instr = cmd_complete_lookup(&sl, t);
+	if (!instr) {
 		instr = t;
-	} else {
-		command_complete(&sl, instr);
-		path_command_complete(&sl, instr);
-		env_param_complete(&sl, instr, 0);
+		if ((t = strrchr(t, ' '))) {
+			t++;
+			file_complete(&sl, t);
+			instr = t;
+		} else {
+			command_complete(&sl, instr);
+			path_command_complete(&sl, instr);
+			env_param_complete(&sl, instr, 0);
+		}
+		if (*instr == '$')
+			env_param_complete(&sl, instr + 1, 1);
 	}
-	if (*instr == '$')
-		env_param_complete(&sl, instr + 1, 1);
 
 	pos = strlen(instr);
 
diff --git a/include/command.h b/include/command.h
index b2e8449..80cbf56 100644
--- a/include/command.h
+++ b/include/command.h
@@ -40,6 +40,8 @@ extern struct list_head command_list;
 
 #define for_each_command(cmd)	list_for_each_entry(cmd, &command_list, list)
 
+struct string_list;
+
 /*
  * Monitor Command Table
  */
@@ -48,6 +50,7 @@ struct command {
 	const char	**aliases;
 					/* Implementation function	*/
 	int		(*cmd)(int, char *[]);
+	int		(*complete)(struct string_list *sl, char *instr);
 	const char	*usage;		/* Usage message	(short)	*/
 
 	struct list_head list;		/* List of commands		*/
@@ -88,6 +91,11 @@ const struct command __barebox_cmd_##_name						\
 
 #define BAREBOX_CMD_END					\
 };
+#ifdef CONFIG_AUTO_COMPLETE
+#define BAREBOX_CMD_COMPLETE(_cpt) .complete = _cpt,
+#else
+#define BAREBOX_CMD_COMPLETE(_cpt)
+#endif
 
 #define BAREBOX_CMD_HELP_START(_name) \
 static const __maybe_unused char cmd_##_name##_help[] =
diff --git a/include/complete.h b/include/complete.h
index cc0e88d..0c8ebd6 100644
--- a/include/complete.h
+++ b/include/complete.h
@@ -2,9 +2,16 @@
 #define __COMPLETE_
 
 #include <linux/list.h>
+#include <malloc.h>
+#include <stringlist.h>
+
+#define COMPLETE_END		0
+#define COMPLETE_CONTINUE	1
 
 int complete(char *instr, char **outstr);
 void complete_reset(void);
 
+int command_complete(struct string_list *sl, char *instr);
+
 #endif /* __COMPLETE_ */
 
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 05/11] complete: add device name complete support for devinfo
  2012-04-30 12:23 [PATCH 00/11 v3] improve complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (3 preceding siblings ...)
  2012-04-30 12:25 ` [PATCH 04/11] complete: add generic command complete framework Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-30 12:25 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-30 12:25 ` [PATCH 06/11] complete: add help complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-30 12:25 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/complete.c     |   20 ++++++++++++++++++++
 drivers/base/driver.c |    2 ++
 include/complete.h    |    1 +
 3 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/common/complete.c b/common/complete.c
index d848396..c2b37e4 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -145,6 +145,26 @@ int command_complete(struct string_list *sl, char *instr)
 	return 0;
 }
 
+int device_complete(struct string_list *sl, char *instr)
+{
+	struct device_d *dev;
+	int len;
+
+	if (!instr)
+		instr = "";
+
+	len = strlen(instr);
+
+	for_each_device(dev) {
+		if (strncmp(instr, dev_name(dev), len))
+			continue;
+
+		string_list_add_asprintf(sl, "%s ", dev_name(dev));
+	}
+
+	return COMPLETE_CONTINUE;
+}
+
 static int device_param_complete(char *begin, struct device_d *dev,
 				 struct string_list *sl, char *instr)
 {
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 9924fee..547d684 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -33,6 +33,7 @@
 #include <errno.h>
 #include <fs.h>
 #include <linux/list.h>
+#include <complete.h>
 
 LIST_HEAD(device_list);
 EXPORT_SYMBOL(device_list);
@@ -443,6 +444,7 @@ BAREBOX_CMD_START(devinfo)
 	.cmd		= do_devinfo,
 	.usage		= "Show information about devices and drivers.",
 	BAREBOX_CMD_HELP(cmd_devinfo_help)
+	BAREBOX_CMD_COMPLETE(device_complete)
 BAREBOX_CMD_END
 #endif
 
diff --git a/include/complete.h b/include/complete.h
index 0c8ebd6..9f8d784 100644
--- a/include/complete.h
+++ b/include/complete.h
@@ -12,6 +12,7 @@ int complete(char *instr, char **outstr);
 void complete_reset(void);
 
 int command_complete(struct string_list *sl, char *instr);
+int device_complete(struct string_list *sl, char *instr);
 
 #endif /* __COMPLETE_ */
 
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 06/11] complete: add help complete support
  2012-04-30 12:23 [PATCH 00/11 v3] improve complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (4 preceding siblings ...)
  2012-04-30 12:25 ` [PATCH 05/11] complete: add device name complete support for devinfo Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-30 12:25 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-30 12:26 ` [PATCH 07/11] complete: add empty " Jean-Christophe PLAGNIOL-VILLARD
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-30 12:25 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/help.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

diff --git a/commands/help.c b/commands/help.c
index 706b905..d7d9ba2 100644
--- a/commands/help.c
+++ b/commands/help.c
@@ -23,6 +23,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 
 /*
  * Use puts() instead of printf() to avoid printf buffer overflow
@@ -68,5 +69,6 @@ BAREBOX_CMD_START(help)
 	.aliases	= help_aliases,
 	.usage		= "print online help",
 	BAREBOX_CMD_HELP(cmd_help_help)
+	BAREBOX_CMD_COMPLETE(command_complete)
 BAREBOX_CMD_END
 
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 07/11] complete: add empty complete support
  2012-04-30 12:23 [PATCH 00/11 v3] improve complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (5 preceding siblings ...)
  2012-04-30 12:25 ` [PATCH 06/11] complete: add help complete support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-30 12:26 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-30 12:26 ` [PATCH 08/11] complete: add eth interface " Jean-Christophe PLAGNIOL-VILLARD
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-30 12:26 UTC (permalink / raw)
  To: barebox

for cpuinfo, clear, dhcp, false, login, lsmod, meminfo, passwd, pwd, reginfo,
reset, true, usb, version

for mach-imx and mach-mxs: dump_clocks
for u_serial: mycdev

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 arch/arm/cpu/cpuinfo.c        |    2 ++
 arch/arm/mach-imx/speed.c     |    2 ++
 arch/arm/mach-mxs/imx.c       |    2 ++
 commands/clear.c              |    2 ++
 commands/false.c              |    2 ++
 commands/login.c              |    2 ++
 commands/lsmod.c              |    2 ++
 commands/meminfo.c            |    2 ++
 commands/passwd.c             |    2 ++
 commands/pwd.c                |    2 ++
 commands/reginfo.c            |    2 ++
 commands/reset.c              |    2 ++
 commands/true.c               |    2 ++
 commands/usb.c                |    2 ++
 commands/version.c            |    2 ++
 common/complete.c             |    5 +++++
 drivers/usb/gadget/u_serial.c |    2 ++
 include/complete.h            |    1 +
 net/dhcp.c                    |    2 ++
 19 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/arch/arm/cpu/cpuinfo.c b/arch/arm/cpu/cpuinfo.c
index 09acb5f..ca986f8 100644
--- a/arch/arm/cpu/cpuinfo.c
+++ b/arch/arm/cpu/cpuinfo.c
@@ -22,6 +22,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 
 #define CPU_ARCH_UNKNOWN	0
 #define CPU_ARCH_ARMv3		1
@@ -181,5 +182,6 @@ static int do_cpuinfo(int argc, char *argv[])
 BAREBOX_CMD_START(cpuinfo)
 	.cmd            = do_cpuinfo,
 	.usage          = "Show info about CPU",
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
 
diff --git a/arch/arm/mach-imx/speed.c b/arch/arm/mach-imx/speed.c
index 63e24b4..6f8d20b 100644
--- a/arch/arm/mach-imx/speed.c
+++ b/arch/arm/mach-imx/speed.c
@@ -24,6 +24,7 @@
 #include <asm-generic/div64.h>
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <mach/clock.h>
 
 /*
@@ -80,5 +81,6 @@ static int do_clocks(int argc, char *argv[])
 BAREBOX_CMD_START(dump_clocks)
 	.cmd		= do_clocks,
 	.usage		= "show clock frequencies",
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
 
diff --git a/arch/arm/mach-mxs/imx.c b/arch/arm/mach-mxs/imx.c
index a4dae20..c64f23c 100644
--- a/arch/arm/mach-mxs/imx.c
+++ b/arch/arm/mach-mxs/imx.c
@@ -19,6 +19,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 
 extern void imx_dump_clocks(void);
 
@@ -32,4 +33,5 @@ static int do_clocks(int argc, char *argv[])
 BAREBOX_CMD_START(dump_clocks)
 	.cmd		= do_clocks,
 	.usage		= "show clock frequencies",
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
diff --git a/commands/clear.c b/commands/clear.c
index 9e5da10..28b4da9 100644
--- a/commands/clear.c
+++ b/commands/clear.c
@@ -22,6 +22,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <readkey.h>
 
 static int do_clear(int argc, char *argv[])
@@ -39,4 +40,5 @@ BAREBOX_CMD_HELP_END
 BAREBOX_CMD_START(clear)
 	.cmd		= do_clear,
 	.usage		= "clear screen",
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
diff --git a/commands/false.c b/commands/false.c
index 6ba3823..1642f8d 100644
--- a/commands/false.c
+++ b/commands/false.c
@@ -23,6 +23,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 
 static int do_false(int argc, char *argv[])
 {
@@ -32,5 +33,6 @@ static int do_false(int argc, char *argv[])
 BAREBOX_CMD_START(false)
 	.cmd		= do_false,
 	.usage		= "do nothing, unsuccessfully",
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
 
diff --git a/commands/login.c b/commands/login.c
index 2f3d766..0b5f3cb 100644
--- a/commands/login.c
+++ b/commands/login.c
@@ -20,6 +20,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <password.h>
 #include <getopt.h>
 
@@ -80,4 +81,5 @@ BAREBOX_CMD_START(login)
 	.cmd		= do_login,
 	.usage		= "login",
 	BAREBOX_CMD_HELP(cmd_login_help)
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
diff --git a/commands/lsmod.c b/commands/lsmod.c
index f7da1d0..e54eadc 100644
--- a/commands/lsmod.c
+++ b/commands/lsmod.c
@@ -1,5 +1,6 @@
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <module.h>
 
 static int do_lsmod(int argc, char *argv[])
@@ -15,4 +16,5 @@ static int do_lsmod(int argc, char *argv[])
 BAREBOX_CMD_START(lsmod)
 	.cmd		= do_lsmod,
 	.usage		= "list modules",
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
diff --git a/commands/meminfo.c b/commands/meminfo.c
index b412744..1d24cfd 100644
--- a/commands/meminfo.c
+++ b/commands/meminfo.c
@@ -21,6 +21,7 @@
  */
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <malloc.h>
 
 static int do_meminfo(int argc, char *argv[])
@@ -33,4 +34,5 @@ static int do_meminfo(int argc, char *argv[])
 BAREBOX_CMD_START(meminfo)
 	.cmd		= do_meminfo,
 	.usage		= "print info about memory usage",
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
diff --git a/commands/passwd.c b/commands/passwd.c
index cdbcdf5..7f704ad 100644
--- a/commands/passwd.c
+++ b/commands/passwd.c
@@ -20,6 +20,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <password.h>
 #include <errno.h>
 
@@ -95,4 +96,5 @@ BAREBOX_CMD_START(passwd)
 	.cmd		= do_passwd,
 	.usage		= "passwd",
 	BAREBOX_CMD_HELP(cmd_passwd_help)
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
diff --git a/commands/pwd.c b/commands/pwd.c
index 4afe2d4..d68a509 100644
--- a/commands/pwd.c
+++ b/commands/pwd.c
@@ -21,6 +21,7 @@
  */
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <fs.h>
 
 static int do_pwd(int argc, char *argv[])
@@ -32,4 +33,5 @@ static int do_pwd(int argc, char *argv[])
 BAREBOX_CMD_START(pwd)
 	.cmd		= do_pwd,
 	.usage		= "print working directory",
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
diff --git a/commands/reginfo.c b/commands/reginfo.c
index 009a065..a31013a 100644
--- a/commands/reginfo.c
+++ b/commands/reginfo.c
@@ -22,6 +22,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 
 static int do_reginfo(int argc, char *argv[])
 {
@@ -32,4 +33,5 @@ static int do_reginfo(int argc, char *argv[])
 BAREBOX_CMD_START(reginfo)
 	.cmd		= do_reginfo,
 	.usage		= "print register information",
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
diff --git a/commands/reset.c b/commands/reset.c
index 9f242d1..97d04ee 100644
--- a/commands/reset.c
+++ b/commands/reset.c
@@ -22,6 +22,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 
 static int cmd_reset(int argc, char *argv[])
 {
@@ -34,4 +35,5 @@ static int cmd_reset(int argc, char *argv[])
 BAREBOX_CMD_START(reset)
 	.cmd		= cmd_reset,
 	.usage		= "Perform RESET of the CPU",
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
diff --git a/commands/true.c b/commands/true.c
index 773ddef..e50152f 100644
--- a/commands/true.c
+++ b/commands/true.c
@@ -23,6 +23,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 
 static int do_true(int argc, char *argv[])
 {
@@ -32,5 +33,6 @@ static int do_true(int argc, char *argv[])
 BAREBOX_CMD_START(true)
 	.cmd		= do_true,
 	.usage		= "do nothing, successfully",
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
 
diff --git a/commands/usb.c b/commands/usb.c
index e28afd0..d02ea4b 100644
--- a/commands/usb.c
+++ b/commands/usb.c
@@ -21,6 +21,7 @@
  */
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <usb/usb.h>
 #include <getopt.h>
 
@@ -56,4 +57,5 @@ BAREBOX_CMD_START(usb)
 	.cmd		= do_usb,
 	.usage		= "(re-)detect USB devices",
 	BAREBOX_CMD_HELP(cmd_usb_help)
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
diff --git a/commands/version.c b/commands/version.c
index 8901fae..6dbda7a 100644
--- a/commands/version.c
+++ b/commands/version.c
@@ -23,6 +23,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 
 static int do_version(int argc, char *argv[])
 {
@@ -33,5 +34,6 @@ static int do_version(int argc, char *argv[])
 BAREBOX_CMD_START(version)
 	.cmd		= do_version,
 	.usage		= "print monitor version",
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
 
diff --git a/common/complete.c b/common/complete.c
index c2b37e4..c1d6489 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -188,6 +188,11 @@ static int device_param_complete(char *begin, struct device_d *dev,
 	return 0;
 }
 
+int empty_complete(struct string_list *sl, char *instr)
+{
+	return COMPLETE_END;
+}
+
 static int env_param_complete(struct string_list *sl, char *instr, int eval)
 {
 	struct device_d *dev;
diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
index c5e7387..946b4f2 100644
--- a/drivers/usb/gadget/u_serial.c
+++ b/drivers/usb/gadget/u_serial.c
@@ -18,6 +18,7 @@
 /* #define VERBOSE_DEBUG */
 
 #include <common.h>
+#include <complete.h>
 #include <usb/cdc.h>
 #include <kfifo.h>
 #include <clock.h>
@@ -502,6 +503,7 @@ static int do_mycdev(int argc, char *argv[])
 
 BAREBOX_CMD_START(mycdev)
 	.cmd		= do_mycdev,
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
 
 /**
diff --git a/include/complete.h b/include/complete.h
index 9f8d784..006369c 100644
--- a/include/complete.h
+++ b/include/complete.h
@@ -13,6 +13,7 @@ void complete_reset(void);
 
 int command_complete(struct string_list *sl, char *instr);
 int device_complete(struct string_list *sl, char *instr);
+int empty_complete(struct string_list *sl, char *instr);
 
 #endif /* __COMPLETE_ */
 
diff --git a/net/dhcp.c b/net/dhcp.c
index 0c882fb..9cd0282 100644
--- a/net/dhcp.c
+++ b/net/dhcp.c
@@ -10,6 +10,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <environment.h>
 #include <clock.h>
 #include <net.h>
@@ -704,6 +705,7 @@ BAREBOX_CMD_START(dhcp)
 	.cmd		= do_dhcp,
 	.usage		= "invoke dhcp client to obtain ip/boot params",
 	BAREBOX_CMD_HELP(cmd_dhcp_help)
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
 
 BAREBOX_MAGICVAR(bootfile, "bootfile returned from DHCP request");
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 08/11] complete: add eth interface complete support
  2012-04-30 12:23 [PATCH 00/11 v3] improve complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (6 preceding siblings ...)
  2012-04-30 12:26 ` [PATCH 07/11] complete: add empty " Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-30 12:26 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-30 12:26 ` [PATCH 09/11] complete: add go and sleep support Jean-Christophe PLAGNIOL-VILLARD
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-30 12:26 UTC (permalink / raw)
  To: barebox

use it on ethact

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/net.c     |    2 ++
 include/complete.h |    1 +
 net/eth.c          |   21 +++++++++++++++++++++
 3 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/commands/net.c b/commands/net.c
index c5c6373..a453f4e 100644
--- a/commands/net.c
+++ b/commands/net.c
@@ -28,6 +28,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <environment.h>
 #include <driver.h>
 #include <net.h>
@@ -96,5 +97,6 @@ BAREBOX_CMD_START(ethact)
 	.cmd		= do_ethact,
 	.usage		= "set current ethernet device",
 	BAREBOX_CMD_HELP(cmd_ethact_help)
+	BAREBOX_CMD_COMPLETE(eth_complete)
 BAREBOX_CMD_END
 
diff --git a/include/complete.h b/include/complete.h
index 006369c..12c4e15 100644
--- a/include/complete.h
+++ b/include/complete.h
@@ -14,6 +14,7 @@ void complete_reset(void);
 int command_complete(struct string_list *sl, char *instr);
 int device_complete(struct string_list *sl, char *instr);
 int empty_complete(struct string_list *sl, char *instr);
+int eth_complete(struct string_list *sl, char *instr);
 
 #endif /* __COMPLETE_ */
 
diff --git a/net/eth.c b/net/eth.c
index 130805b..4ea9fb0 100644
--- a/net/eth.c
+++ b/net/eth.c
@@ -23,6 +23,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <driver.h>
 #include <init.h>
 #include <net.h>
@@ -109,6 +110,26 @@ struct eth_device *eth_get_byname(char *ethname)
 	return NULL;
 }
 
+#ifdef CONFIG_AUTO_COMPLETE
+int eth_complete(struct string_list *sl, char *instr)
+{
+	struct eth_device *edev;
+	const char *devname;
+	int len;
+
+	len = strlen(instr);
+
+	list_for_each_entry(edev, &netdev_list, list) {
+		devname = dev_name(&edev->dev);
+		if (strncmp(instr, devname, len))
+			continue;
+
+		string_list_add_asprintf(sl, "%s ", devname);
+	}
+	return COMPLETE_CONTNINUE;
+}
+#endif
+
 int eth_send(void *packet, int length)
 {
 	int ret;
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 09/11] complete: add go and sleep support
  2012-04-30 12:23 [PATCH 00/11 v3] improve complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (7 preceding siblings ...)
  2012-04-30 12:26 ` [PATCH 08/11] complete: add eth interface " Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-30 12:26 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-30 12:26 ` [PATCH 10/11] complete: add delpart complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-30 12:26 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/go.c      |    2 ++
 commands/sleep.c   |    2 ++
 common/complete.c  |    5 +++++
 include/complete.h |    1 +
 4 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/commands/go.c b/commands/go.c
index c821207..e9e9d40 100644
--- a/commands/go.c
+++ b/commands/go.c
@@ -25,6 +25,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <fs.h>
 #include <fcntl.h>
 #include <linux/ctype.h>
@@ -91,4 +92,5 @@ BAREBOX_CMD_START(go)
 	.cmd		= do_go,
 	.usage		= "start application at address or file",
 	BAREBOX_CMD_HELP(cmd_go_help)
+	BAREBOX_CMD_COMPLETE(cammand_var_complete)
 BAREBOX_CMD_END
diff --git a/commands/sleep.c b/commands/sleep.c
index f772e87..c5f7867 100644
--- a/commands/sleep.c
+++ b/commands/sleep.c
@@ -22,6 +22,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <clock.h>
 
 static int do_sleep(int argc, char *argv[])
@@ -46,4 +47,5 @@ static int do_sleep(int argc, char *argv[])
 BAREBOX_CMD_START(sleep)
 	.cmd		= do_sleep,
 	.usage		= "delay execution for n seconds",
+	BAREBOX_CMD_COMPLETE(cammand_var_complete)
 BAREBOX_CMD_END
diff --git a/common/complete.c b/common/complete.c
index c1d6489..45c6908 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -193,6 +193,11 @@ int empty_complete(struct string_list *sl, char *instr)
 	return COMPLETE_END;
 }
 
+int cammand_var_complete(struct string_list *sl, char *instr)
+{
+	return COMPLETE_CONTINUE;
+}
+
 static int env_param_complete(struct string_list *sl, char *instr, int eval)
 {
 	struct device_d *dev;
diff --git a/include/complete.h b/include/complete.h
index 12c4e15..1365803 100644
--- a/include/complete.h
+++ b/include/complete.h
@@ -15,6 +15,7 @@ int command_complete(struct string_list *sl, char *instr);
 int device_complete(struct string_list *sl, char *instr);
 int empty_complete(struct string_list *sl, char *instr);
 int eth_complete(struct string_list *sl, char *instr);
+int cammand_var_complete(struct string_list *sl, char *instr);
 
 #endif /* __COMPLETE_ */
 
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 10/11] complete: add delpart complete support
  2012-04-30 12:23 [PATCH 00/11 v3] improve complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (8 preceding siblings ...)
  2012-04-30 12:26 ` [PATCH 09/11] complete: add go and sleep support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-30 12:26 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-04-30 12:26 ` [PATCH 11/11] complete: add executable file support Jean-Christophe PLAGNIOL-VILLARD
  2012-05-01 19:43 ` [PATCH 00/11 v3] improve complete support Sascha Hauer
  11 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-30 12:26 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 commands/partition.c |    2 ++
 fs/devfs-core.c      |   19 +++++++++++++++++++
 include/complete.h   |    1 +
 3 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/commands/partition.c b/commands/partition.c
index 4892261..6cce042 100644
--- a/commands/partition.c
+++ b/commands/partition.c
@@ -32,6 +32,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <driver.h>
 #include <malloc.h>
 #include <partition.h>
@@ -225,5 +226,6 @@ BAREBOX_CMD_START(delpart)
 	.cmd = do_delpart,
 	.usage = "delete partition(s)",
 	BAREBOX_CMD_HELP(cmd_delpart_help)
+	BAREBOX_CMD_COMPLETE(devfs_partition_complete)
 BAREBOX_CMD_END
 
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 3014d0e..ff6a976 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -20,6 +20,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #include <common.h>
+#include <complete.h>
 #include <driver.h>
 #include <errno.h>
 #include <malloc.h>
@@ -29,6 +30,24 @@
 
 LIST_HEAD(cdev_list);
 
+#ifdef CONFIG_AUTO_COMPLETE
+int devfs_partition_complete(struct string_list *sl, char *instr)
+{
+	struct cdev *cdev;
+	int len;
+
+	len = strlen(instr);
+
+	list_for_each_entry(cdev, &cdev_list, list) {
+		if (cdev->flags & DEVFS_IS_PARTITION &&
+		    !strncmp(instr, cdev->name, len)) {
+			string_list_add_asprintf(sl, "%s ", cdev->name);
+		}
+	}
+	return COMPLETE_CONTINUE;
+}
+#endif
+
 struct cdev *cdev_by_name(const char *filename)
 {
 	struct cdev *cdev;
diff --git a/include/complete.h b/include/complete.h
index 1365803..8248c64 100644
--- a/include/complete.h
+++ b/include/complete.h
@@ -16,6 +16,7 @@ int device_complete(struct string_list *sl, char *instr);
 int empty_complete(struct string_list *sl, char *instr);
 int eth_complete(struct string_list *sl, char *instr);
 int cammand_var_complete(struct string_list *sl, char *instr);
+int devfs_partition_complete(struct string_list *sl, char *instr);
 
 #endif /* __COMPLETE_ */
 
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 11/11] complete: add executable file support
  2012-04-30 12:23 [PATCH 00/11 v3] improve complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (9 preceding siblings ...)
  2012-04-30 12:26 ` [PATCH 10/11] complete: add delpart complete support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-30 12:26 ` Jean-Christophe PLAGNIOL-VILLARD
  2012-05-01 19:43 ` [PATCH 00/11 v3] improve complete support Sascha Hauer
  11 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-30 12:26 UTC (permalink / raw)
  To: barebox

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 common/complete.c |   30 +++++++++++++++++++-----------
 1 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/common/complete.c b/common/complete.c
index 45c6908..0b03d7c 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -26,7 +26,7 @@
 #include <command.h>
 #include <environment.h>
 
-static int file_complete(struct string_list *sl, char *instr)
+static int file_complete(struct string_list *sl, char *instr, int exec)
 {
 	char *path = strdup(instr);
 	struct stat s;
@@ -46,15 +46,20 @@ static int file_complete(struct string_list *sl, char *instr)
 		if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
 			continue;
 
-		if (!strncmp(base, d->d_name, strlen(base))) {
-			strcpy(tmp, instr);
-			strcat(tmp, d->d_name + strlen(base));
-			if (!stat(tmp, &s) && S_ISDIR(s.st_mode))
-				strcat(tmp, "/");
-			else
-				strcat(tmp, " ");
-			string_list_add_sorted(sl, tmp);
+		if (strncmp(base, d->d_name, strlen(base)))
+			continue;
+
+		strcpy(tmp, instr);
+		strcat(tmp, d->d_name + strlen(base));
+		if (!stat(tmp, &s) && S_ISDIR(s.st_mode)) {
+			strcat(tmp, "/");
+		} else {
+			if (exec && !S_ISREG(s.st_mode))
+				continue;
+			strcat(tmp, " ");
 		}
+
+		string_list_add_sorted(sl, tmp);
 	}
 
 	closedir(dir);
@@ -316,9 +321,12 @@ int complete(char *instr, char **outstr)
 	instr = cmd_complete_lookup(&sl, t);
 	if (!instr) {
 		instr = t;
-		if ((t = strrchr(t, ' '))) {
+		if (t && (t[0] == '/' || !strncmp(t, "./", 2))) {
+			file_complete(&sl, t, 1);
+			instr = t;
+		} else if ((t = strrchr(t, ' '))) {
 			t++;
-			file_complete(&sl, t);
+			file_complete(&sl, t, 0);
 			instr = t;
 		} else {
 			command_complete(&sl, instr);
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 14+ messages in thread

* Re: [PATCH 00/11 v3] improve complete support
  2012-04-30 12:23 [PATCH 00/11 v3] improve complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (10 preceding siblings ...)
  2012-04-30 12:26 ` [PATCH 11/11] complete: add executable file support Jean-Christophe PLAGNIOL-VILLARD
@ 2012-05-01 19:43 ` Sascha Hauer
  11 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2012-05-01 19:43 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Mon, Apr 30, 2012 at 02:23:34PM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> Hi,
> 
> 	the following patch serie improve the complete support
> 	by adding a complete framework to aalow commands complete support
> 
> 	the add also car complete support for eval and setting and executable
> 	file support
> 
> 	this also include an update of the stringlist API to support asprintf
> 	API
> 
> v3:
> 
> 	add macro for complete state
> 
> The following changes since commit 6b489256ee1358973d536e723c77c2483e6b9f5b:
> 
>   Makefile: add barebox.srec to 'clean' (2012-04-30 14:01:34 +0200)
> 
> are available in the git repository at:
> 
>   git://git.jcrosoft.org/barebox.git tags/complete_update_support

Pulled, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [PATCH 02/11] stringlist: implement string_list_add_asprintf
  2012-04-19  5:38 [PATCH 00/11 v2] " Jean-Christophe PLAGNIOL-VILLARD
@ 2012-04-19  5:44 ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2012-04-19  5:44 UTC (permalink / raw)
  To: barebox

From: Sascha Hauer <s.hauer@pengutronix.de>

Useful for allocating a string list entry on the fly.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 include/stringlist.h |    1 +
 lib/stringlist.c     |   24 ++++++++++++++++++++++++
 2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/include/stringlist.h b/include/stringlist.h
index 4b3cbf3..dd3f623 100644
--- a/include/stringlist.h
+++ b/include/stringlist.h
@@ -9,6 +9,7 @@ struct string_list {
 };
 
 int string_list_add(struct string_list *sl, char *str);
+int string_list_add_asprintf(struct string_list *sl, const char *fmt, ...);
 int string_list_add_sorted(struct string_list *sl, char *str);
 int string_list_contains(struct string_list *sl, char *str);
 void string_list_print_by_column(struct string_list *sl);
diff --git a/lib/stringlist.c b/lib/stringlist.c
index c8b835e..b965aa0 100644
--- a/lib/stringlist.c
+++ b/lib/stringlist.c
@@ -1,6 +1,7 @@
 #include <common.h>
 #include <xfuncs.h>
 #include <malloc.h>
+#include <errno.h>
 #include <stringlist.h>
 
 static int string_list_compare(struct list_head *a, struct list_head *b)
@@ -24,6 +25,29 @@ int string_list_add(struct string_list *sl, char *str)
 	return 0;
 }
 
+int string_list_add_asprintf(struct string_list *sl, const char *fmt, ...)
+{
+	struct string_list *new;
+	va_list args;
+
+	new = xmalloc(sizeof(*new));
+
+	va_start(args, fmt);
+
+	new->str = vasprintf(fmt, args);
+
+	va_end(args);
+
+	if (!new->str) {
+		free(new);
+		return -ENOMEM;
+	}
+
+	list_add_tail(&new->list, &sl->list);
+
+	return 0;
+}
+
 int string_list_add_sorted(struct string_list *sl, char *str)
 {
 	struct string_list *new;
-- 
1.7.9.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2012-05-01 19:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-30 12:23 [PATCH 00/11 v3] improve complete support Jean-Christophe PLAGNIOL-VILLARD
2012-04-30 12:25 ` [PATCH 01/11] stringlist: use seperately allocated string Jean-Christophe PLAGNIOL-VILLARD
2012-04-30 12:25 ` [PATCH 02/11] stringlist: implement string_list_add_asprintf Jean-Christophe PLAGNIOL-VILLARD
2012-04-30 12:25 ` [PATCH 03/11] complete: add var and device param complete support Jean-Christophe PLAGNIOL-VILLARD
2012-04-30 12:25 ` [PATCH 04/11] complete: add generic command complete framework Jean-Christophe PLAGNIOL-VILLARD
2012-04-30 12:25 ` [PATCH 05/11] complete: add device name complete support for devinfo Jean-Christophe PLAGNIOL-VILLARD
2012-04-30 12:25 ` [PATCH 06/11] complete: add help complete support Jean-Christophe PLAGNIOL-VILLARD
2012-04-30 12:26 ` [PATCH 07/11] complete: add empty " Jean-Christophe PLAGNIOL-VILLARD
2012-04-30 12:26 ` [PATCH 08/11] complete: add eth interface " Jean-Christophe PLAGNIOL-VILLARD
2012-04-30 12:26 ` [PATCH 09/11] complete: add go and sleep support Jean-Christophe PLAGNIOL-VILLARD
2012-04-30 12:26 ` [PATCH 10/11] complete: add delpart complete support Jean-Christophe PLAGNIOL-VILLARD
2012-04-30 12:26 ` [PATCH 11/11] complete: add executable file support Jean-Christophe PLAGNIOL-VILLARD
2012-05-01 19:43 ` [PATCH 00/11 v3] improve complete support Sascha Hauer
  -- strict thread matches above, loose matches on Subject: below --
2012-04-19  5:38 [PATCH 00/11 v2] " Jean-Christophe PLAGNIOL-VILLARD
2012-04-19  5:44 ` [PATCH 02/11] stringlist: implement string_list_add_asprintf Jean-Christophe PLAGNIOL-VILLARD

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox