mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* pull request complete support
@ 2011-06-09 14:50 Jean-Christophe PLAGNIOL-VILLARD
  2011-06-09 14:55 ` [PATCH 1/6] complete: add var and device param " Jean-Christophe PLAGNIOL-VILLARD
                   ` (7 more replies)
  0 siblings, 8 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-06-09 14:50 UTC (permalink / raw)
  To: barebox

Hi,

	This patch series add the support of the complete for :
	- var and device param (set and get)
	- generic command complete framework
	- devinfo
	- help
	- empty command complete
	- eth interface

	this will also include the move driver and bus code to drivers/base
	patch as this series depend on it

	Please pull
The following changes since commit 6e27bfb15e4e2446753fe9affcc3128772205cec:

  Merge branch 'next' (2011-06-06 11:29:45 +0200)

are available in the git repository at:

  git://uboot.jcrosoft.org/barebox.git complete

Jean-Christophe PLAGNIOL-VILLARD (7):
      move driver and bus code to drivers/base
      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

 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/help.c                          |    2 +
 commands/login.c                         |    2 +
 commands/lsmod.c                         |    2 +
 commands/meminfo.c                       |    2 +
 commands/net.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                        |  183 ++++++++++++++++++++++++++++--
 drivers/Makefile                         |    1 +
 drivers/base/Makefile                    |    2 +
 {lib => drivers/base}/driver.c           |    2 +
 lib/bus.c => drivers/base/platform_bus.c |    0
 drivers/usb/gadget/u_serial.c            |    2 +
 include/command.h                        |    8 ++
 include/complete.h                       |    7 +
 lib/Makefile                             |    2 -
 net/dhcp.c                               |    2 +
 net/eth.c                                |   23 ++++
 28 files changed, 253 insertions(+), 13 deletions(-)
 create mode 100644 drivers/base/Makefile
 rename {lib => drivers/base}/driver.c (99%)
 rename lib/bus.c => drivers/base/platform_bus.c (100%)

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 1/6] complete: add var and device param complete support
  2011-06-09 14:50 pull request complete support Jean-Christophe PLAGNIOL-VILLARD
@ 2011-06-09 14:55 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-06-10  1:29   ` [PATCH v2] " Jean-Christophe PLAGNIOL-VILLARD
  2011-06-09 14:55 ` [PATCH 2/6] complete: add generic command complete framework Jean-Christophe PLAGNIOL-VILLARD
                   ` (6 subsequent siblings)
  7 siblings, 1 reply; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-06-09 14:55 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 |  111 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 110 insertions(+), 1 deletions(-)

diff --git a/common/complete.c b/common/complete.c
index 46ba871..9d9f166 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -27,6 +27,7 @@
 #include <libgen.h>
 #include <command.h>
 #include <stringlist.h>
+#include <environment.h>
 
 static int file_complete(struct string_list *sl, char *instr)
 {
@@ -84,6 +85,110 @@ static int command_complete(struct string_list *sl, char *instr)
 	return 0;
 }
 
+static int device_param_complete(char begin, struct device_d *dev,
+				 struct string_list *sl, char *instr)
+{
+	struct param_d *param;
+	char cmd[128];
+	char *tmp = cmd;
+	int len, len2;
+
+	len = strlen(instr);
+	if (begin) {
+		tmp[0] = begin;
+		tmp++;
+	}
+	strcpy(tmp, dev_name(dev));
+	len2 = strlen(dev_name(dev));
+	tmp += len2;
+	tmp[0] = '.';
+	tmp++;
+
+	list_for_each_entry(param, &dev->parameters, list) {
+		memset(tmp, 0x0, 128 - (int)(tmp - cmd));
+		if (!strncmp(instr, param->name, len)) {
+			strcpy(tmp, param->name);
+			len2 = strlen(param->name);
+			if (begin)
+				tmp[len2] = ' ';
+			else
+				tmp[len2] = '=';
+			tmp[len2 + 1] = 0;
+			string_list_add(sl, cmd);
+		}
+	}
+
+	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 cmd[128];
+	char *instr_param;
+	char *tmp = cmd;
+	int len, len2;
+	char end = '=';
+
+	if (eval) {
+		cmd[0] = '$';
+		tmp++;
+		end = ' ';
+	}
+
+	instr_param = strrchr(instr, '.');
+	len = strlen(instr);
+
+	current_c = get_current_context();
+	var = current_c->local->next;
+	while (var) {
+		if (!strncmp(instr, var_name(var), len)) {
+			len2 = strlen(var_name(var));
+			strcpy(tmp, var_name(var));
+			tmp[len2] = end;
+			tmp[len2 + 1] = 0;
+			string_list_add(sl, cmd);
+		}
+		var = var->next;
+	}
+
+	c = get_current_context();
+	while(c) {
+		var = c->global->next;
+		while (var) {
+			if (!strncmp(instr, var_name(var), len)) {
+				len2 = strlen(var_name(var));
+				strcpy(tmp, var_name(var));
+				tmp[len2] = end;
+				tmp[len2 + 1] = 0;
+				string_list_add(sl, cmd);
+			}
+			var = var->next;
+		}
+		c = c->parent;
+	}
+
+	if (instr_param) {
+		len = (instr_param - instr);
+		instr_param++;
+	} else {
+		len = strlen(instr);
+	}
+
+	for_each_device(dev) {
+		if (!strncmp(instr, dev_name(dev), len)) {
+			if (eval)
+				device_param_complete('$', dev, sl, instr_param);
+			else
+				device_param_complete(0, dev, sl, instr_param);
+		}
+	}
+
+	return 0;
+}
+
 static int tab_pressed = 0;
 
 void complete_reset(void)
@@ -121,8 +226,12 @@ int complete(char *instr, char **outstr)
 		t++;
 		file_complete(&sl, t);
 		instr = t;
-	} else
+	} else {
 		command_complete(&sl, instr);
+		env_param_complete(&sl, instr, 0);
+	}
+	if (*instr == '$')
+		env_param_complete(&sl, instr + 1, 1);
 
 	pos = strlen(instr);
 
-- 
1.7.4.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 2/6] complete: add generic command complete framework
  2011-06-09 14:50 pull request complete support Jean-Christophe PLAGNIOL-VILLARD
  2011-06-09 14:55 ` [PATCH 1/6] complete: add var and device param " Jean-Christophe PLAGNIOL-VILLARD
@ 2011-06-09 14:55 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-06-09 14:55 ` [PATCH 3/6] complete: add device name complete support for devinfo Jean-Christophe PLAGNIOL-VILLARD
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-06-09 14:55 UTC (permalink / raw)
  To: barebox

introduce generic command specific complete callback

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

diff --git a/common/complete.c b/common/complete.c
index 9d9f166..098b80d 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)
@@ -68,7 +65,7 @@ out:
 	return 0;
 }
 
-static int command_complete(struct string_list *sl, char *instr)
+int command_complete(struct string_list *sl, char *instr)
 {
 	struct command *cmdtp;
 	char cmd[128];
@@ -196,6 +193,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 && *instr == '$')
+		env_param_complete(sl, instr + 1, 1);
+
+	return res;
+}
+
 int complete(char *instr, char **outstr)
 {
 	struct string_list sl, *entry, *first_entry;
@@ -219,19 +242,21 @@ 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);
-		env_param_complete(&sl, instr, 0);
+		if ((t = strrchr(t, ' '))) {
+			t++;
+			file_complete(&sl, t);
+			instr = t;
+		} else {
+			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 e221546..75afd95 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)(struct command *, 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..3f1fe89 100644
--- a/include/complete.h
+++ b/include/complete.h
@@ -2,9 +2,13 @@
 #define __COMPLETE_
 
 #include <linux/list.h>
+#include <malloc.h>
+#include <stringlist.h>
 
 int complete(char *instr, char **outstr);
 void complete_reset(void);
 
+int command_complete(struct string_list *sl, char *instr);
+
 #endif /* __COMPLETE_ */
 
-- 
1.7.4.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 3/6] complete: add device name complete support for devinfo
  2011-06-09 14:50 pull request complete support Jean-Christophe PLAGNIOL-VILLARD
  2011-06-09 14:55 ` [PATCH 1/6] complete: add var and device param " Jean-Christophe PLAGNIOL-VILLARD
  2011-06-09 14:55 ` [PATCH 2/6] complete: add generic command complete framework Jean-Christophe PLAGNIOL-VILLARD
@ 2011-06-09 14:55 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-06-09 14:55 ` [PATCH 4/6] complete: add help complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-06-09 14:55 UTC (permalink / raw)
  To: barebox

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

diff --git a/common/complete.c b/common/complete.c
index 098b80d..e197872 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -82,6 +82,28 @@ int command_complete(struct string_list *sl, char *instr)
 	return 0;
 }
 
+int device_complete(struct string_list *sl, char *instr)
+{
+	struct device_d *dev;
+	char cmd[128];
+	int len, len2;
+
+	len = strlen(instr);
+
+	for_each_device(dev) {
+		if (!strncmp(instr, dev_name(dev), len)) {
+			len2 = strlen(dev_name(dev));
+			strcpy(cmd, dev_name(dev));
+			cmd[len2] = ' ';
+			cmd[len2 + 1] = 0;
+			string_list_add(sl, cmd);
+		}
+	}
+
+	return 0;
+}
+
+
 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 4c10a49..ea1dc6e 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);
@@ -376,6 +377,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 3f1fe89..8dfc99c 100644
--- a/include/complete.h
+++ b/include/complete.h
@@ -9,6 +9,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.4.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 4/6] complete: add help complete support
  2011-06-09 14:50 pull request complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (2 preceding siblings ...)
  2011-06-09 14:55 ` [PATCH 3/6] complete: add device name complete support for devinfo Jean-Christophe PLAGNIOL-VILLARD
@ 2011-06-09 14:55 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-06-09 14:55 ` [PATCH 5/6] complete: add empty " Jean-Christophe PLAGNIOL-VILLARD
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-06-09 14:55 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 f8387bd..cfc79f5 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
@@ -66,5 +67,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.4.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 5/6] complete: add empty complete support
  2011-06-09 14:50 pull request complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (3 preceding siblings ...)
  2011-06-09 14:55 ` [PATCH 4/6] complete: add help complete support Jean-Christophe PLAGNIOL-VILLARD
@ 2011-06-09 14:55 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-06-09 14:55 ` [PATCH 6/6] complete: add eth interface " Jean-Christophe PLAGNIOL-VILLARD
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-06-09 14:55 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 e19b8de..b42d27b 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>
 
 static void decode_cache(unsigned long size)
 {
@@ -132,5 +133,6 @@ static int do_cpuinfo(struct command *cmdtp, 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 750ace0..2f6a344 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(struct command *cmdtp, 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 14a4249..529c81e 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(struct command *cmdtp, 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 6a6b6c5..343046a 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(struct command *cmdtp, 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 a90eadc..a0055e9 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(struct command *cmdtp, int argc, char *argv[])
 {
@@ -32,5 +33,6 @@ static int do_false(struct command *cmdtp, 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 7d99b73..0c8edbd 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>
 
 #define PASSWD_MAX_LENGTH	(128 + 1)
@@ -60,4 +61,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 26d2fe4..dd56933 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(struct command *cmdtp, int argc, char *argv[])
@@ -15,4 +16,5 @@ static int do_lsmod(struct command *cmdtp, 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 abbaf9c..c068ee3 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(struct command *cmdtp, int argc, char *argv[])
@@ -33,4 +34,5 @@ static int do_meminfo(struct command *cmdtp, 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 9435091..a007976 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 d51fa1a..ebc2f71 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(struct command *cmdtp, int argc, char *argv[])
@@ -32,4 +33,5 @@ static int do_pwd(struct command *cmdtp, 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 90651d5..aefb194 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(struct command *cmdtp, int argc, char *argv[])
 {
@@ -32,4 +33,5 @@ static int do_reginfo(struct command *cmdtp, 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 46ab901..dd1b8ce 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(struct command *cmdtp, int argc, char *argv[])
 {
@@ -34,4 +35,5 @@ static int cmd_reset(struct command *cmdtp, 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 8c77dec..e2bdce8 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(struct command *cmdtp, int argc, char *argv[])
 {
@@ -32,5 +33,6 @@ static int do_true(struct command *cmdtp, 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 0aac78e..c0fed93 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>
 
 static int do_usb(struct command *cmdtp, int argc, char *argv[])
@@ -38,4 +39,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 2b3ac05..ea0bd47 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(struct command *cmdtp, int argc, char *argv[])
 {
@@ -33,5 +34,6 @@ static int do_version(struct command *cmdtp, 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 e197872..586a7eb 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -140,6 +140,11 @@ static int device_param_complete(char begin, struct device_d *dev,
 	return 0;
 }
 
+int empty_complete(struct string_list *sl, char *instr)
+{
+	return 1;
+}
+
 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 d3baed7..e2b5a98 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>
 
@@ -482,6 +483,7 @@ static int do_mycdev(struct command *cmdtp, 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 8dfc99c..4b0e979 100644
--- a/include/complete.h
+++ b/include/complete.h
@@ -10,6 +10,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 d1781bc..df9e169 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>
@@ -480,5 +481,6 @@ out:
 BAREBOX_CMD_START(dhcp)
 	.cmd		= do_dhcp,
 	.usage		= "invoke dhcp client to obtain ip/boot params",
+	BAREBOX_CMD_COMPLETE(empty_complete)
 BAREBOX_CMD_END
 
-- 
1.7.4.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 6/6] complete: add eth interface complete support
  2011-06-09 14:50 pull request complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (4 preceding siblings ...)
  2011-06-09 14:55 ` [PATCH 5/6] complete: add empty " Jean-Christophe PLAGNIOL-VILLARD
@ 2011-06-09 14:55 ` Jean-Christophe PLAGNIOL-VILLARD
  2011-06-09 22:46 ` pull request " Hubert Feurstein
  2011-06-10  1:30 ` Jean-Christophe PLAGNIOL-VILLARD
  7 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-06-09 14:55 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          |   23 +++++++++++++++++++++++
 3 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/commands/net.c b/commands/net.c
index 938463c..347613f 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 4b0e979..ea8c53a 100644
--- a/include/complete.h
+++ b/include/complete.h
@@ -11,6 +11,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 c5b346c..a669613 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>
@@ -63,6 +64,28 @@ 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;
+	char cmd[128];
+	int len, len2;
+
+	len = strlen(instr);
+
+	list_for_each_entry(edev, &netdev_list, list) {
+		sprintf(cmd, "%s%d", edev->dev.name, edev->dev.id);
+		if (!strncmp(instr, cmd, len)) {
+			len2 = strlen(cmd);
+			cmd[len2] = ' ';
+			cmd[len2 + 1] = 0;
+			string_list_add(sl, cmd);
+		}
+	}
+	return 0;
+}
+#endif
+
 int eth_send(void *packet, int length)
 {
 	int ret;
-- 
1.7.4.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: pull request complete support
  2011-06-09 14:50 pull request complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (5 preceding siblings ...)
  2011-06-09 14:55 ` [PATCH 6/6] complete: add eth interface " Jean-Christophe PLAGNIOL-VILLARD
@ 2011-06-09 22:46 ` Hubert Feurstein
  2011-06-10  1:25   ` Jean-Christophe PLAGNIOL-VILLARD
  2011-06-10  1:30 ` Jean-Christophe PLAGNIOL-VILLARD
  7 siblings, 1 reply; 14+ messages in thread
From: Hubert Feurstein @ 2011-06-09 22:46 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

Hi Jean-Christophe,

I've tested it in the sandbox and get an access violation when I type
"dev<TAB>". Here is the backtrace:

#0  0x0040dd1b in strlen (s=0x0) at lib/string.c:228
#1  0x00404652 in device_param_complete (begin=0 '\000',
dev=0xb763fa94, sl=0xbfffefe0, instr=0x0) at common/complete.c:115
#2  0x00404a24 in env_param_complete (sl=0xbfffefe0, instr=0x426160
"dev", eval=0) at common/complete.c:209
#3  0x00404c59 in complete (instr=0x426160 "dev", outstr=0xbffff064)
at common/complete.c:282
#4  0x00415687 in readline (prompt=0x426ac0 "barebox:/ ", buf=0x426160
"dev", len=1024) at lib/readline.c:209
#5  0x00401363 in get_user_input (i=0xbffff1c8) at common/hush.c:414
#6  0x004014c2 in file_get (i=0xbffff1c8) at common/hush.c:463
#7  0x00402e4f in parse_stream (dest=0xbffff154, ctx=0xbffff198,
input=0xbffff1c8, end_trigger=10) at common/hush.c:1278
#8  0x00402fd2 in parse_stream_outer (ctx=0xbffff198, inp=0xbffff1c8,
flag=2) at common/hush.c:1428
#9  0x00403770 in run_shell () at common/hush.c:1647
#10 0x00407d6a in start_barebox () at common/startup.c:167
#11 0x0041f082 in main ()

Best Regards
Hubert

2011/6/9 Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>:
> Hi,
>
>        This patch series add the support of the complete for :
>        - var and device param (set and get)
>        - generic command complete framework
>        - devinfo
>        - help
>        - empty command complete
>        - eth interface
>
>        this will also include the move driver and bus code to drivers/base
>        patch as this series depend on it
>
>        Please pull
> The following changes since commit 6e27bfb15e4e2446753fe9affcc3128772205cec:
>
>  Merge branch 'next' (2011-06-06 11:29:45 +0200)
>
> are available in the git repository at:
>
>  git://uboot.jcrosoft.org/barebox.git complete
>
> Jean-Christophe PLAGNIOL-VILLARD (7):
>      move driver and bus code to drivers/base
>      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
>
>  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/help.c                          |    2 +
>  commands/login.c                         |    2 +
>  commands/lsmod.c                         |    2 +
>  commands/meminfo.c                       |    2 +
>  commands/net.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                        |  183 ++++++++++++++++++++++++++++--
>  drivers/Makefile                         |    1 +
>  drivers/base/Makefile                    |    2 +
>  {lib => drivers/base}/driver.c           |    2 +
>  lib/bus.c => drivers/base/platform_bus.c |    0
>  drivers/usb/gadget/u_serial.c            |    2 +
>  include/command.h                        |    8 ++
>  include/complete.h                       |    7 +
>  lib/Makefile                             |    2 -
>  net/dhcp.c                               |    2 +
>  net/eth.c                                |   23 ++++
>  28 files changed, 253 insertions(+), 13 deletions(-)
>  create mode 100644 drivers/base/Makefile
>  rename {lib => drivers/base}/driver.c (99%)
>  rename lib/bus.c => drivers/base/platform_bus.c (100%)
>
> Best Regards,
> J.
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
>

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

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

* Re: pull request complete support
  2011-06-09 22:46 ` pull request " Hubert Feurstein
@ 2011-06-10  1:25   ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-06-10  1:25 UTC (permalink / raw)
  To: Hubert Feurstein; +Cc: barebox

[-- Attachment #1: Type: text/plain, Size: 1242 bytes --]

On 00:46 Fri 10 Jun     , Hubert Feurstein wrote:
> Hi Jean-Christophe,
> 
> I've tested it in the sandbox and get an access violation when I type
> "dev<TAB>". Here is the backtrace:
> 
> #0  0x0040dd1b in strlen (s=0x0) at lib/string.c:228
> #1  0x00404652 in device_param_complete (begin=0 '\000',
> dev=0xb763fa94, sl=0xbfffefe0, instr=0x0) at common/complete.c:115
> #2  0x00404a24 in env_param_complete (sl=0xbfffefe0, instr=0x426160
> "dev", eval=0) at common/complete.c:209
> #3  0x00404c59 in complete (instr=0x426160 "dev", outstr=0xbffff064)
> at common/complete.c:282
> #4  0x00415687 in readline (prompt=0x426ac0 "barebox:/ ", buf=0x426160
> "dev", len=1024) at lib/readline.c:209
> #5  0x00401363 in get_user_input (i=0xbffff1c8) at common/hush.c:414
> #6  0x004014c2 in file_get (i=0xbffff1c8) at common/hush.c:463
> #7  0x00402e4f in parse_stream (dest=0xbffff154, ctx=0xbffff198,
> input=0xbffff1c8, end_trigger=10) at common/hush.c:1278
> #8  0x00402fd2 in parse_stream_outer (ctx=0xbffff198, inp=0xbffff1c8,
> flag=2) at common/hush.c:1428
> #9  0x00403770 in run_shell () at common/hush.c:1647
> #10 0x00407d6a in start_barebox () at common/startup.c:167
> #11 0x0041f082 in main ()

try with this patch

Best Regards,
J.

[-- Attachment #2: p.patch --]
[-- Type: text/x-diff, Size: 740 bytes --]

diff --git a/common/complete.c b/common/complete.c
index 586a7eb..f9c05b4 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -88,6 +88,9 @@ int device_complete(struct string_list *sl, char *instr)
 	char cmd[128];
 	int len, len2;
 
+	if (!instr)
+		instr = "";
+
 	len = strlen(instr);
 
 	for_each_device(dev) {
@@ -112,6 +115,9 @@ static int device_param_complete(char begin, struct device_d *dev,
 	char *tmp = cmd;
 	int len, len2;
 
+	if (!instr)
+		instr = "";
+
 	len = strlen(instr);
 	if (begin) {
 		tmp[0] = begin;
@@ -156,6 +162,9 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
 	int len, len2;
 	char end = '=';
 
+	if (!instr)
+		instr = "";
+
 	if (eval) {
 		cmd[0] = '$';
 		tmp++;

[-- Attachment #3: Type: text/plain, Size: 149 bytes --]

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

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

* [PATCH v2] complete: add var and device param complete support
  2011-06-09 14:55 ` [PATCH 1/6] complete: add var and device param " Jean-Christophe PLAGNIOL-VILLARD
@ 2011-06-10  1:29   ` Jean-Christophe PLAGNIOL-VILLARD
  2011-06-10  6:53     ` Sascha Hauer
  0 siblings, 1 reply; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-06-10  1:29 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>
---
v2:

make the call device_param_complete safe

Best Regards,
J.
 common/complete.c |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 111 insertions(+), 1 deletions(-)

diff --git a/common/complete.c b/common/complete.c
index 46ba871..5f1df74 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -27,6 +27,7 @@
 #include <libgen.h>
 #include <command.h>
 #include <stringlist.h>
+#include <environment.h>
 
 static int file_complete(struct string_list *sl, char *instr)
 {
@@ -84,6 +85,111 @@ static int command_complete(struct string_list *sl, char *instr)
 	return 0;
 }
 
+static int device_param_complete(char begin, struct device_d *dev,
+				 struct string_list *sl, char *instr)
+{
+	struct param_d *param;
+	char cmd[128];
+	char *tmp = cmd;
+	int len, len2;
+
+	len = strlen(instr);
+	if (begin) {
+		tmp[0] = begin;
+		tmp++;
+	}
+	strcpy(tmp, dev_name(dev));
+	len2 = strlen(dev_name(dev));
+	tmp += len2;
+	tmp[0] = '.';
+	tmp++;
+
+	list_for_each_entry(param, &dev->parameters, list) {
+		memset(tmp, 0x0, 128 - (int)(tmp - cmd));
+		if (!strncmp(instr, param->name, len)) {
+			strcpy(tmp, param->name);
+			len2 = strlen(param->name);
+			if (begin)
+				tmp[len2] = ' ';
+			else
+				tmp[len2] = '=';
+			tmp[len2 + 1] = 0;
+			string_list_add(sl, cmd);
+		}
+	}
+
+	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 cmd[128];
+	char *instr_param;
+	char *tmp = cmd;
+	int len, len2;
+	char end = '=';
+
+	if (eval) {
+		cmd[0] = '$';
+		tmp++;
+		end = ' ';
+	}
+
+	instr_param = strrchr(instr, '.');
+	len = strlen(instr);
+
+	current_c = get_current_context();
+	var = current_c->local->next;
+	while (var) {
+		if (!strncmp(instr, var_name(var), len)) {
+			len2 = strlen(var_name(var));
+			strcpy(tmp, var_name(var));
+			tmp[len2] = end;
+			tmp[len2 + 1] = 0;
+			string_list_add(sl, cmd);
+		}
+		var = var->next;
+	}
+
+	c = get_current_context();
+	while(c) {
+		var = c->global->next;
+		while (var) {
+			if (!strncmp(instr, var_name(var), len)) {
+				len2 = strlen(var_name(var));
+				strcpy(tmp, var_name(var));
+				tmp[len2] = end;
+				tmp[len2 + 1] = 0;
+				string_list_add(sl, cmd);
+			}
+			var = var->next;
+		}
+		c = c->parent;
+	}
+
+	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(0, dev, sl, instr_param);
+		}
+	}
+
+	return 0;
+}
+
 static int tab_pressed = 0;
 
 void complete_reset(void)
@@ -121,8 +227,12 @@ int complete(char *instr, char **outstr)
 		t++;
 		file_complete(&sl, t);
 		instr = t;
-	} else
+	} else {
 		command_complete(&sl, instr);
+		env_param_complete(&sl, instr, 0);
+	}
+	if (*instr == '$')
+		env_param_complete(&sl, instr + 1, 1);
 
 	pos = strlen(instr);
 
-- 
1.7.4.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: pull request complete support
  2011-06-09 14:50 pull request complete support Jean-Christophe PLAGNIOL-VILLARD
                   ` (6 preceding siblings ...)
  2011-06-09 22:46 ` pull request " Hubert Feurstein
@ 2011-06-10  1:30 ` Jean-Christophe PLAGNIOL-VILLARD
  7 siblings, 0 replies; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-06-10  1:30 UTC (permalink / raw)
  To: barebox

On 16:50 Thu 09 Jun     , Jean-Christophe PLAGNIOL-VILLARD wrote:
> Hi,
> 
> 	This patch series add the support of the complete for :
> 	- var and device param (set and get)
> 	- generic command complete framework
> 	- devinfo
> 	- help
> 	- empty command complete
> 	- eth interface
> 
> 	this will also include the move driver and bus code to drivers/base
> 	patch as this series depend on it
git updated with
[PATCH v2] complete: add var and device param complete support

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

* Re: [PATCH v2] complete: add var and device param complete support
  2011-06-10  1:29   ` [PATCH v2] " Jean-Christophe PLAGNIOL-VILLARD
@ 2011-06-10  6:53     ` Sascha Hauer
  2011-06-10  7:03       ` Jean-Christophe PLAGNIOL-VILLARD
  0 siblings, 1 reply; 14+ messages in thread
From: Sascha Hauer @ 2011-06-10  6:53 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Fri, Jun 10, 2011 at 03:29:27AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> with $xx or xx= or if device $xx.yy or xx.yy=
> 
> Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> ---
> v2:
> 
> make the call device_param_complete safe
> 
> Best Regards,
> J.
>  common/complete.c |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
>  1 files changed, 111 insertions(+), 1 deletions(-)
> 
> diff --git a/common/complete.c b/common/complete.c
> index 46ba871..5f1df74 100644
> --- a/common/complete.c
> +++ b/common/complete.c
> @@ -27,6 +27,7 @@
>  #include <libgen.h>
>  #include <command.h>
>  #include <stringlist.h>
> +#include <environment.h>
>  
>  static int file_complete(struct string_list *sl, char *instr)
>  {
> @@ -84,6 +85,111 @@ static int command_complete(struct string_list *sl, char *instr)
>  	return 0;
>  }
>  
> +static int device_param_complete(char begin, struct device_d *dev,
> +				 struct string_list *sl, char *instr)
> +{
> +	struct param_d *param;
> +	char cmd[128];
> +	char *tmp = cmd;
> +	int len, len2;
> +
> +	len = strlen(instr);
> +	if (begin) {
> +		tmp[0] = begin;
> +		tmp++;
> +	}
> +	strcpy(tmp, dev_name(dev));
> +	len2 = strlen(dev_name(dev));
> +	tmp += len2;
> +	tmp[0] = '.';
> +	tmp++;
> +
> +	list_for_each_entry(param, &dev->parameters, list) {
> +		memset(tmp, 0x0, 128 - (int)(tmp - cmd));
> +		if (!strncmp(instr, param->name, len)) {
> +			strcpy(tmp, param->name);
> +			len2 = strlen(param->name);
> +			if (begin)
> +				tmp[len2] = ' ';
> +			else
> +				tmp[len2] = '=';
> +			tmp[len2 + 1] = 0;
> +			string_list_add(sl, cmd);
> +		}
> +	}

The fixed length arrays might overflow. Maybe not in this function, but
when this becomes a template maybe in other functions. Looking at it
this code could really improve with sprintf, more specifically
string_list_asprintf. I'll post a patch in a minute.

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

* Re: [PATCH v2] complete: add var and device param complete support
  2011-06-10  6:53     ` Sascha Hauer
@ 2011-06-10  7:03       ` Jean-Christophe PLAGNIOL-VILLARD
  2011-06-10  8:00         ` Sascha Hauer
  0 siblings, 1 reply; 14+ messages in thread
From: Jean-Christophe PLAGNIOL-VILLARD @ 2011-06-10  7:03 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: barebox

On 08:53 Fri 10 Jun     , Sascha Hauer wrote:
> On Fri, Jun 10, 2011 at 03:29:27AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > with $xx or xx= or if device $xx.yy or xx.yy=
> > 
> > Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
> > ---
> > v2:
> > 
> > make the call device_param_complete safe
> > 
> > Best Regards,
> > J.
> >  common/complete.c |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
> >  1 files changed, 111 insertions(+), 1 deletions(-)
> > 
> > diff --git a/common/complete.c b/common/complete.c
> > index 46ba871..5f1df74 100644
> > --- a/common/complete.c
> > +++ b/common/complete.c
> > @@ -27,6 +27,7 @@
> >  #include <libgen.h>
> >  #include <command.h>
> >  #include <stringlist.h>
> > +#include <environment.h>
> >  
> >  static int file_complete(struct string_list *sl, char *instr)
> >  {
> > @@ -84,6 +85,111 @@ static int command_complete(struct string_list *sl, char *instr)
> >  	return 0;
> >  }
> >  
> > +static int device_param_complete(char begin, struct device_d *dev,
> > +				 struct string_list *sl, char *instr)
> > +{
> > +	struct param_d *param;
> > +	char cmd[128];
> > +	char *tmp = cmd;
> > +	int len, len2;
> > +
> > +	len = strlen(instr);
> > +	if (begin) {
> > +		tmp[0] = begin;
> > +		tmp++;
> > +	}
> > +	strcpy(tmp, dev_name(dev));
> > +	len2 = strlen(dev_name(dev));
> > +	tmp += len2;
> > +	tmp[0] = '.';
> > +	tmp++;
> > +
> > +	list_for_each_entry(param, &dev->parameters, list) {
> > +		memset(tmp, 0x0, 128 - (int)(tmp - cmd));
> > +		if (!strncmp(instr, param->name, len)) {
> > +			strcpy(tmp, param->name);
> > +			len2 = strlen(param->name);
> > +			if (begin)
> > +				tmp[len2] = ' ';
> > +			else
> > +				tmp[len2] = '=';
> > +			tmp[len2 + 1] = 0;
> > +			string_list_add(sl, cmd);
> > +		}
> > +	}
> 
> The fixed length arrays might overflow. Maybe not in this function, but
> when this becomes a template maybe in other functions. Looking at it
> this code could really improve with sprintf, more specifically
> string_list_asprintf. I'll post a patch in a minute.
can we do it in a second step?

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

* Re: [PATCH v2] complete: add var and device param complete support
  2011-06-10  7:03       ` Jean-Christophe PLAGNIOL-VILLARD
@ 2011-06-10  8:00         ` Sascha Hauer
  0 siblings, 0 replies; 14+ messages in thread
From: Sascha Hauer @ 2011-06-10  8:00 UTC (permalink / raw)
  To: Jean-Christophe PLAGNIOL-VILLARD; +Cc: barebox

On Fri, Jun 10, 2011 at 09:03:42AM +0200, Jean-Christophe PLAGNIOL-VILLARD wrote:
> > >  
> > > +static int device_param_complete(char begin, struct device_d *dev,
> > > +				 struct string_list *sl, char *instr)
> > > +{
> > > +	struct param_d *param;
> > > +	char cmd[128];
> > > +	char *tmp = cmd;
> > > +	int len, len2;
> > > +
> > > +	len = strlen(instr);
> > > +	if (begin) {
> > > +		tmp[0] = begin;
> > > +		tmp++;
> > > +	}
> > > +	strcpy(tmp, dev_name(dev));
> > > +	len2 = strlen(dev_name(dev));
> > > +	tmp += len2;
> > > +	tmp[0] = '.';
> > > +	tmp++;
> > > +
> > > +	list_for_each_entry(param, &dev->parameters, list) {
> > > +		memset(tmp, 0x0, 128 - (int)(tmp - cmd));
> > > +		if (!strncmp(instr, param->name, len)) {
> > > +			strcpy(tmp, param->name);
> > > +			len2 = strlen(param->name);
> > > +			if (begin)
> > > +				tmp[len2] = ' ';
> > > +			else
> > > +				tmp[len2] = '=';
> > > +			tmp[len2 + 1] = 0;
> > > +			string_list_add(sl, cmd);
> > > +		}
> > > +	}
> > 
> > The fixed length arrays might overflow. Maybe not in this function, but
> > when this becomes a template maybe in other functions. Looking at it
> > this code could really improve with sprintf, more specifically
> > string_list_asprintf. I'll post a patch in a minute.
> can we do it in a second step?

No, this creates more work for all of us. Consider your code may have
bugs, then by applying this patch we will expose them to the users which
will cause bug reports we have to work on. Then we switch to
string_list_asprintf which may have bugs aswell.

I know you have limited time and for this reason you want to see your
patches upstream asap, but this can't be the excuse for delaying
cleanups as we *all* have limited time.

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

end of thread, other threads:[~2011-06-10  8:00 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-06-09 14:50 pull request complete support Jean-Christophe PLAGNIOL-VILLARD
2011-06-09 14:55 ` [PATCH 1/6] complete: add var and device param " Jean-Christophe PLAGNIOL-VILLARD
2011-06-10  1:29   ` [PATCH v2] " Jean-Christophe PLAGNIOL-VILLARD
2011-06-10  6:53     ` Sascha Hauer
2011-06-10  7:03       ` Jean-Christophe PLAGNIOL-VILLARD
2011-06-10  8:00         ` Sascha Hauer
2011-06-09 14:55 ` [PATCH 2/6] complete: add generic command complete framework Jean-Christophe PLAGNIOL-VILLARD
2011-06-09 14:55 ` [PATCH 3/6] complete: add device name complete support for devinfo Jean-Christophe PLAGNIOL-VILLARD
2011-06-09 14:55 ` [PATCH 4/6] complete: add help complete support Jean-Christophe PLAGNIOL-VILLARD
2011-06-09 14:55 ` [PATCH 5/6] complete: add empty " Jean-Christophe PLAGNIOL-VILLARD
2011-06-09 14:55 ` [PATCH 6/6] complete: add eth interface " Jean-Christophe PLAGNIOL-VILLARD
2011-06-09 22:46 ` pull request " Hubert Feurstein
2011-06-10  1:25   ` Jean-Christophe PLAGNIOL-VILLARD
2011-06-10  1:30 ` 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