Skip to contentSkip to conversation

pull request complete support

PATCH New Jean-Christophe PLAGNIOL-VILLARD 3 participants 14 messages Jun 9, 2011 – Jun 10, 2011

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#1 lore raw

PATCH 1/6 complete: add var and device param complete support

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

---
 common/complete.c |  111 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 110 insertions(+), 1 deletions(-)
common/complete.c +110 -1
index 46ba871..9d9f166 100644
@@ -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);
 
Signature · 7 lines
1.7.4.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#2 lore raw

PATCH v2 1/1 complete: add var and device param complete support

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

---
v2:

make the call device_param_complete safe

Best Regards,
J.

 common/complete.c |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 111 insertions(+), 1 deletions(-)
common/complete.c +111 -1
index 46ba871..5f1df74 100644
@@ -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);
 
Signature · 7 lines
1.7.4.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
maintainer
#3 lore raw

Re: [PATCH v2] complete: add var and device param complete support

Quoted 51 lines · Jean-Christophe PLAGNIOL-VILLARD

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

---
v2:

make the call device_param_complete safe

Best Regards,
J.

 common/complete.c |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 111 insertions(+), 1 deletions(-)
common/complete.c +23 -0
index 46ba871..5f1df74 100644
@@ -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)) {

common/complete.c static int command_complete(struct string_list *sl, char *instr) · line 119

Quoted 10 lines
common/complete.c +10 -0
+			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

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#4 lore raw

Re: [PATCH v2] complete: add var and device param complete support

Quoted 59 lines · Sascha Hauer
Quoted 58 lines · Jean-Christophe PLAGNIOL-VILLARD

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

---
v2:

make the call device_param_complete safe

Best Regards,
J.

 common/complete.c |  112 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 111 insertions(+), 1 deletions(-)
common/complete.c +30 -0
index 46ba871..5f1df74 100644
@@ -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;
Quoted 8 lines

common/complete.c static int command_complete(struct string_list *sl, char *instr) · line 119

Quoted 3 lines
common/complete.c +3 -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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

maintainer
#5 lore raw

Re: [PATCH v2] complete: add var and device param complete support

Quoted 38 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 30 lines
Quoted 30 lines
common/complete.c +29 -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;
Quoted 8 lines

common/complete.c static int command_complete(struct string_list *sl, char *instr) · line 119

Quoted 3 lines
common/complete.c +3 -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.

Quoted 1 line

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

Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#6 lore raw

PATCH 2/6 complete: add generic command complete framework

In reply to Jean-Christophe PLAGNIOL-VILLARD

introduce generic command specific complete callback

---
 common/complete.c  |   53 ++++++++++++++++++++++++++++++++++++++-------------
 include/command.h  |    8 +++++++
 include/complete.h |    4 +++
 3 files changed, 51 insertions(+), 14 deletions(-)
common/complete.c +39 -14
index 9d9f166..098b80d 100644
@@ -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);
 
include/command.h +8 -0
index e221546..75afd95 100644
@@ -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[] =
include/complete.h +4 -0
index cc0e88d..3f1fe89 100644
@@ -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_ */
 
Signature · 7 lines
1.7.4.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#7 lore raw

PATCH 3/6 complete: add device name complete support for devinfo

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 common/complete.c     |   22 ++++++++++++++++++++++
 drivers/base/driver.c |    2 ++
 include/complete.h    |    1 +
 3 files changed, 25 insertions(+), 0 deletions(-)
common/complete.c +22 -0
index 098b80d..e197872 100644
@@ -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)
 {
drivers/base/driver.c +2 -0
index 4c10a49..ea1dc6e 100644
@@ -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
 
include/complete.h +1 -0
index 3f1fe89..8dfc99c 100644
@@ -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_ */
 
Signature · 7 lines
1.7.4.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#8 lore raw

PATCH 4/6 complete: add help complete support

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 commands/help.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
commands/help.c +2 -0
index f8387bd..cfc79f5 100644
@@ -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
 
Signature · 7 lines
1.7.4.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#9 lore raw

PATCH 5/6 complete: add empty complete support

In reply to Jean-Christophe PLAGNIOL-VILLARD

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

---
 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(-)
arch/arm/cpu/cpuinfo.c +2 -0
index e19b8de..b42d27b 100644
@@ -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
 
arch/arm/mach-imx/speed.c +2 -0
index 750ace0..2f6a344 100644
@@ -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
 
arch/arm/mach-mxs/imx.c +2 -0
index 14a4249..529c81e 100644
@@ -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
commands/clear.c +2 -0
index 6a6b6c5..343046a 100644
@@ -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
commands/false.c +2 -0
index a90eadc..a0055e9 100644
@@ -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
 
commands/login.c +2 -0
index 7d99b73..0c8edbd 100644
@@ -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
commands/lsmod.c +2 -0
index 26d2fe4..dd56933 100644
@@ -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
commands/meminfo.c +2 -0
index abbaf9c..c068ee3 100644
@@ -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
commands/passwd.c +2 -0
index 9435091..a007976 100644
@@ -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
commands/pwd.c +2 -0
index d51fa1a..ebc2f71 100644
@@ -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
commands/reginfo.c +2 -0
index 90651d5..aefb194 100644
@@ -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
commands/reset.c +2 -0
index 46ab901..dd1b8ce 100644
@@ -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
commands/true.c +2 -0
index 8c77dec..e2bdce8 100644
@@ -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
 
commands/usb.c +2 -0
index 0aac78e..c0fed93 100644
@@ -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
commands/version.c +2 -0
index 2b3ac05..ea0bd47 100644
@@ -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
 
common/complete.c +5 -0
index e197872..586a7eb 100644
@@ -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;
drivers/usb/gadget/u_serial.c +2 -0
index d3baed7..e2b5a98 100644
@@ -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
 
 /**
include/complete.h +1 -0
index 8dfc99c..4b0e979 100644
@@ -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_ */
 
net/dhcp.c +2 -0
index d1781bc..df9e169 100644
@@ -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
 
Signature · 7 lines
1.7.4.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#10 lore raw

PATCH 6/6 complete: add eth interface complete support

In reply to Jean-Christophe PLAGNIOL-VILLARD

use it on ethact

---
 commands/net.c     |    2 ++
 include/complete.h |    1 +
 net/eth.c          |   23 +++++++++++++++++++++++
 3 files changed, 26 insertions(+), 0 deletions(-)
commands/net.c +2 -0
index 938463c..347613f 100644
@@ -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
 
include/complete.h +1 -0
index 4b0e979..ea8c53a 100644
@@ -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_ */
 
net/eth.c +23 -0
index c5b346c..a669613 100644
@@ -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;
Signature · 7 lines
1.7.4.1


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
#11 lore raw
In reply to Jean-Christophe PLAGNIOL-VILLARD

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 <[email protected]>:

Quoted 64 lines

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%)

Quoted 8 lines

Best Regards,
J.

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#12 lore raw
Quoted 17 lines · Hubert Feurstein

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,
Quoted 6 lines

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.

common/complete.c +9 -0
index 586a7eb..f9c05b4 100644
@@ -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++;

_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox

#13 lore raw
In reply to Jean-Christophe PLAGNIOL-VILLARD
Quoted 10 lines · Jean-Christophe PLAGNIOL-VILLARD

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

Quoted 2 lines

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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox