Skip to contentSkip to conversation

improve complete support

PATCH Superseded Jean-Christophe PLAGNIOL-VILLARD 2 participants 19 messages Apr 19, 2012 – Apr 23, 2012

Subsystems (8)
Networking Arm (32-bit) VFS USB +4 more subsystems

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover improve complete support

Hi,

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

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

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

The following changes since commit a7ddbc40865a8ffe716aca686763780febad575c:

Merge branch 'binfmt' of git://git.jcrosoft.org/barebox into next (2012-04-18 20:42:17 +0200)

are available in the git repository at:

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

for you to fetch changes up to fcbc878be12d1c8d2bf839255b1bb7bd465adb96:

complete: add executable file support (2012-04-19 13:49:42 +0800)

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

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

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

Best Regards,
J.

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

#1 lore raw

PATCH v2 1/11 stringlist: use seperately allocated string

From: Sascha Hauer <[email protected]>

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

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


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

PATCH v2 2/11 stringlist: implement string_list_add_asprintf

In reply to Jean-Christophe PLAGNIOL-VILLARD

From: Sascha Hauer <[email protected]>

Useful for allocating a string list entry on the fly.

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


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

PATCH v2 3/11 complete: add var and device param complete support

In reply to Jean-Christophe PLAGNIOL-VILLARD

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

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


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

PATCH v2 4/11 complete: add generic command complete framework

In reply to Jean-Christophe PLAGNIOL-VILLARD

introduce generic command specific complete callback

---
 common/complete.c  |   55 +++++++++++++++++++++++++++++++++++++--------------
 include/command.h  |    8 +++++++
 include/complete.h |    4 +++
 3 files changed, 52 insertions(+), 15 deletions(-)
common/complete.c +40 -15
index 9d749e0..9515072 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)
@@ -131,7 +128,7 @@ static int path_command_complete(struct string_list *sl, char *instr)
 	return 0;
 }
 
-static int command_complete(struct string_list *sl, char *instr)
+int command_complete(struct string_list *sl, char *instr)
 {
 	struct command *cmdtp;
 
@@ -236,6 +233,32 @@ void complete_reset(void)
 	tab_pressed = 0;
 }
 
+static char* cmd_complete_lookup(struct string_list *sl, char *instr)
+{
+	struct command *cmdtp;
+	int len;
+	int ret = 1;
+	char *res = NULL;
+
+	for_each_command(cmdtp) {
+		len = strlen(cmdtp->name);
+		if (!strncmp(instr, cmdtp->name, len) && instr[len] == ' ') {
+			instr += len + 1;
+			if (cmdtp->complete) {
+				ret = cmdtp->complete(sl, instr);
+				res = instr;
+			}
+			goto end;
+		}
+	}
+
+end:
+	if (!ret && *instr == '$')
+		env_param_complete(sl, instr + 1, 1);
+
+	return res;
+}
+
 int complete(char *instr, char **outstr)
 {
 	struct string_list sl, *entry, *first_entry;
@@ -259,20 +282,22 @@ int complete(char *instr, char **outstr)
 	while (*t == ' ')
 		t++;
 
-	instr = t;
-
 	/* get the completion possibilities */
-	if ((t = strrchr(t, ' '))) {
-		t++;
-		file_complete(&sl, t);
+	instr = cmd_complete_lookup(&sl, t);
+	if (!instr) {
 		instr = t;
-	} else {
-		command_complete(&sl, instr);
-		path_command_complete(&sl, instr);
-		env_param_complete(&sl, instr, 0);
+		if ((t = strrchr(t, ' '))) {
+			t++;
+			file_complete(&sl, t);
+			instr = t;
+		} else {
+			command_complete(&sl, instr);
+			path_command_complete(&sl, instr);
+			env_param_complete(&sl, instr, 0);
+		}
+		if (*instr == '$')
+			env_param_complete(&sl, instr + 1, 1);
 	}
-	if (*instr == '$')
-		env_param_complete(&sl, instr + 1, 1);
 
 	pos = strlen(instr);
 
include/command.h +8 -0
index b2e8449..80cbf56 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)(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.9.1


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

PATCH v2 5/11 complete: add device name complete support for devinfo

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 common/complete.c     |   20 ++++++++++++++++++++
 drivers/base/driver.c |    2 ++
 include/complete.h    |    1 +
 3 files changed, 23 insertions(+), 0 deletions(-)
common/complete.c +20 -0
index 9515072..cf06101 100644
@@ -145,6 +145,26 @@ int command_complete(struct string_list *sl, char *instr)
 	return 0;
 }
 
+int device_complete(struct string_list *sl, char *instr)
+{
+	struct device_d *dev;
+	int len;
+
+	if (!instr)
+		instr = "";
+
+	len = strlen(instr);
+
+	for_each_device(dev) {
+		if (strncmp(instr, dev_name(dev), len))
+			continue;
+
+		string_list_add_asprintf(sl, "%s ", dev_name(dev));
+	}
+
+	return 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 2d206f9..03b1834 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);
@@ -443,6 +444,7 @@ BAREBOX_CMD_START(devinfo)
 	.cmd		= do_devinfo,
 	.usage		= "Show information about devices and drivers.",
 	BAREBOX_CMD_HELP(cmd_devinfo_help)
+	BAREBOX_CMD_COMPLETE(device_complete)
 BAREBOX_CMD_END
 #endif
 
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.9.1


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

PATCH v2 6/11 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 706b905..d7d9ba2 100644
@@ -23,6 +23,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 
 /*
  * Use puts() instead of printf() to avoid printf buffer overflow
@@ -68,5 +69,6 @@ BAREBOX_CMD_START(help)
 	.aliases	= help_aliases,
 	.usage		= "print online help",
 	BAREBOX_CMD_HELP(cmd_help_help)
+	BAREBOX_CMD_COMPLETE(command_complete)
 BAREBOX_CMD_END
 
Signature · 7 lines
1.7.9.1


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

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


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

PATCH v2 8/11 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          |   21 +++++++++++++++++++++
 3 files changed, 24 insertions(+), 0 deletions(-)
commands/net.c +2 -0
index c5c6373..a453f4e 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 +21 -0
index 130805b..1c35e5b 100644
@@ -23,6 +23,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <driver.h>
 #include <init.h>
 #include <net.h>
@@ -109,6 +110,26 @@ struct eth_device *eth_get_byname(char *ethname)
 	return NULL;
 }
 
+#ifdef CONFIG_AUTO_COMPLETE
+int eth_complete(struct string_list *sl, char *instr)
+{
+	struct eth_device *edev;
+	const char *devname;
+	int len;
+
+	len = strlen(instr);
+
+	list_for_each_entry(edev, &netdev_list, list) {
+		devname = dev_name(&edev->dev);
+		if (strncmp(instr, devname, len))
+			continue;
+
+		string_list_add_asprintf(sl, "%s ", devname);
+	}
+	return 0;
+}
+#endif
+
 int eth_send(void *packet, int length)
 {
 	int ret;
Signature · 7 lines
1.7.9.1


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

PATCH v2 9/11 complete: add go and sleep support

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 commands/go.c      |    2 ++
 commands/sleep.c   |    2 ++
 common/complete.c  |    5 +++++
 include/complete.h |    1 +
 4 files changed, 10 insertions(+), 0 deletions(-)
commands/go.c +2 -0
index c821207..e9e9d40 100644
@@ -25,6 +25,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <fs.h>
 #include <fcntl.h>
 #include <linux/ctype.h>
@@ -91,4 +92,5 @@ BAREBOX_CMD_START(go)
 	.cmd		= do_go,
 	.usage		= "start application at address or file",
 	BAREBOX_CMD_HELP(cmd_go_help)
+	BAREBOX_CMD_COMPLETE(cammand_var_complete)
 BAREBOX_CMD_END
commands/sleep.c +2 -0
index f772e87..c5f7867 100644
@@ -22,6 +22,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <clock.h>
 
 static int do_sleep(int argc, char *argv[])
@@ -46,4 +47,5 @@ static int do_sleep(int argc, char *argv[])
 BAREBOX_CMD_START(sleep)
 	.cmd		= do_sleep,
 	.usage		= "delay execution for n seconds",
+	BAREBOX_CMD_COMPLETE(cammand_var_complete)
 BAREBOX_CMD_END
common/complete.c +5 -0
index 5213b10..9ecce25 100644
@@ -193,6 +193,11 @@ int empty_complete(struct string_list *sl, char *instr)
 	return 1;
 }
 
+int cammand_var_complete(struct string_list *sl, char *instr)
+{
+	return 0;
+}
+
 static int env_param_complete(struct string_list *sl, char *instr, int eval)
 {
 	struct device_d *dev;
include/complete.h +1 -0
index ea8c53a..4336a26 100644
@@ -12,6 +12,7 @@ int command_complete(struct string_list *sl, char *instr);
 int device_complete(struct string_list *sl, char *instr);
 int empty_complete(struct string_list *sl, char *instr);
 int eth_complete(struct string_list *sl, char *instr);
+int cammand_var_complete(struct string_list *sl, char *instr);
 
 #endif /* __COMPLETE_ */
 
Signature · 7 lines
1.7.9.1


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

Re: [PATCH 09/11] complete: add go and sleep support

Quoted 49 lines · Jean-Christophe PLAGNIOL-VILLARD
---
 commands/go.c      |    2 ++
 commands/sleep.c   |    2 ++
 common/complete.c  |    5 +++++
 include/complete.h |    1 +
 4 files changed, 10 insertions(+), 0 deletions(-)
commands/go.c +2 -0
index c821207..e9e9d40 100644
@@ -25,6 +25,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <fs.h>
 #include <fcntl.h>
 #include <linux/ctype.h>
@@ -91,4 +92,5 @@ BAREBOX_CMD_START(go)
 	.cmd		= do_go,
 	.usage		= "start application at address or file",
 	BAREBOX_CMD_HELP(cmd_go_help)
+	BAREBOX_CMD_COMPLETE(cammand_var_complete)
 BAREBOX_CMD_END
commands/sleep.c +2 -0
index f772e87..c5f7867 100644
@@ -22,6 +22,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <clock.h>
 
 static int do_sleep(int argc, char *argv[])
@@ -46,4 +47,5 @@ static int do_sleep(int argc, char *argv[])
 BAREBOX_CMD_START(sleep)
 	.cmd		= do_sleep,
 	.usage		= "delay execution for n seconds",
+	BAREBOX_CMD_COMPLETE(cammand_var_complete)
 BAREBOX_CMD_END
common/complete.c +0 -0
index 5213b10..9ecce25 100644

common/complete.c int empty_complete(struct string_list *sl, char *instr) · line 199

Quoted 7 lines
common/complete.c +4 -0
@@ -193,6 +193,11 @@ int empty_complete(struct string_list *sl, char *instr)
 	return 1;
 }
 
+int cammand_var_complete(struct string_list *sl, char *instr)
+{
+	return 0;
+}

Two patches before this one you introduced empty_complete. This function does the same, except that it returns 0 instead of 1. The return value of the complete functions is never checked, so what is going on here?

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
#11 lore raw

Re: [PATCH 09/11] complete: add go and sleep support

Quoted 53 lines · Sascha Hauer
Quoted 52 lines · Jean-Christophe PLAGNIOL-VILLARD
---
 commands/go.c      |    2 ++
 commands/sleep.c   |    2 ++
 common/complete.c  |    5 +++++
 include/complete.h |    1 +
 4 files changed, 10 insertions(+), 0 deletions(-)
commands/go.c +2 -0
index c821207..e9e9d40 100644
@@ -25,6 +25,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <fs.h>
 #include <fcntl.h>
 #include <linux/ctype.h>
@@ -91,4 +92,5 @@ BAREBOX_CMD_START(go)
 	.cmd		= do_go,
 	.usage		= "start application at address or file",
 	BAREBOX_CMD_HELP(cmd_go_help)
+	BAREBOX_CMD_COMPLETE(cammand_var_complete)
 BAREBOX_CMD_END
commands/sleep.c +2 -0
index f772e87..c5f7867 100644
@@ -22,6 +22,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <clock.h>
 
 static int do_sleep(int argc, char *argv[])
@@ -46,4 +47,5 @@ static int do_sleep(int argc, char *argv[])
 BAREBOX_CMD_START(sleep)
 	.cmd		= do_sleep,
 	.usage		= "delay execution for n seconds",
+	BAREBOX_CMD_COMPLETE(cammand_var_complete)
 BAREBOX_CMD_END
common/complete.c +0 -0
index 5213b10..9ecce25 100644
@@ -193,6 +193,11 @@ int empty_complete(struct string_list *sl, char *instr)
 	return 1;
 }
 
Quoted 8 lines

common/complete.c int empty_complete(struct string_list *sl, char *instr) · line 199

Quoted 4 lines
common/complete.c +4 -0
+int cammand_var_complete(struct string_list *sl, char *instr)
+{
+	return 0;
+}

Two patches before this one you introduced empty_complete. This function does the same, except that it returns 0 instead of 1. The return value of the complete functions is never checked, so what is going on here?

the return value is checked.

no this different we return 0 as you can use env var complete

the empty_complete means no args.

Bst Regards,

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

maintainer
#12 lore raw

Re: [PATCH 09/11] complete: add go and sleep support

Quoted 23 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 13 lines · Sascha Hauer
Quoted 13 lines

BAREBOX_CMD_START(sleep)

commands/sleep.c +1 -0
 	.cmd		= do_sleep,
 	.usage		= "delay execution for n seconds",
+	BAREBOX_CMD_COMPLETE(cammand_var_complete)
 BAREBOX_CMD_END
common/complete.c +0 -0
index 5213b10..9ecce25 100644
@@ -193,6 +193,11 @@ int empty_complete(struct string_list *sl, char *instr)
 	return 1;
 }
 
Quoted 8 lines

common/complete.c int empty_complete(struct string_list *sl, char *instr) · line 199

Quoted 4 lines
common/complete.c +4 -0
+int cammand_var_complete(struct string_list *sl, char *instr)
+{
+	return 0;
+}

Two patches before this one you introduced empty_complete. This function does the same, except that it returns 0 instead of 1. The return value of the complete functions is never checked, so what is going on here?

Quoted 3 lines

the return value is checked.

no this different we return 0 as you can use env var complete

Can you then add a meaningful comment what command cmdtp->complete should return and what it means? A define instead of using '1' may make sense aswell.

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
#13 lore raw

Re: [PATCH 09/11] complete: add go and sleep support

Quoted 24 lines · Sascha Hauer
Quoted 23 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 21 lines · Sascha Hauer
Quoted 10 lines

BAREBOX_CMD_START(sleep)

commands/sleep.c +1 -0
 	.cmd		= do_sleep,
 	.usage		= "delay execution for n seconds",
+	BAREBOX_CMD_COMPLETE(cammand_var_complete)
 BAREBOX_CMD_END
common/complete.c +0 -0
index 5213b10..9ecce25 100644

common/complete.c int empty_complete(struct string_list *sl, char *instr) · line 199

Quoted 7 lines
common/complete.c +4 -0
@@ -193,6 +193,11 @@ int empty_complete(struct string_list *sl, char *instr)
 	return 1;
 }
 
+int cammand_var_complete(struct string_list *sl, char *instr)
+{
+	return 0;
+}

Two patches before this one you introduced empty_complete. This function does the same, except that it returns 0 instead of 1. The return value of the complete functions is never checked, so what is going on here?

Quoted 7 lines
Quoted 3 lines

the return value is checked.

no this different we return 0 as you can use env var complete

Can you then add a meaningful comment what command cmdtp->complete should return and what it means? A define instead of using '1' may make sense aswell.

ok will ad any other comment?

Best Regards,
J.

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

maintainer
#14 lore raw

Re: [PATCH 09/11] complete: add go and sleep support

Quoted 25 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 24 lines · Sascha Hauer
Quoted 23 lines · Jean-Christophe PLAGNIOL-VILLARD
Quoted 21 lines · Sascha Hauer
Quoted 10 lines

BAREBOX_CMD_START(sleep)

commands/sleep.c +1 -0
 	.cmd		= do_sleep,
 	.usage		= "delay execution for n seconds",
+	BAREBOX_CMD_COMPLETE(cammand_var_complete)
 BAREBOX_CMD_END
common/complete.c +0 -0
index 5213b10..9ecce25 100644

common/complete.c int empty_complete(struct string_list *sl, char *instr) · line 199

Quoted 7 lines
common/complete.c +4 -0
@@ -193,6 +193,11 @@ int empty_complete(struct string_list *sl, char *instr)
 	return 1;
 }
 
+int cammand_var_complete(struct string_list *sl, char *instr)
+{
+	return 0;
+}

Two patches before this one you introduced empty_complete. This function does the same, except that it returns 0 instead of 1. The return value of the complete functions is never checked, so what is going on here?

Quoted 8 lines
Quoted 7 lines
Quoted 3 lines

the return value is checked.

no this different we return 0 as you can use env var complete

Can you then add a meaningful comment what command cmdtp->complete should return and what it means? A define instead of using '1' may make sense aswell.

ok will ad any other comment?

No, should be ok then.

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
#15 lore raw

PATCH v2 10/11 complete: add delpart complete support

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 commands/partition.c |    2 ++
 fs/devfs-core.c      |   19 +++++++++++++++++++
 include/complete.h   |    1 +
 3 files changed, 22 insertions(+), 0 deletions(-)
commands/partition.c +2 -0
index 4892261..6cce042 100644
@@ -32,6 +32,7 @@
 
 #include <common.h>
 #include <command.h>
+#include <complete.h>
 #include <driver.h>
 #include <malloc.h>
 #include <partition.h>
@@ -225,5 +226,6 @@ BAREBOX_CMD_START(delpart)
 	.cmd = do_delpart,
 	.usage = "delete partition(s)",
 	BAREBOX_CMD_HELP(cmd_delpart_help)
+	BAREBOX_CMD_COMPLETE(devfs_partition_complete)
 BAREBOX_CMD_END
 
fs/devfs-core.c +19 -0
index 3014d0e..4a34df6 100644
@@ -20,6 +20,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #include <common.h>
+#include <complete.h>
 #include <driver.h>
 #include <errno.h>
 #include <malloc.h>
@@ -29,6 +30,24 @@
 
 LIST_HEAD(cdev_list);
 
+#ifdef CONFIG_AUTO_COMPLETE
+int devfs_partition_complete(struct string_list *sl, char *instr)
+{
+	struct cdev *cdev;
+	int len;
+
+	len = strlen(instr);
+
+	list_for_each_entry(cdev, &cdev_list, list) {
+		if (cdev->flags & DEVFS_IS_PARTITION &&
+		    !strncmp(instr, cdev->name, len)) {
+			string_list_add_asprintf(sl, "%s ", cdev->name);
+		}
+	}
+	return 0;
+}
+#endif
+
 struct cdev *cdev_by_name(const char *filename)
 {
 	struct cdev *cdev;
include/complete.h +1 -0
index 4336a26..c029809 100644
@@ -13,6 +13,7 @@ int device_complete(struct string_list *sl, char *instr);
 int empty_complete(struct string_list *sl, char *instr);
 int eth_complete(struct string_list *sl, char *instr);
 int cammand_var_complete(struct string_list *sl, char *instr);
+int devfs_partition_complete(struct string_list *sl, char *instr);
 
 #endif /* __COMPLETE_ */
 
Signature · 7 lines
1.7.9.1


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

PATCH v2 11/11 complete: add executable file support

In reply to Jean-Christophe PLAGNIOL-VILLARD
---
 common/complete.c |   30 +++++++++++++++++++-----------
 1 files changed, 19 insertions(+), 11 deletions(-)
common/complete.c +19 -11
index 9ecce25..01e9f5d 100644
@@ -26,7 +26,7 @@
 #include <command.h>
 #include <environment.h>
 
-static int file_complete(struct string_list *sl, char *instr)
+static int file_complete(struct string_list *sl, char *instr, int exec)
 {
 	char *path = strdup(instr);
 	struct stat s;
@@ -46,15 +46,20 @@ static int file_complete(struct string_list *sl, char *instr)
 		if (!strcmp(d->d_name, ".") || !strcmp(d->d_name, ".."))
 			continue;
 
-		if (!strncmp(base, d->d_name, strlen(base))) {
-			strcpy(tmp, instr);
-			strcat(tmp, d->d_name + strlen(base));
-			if (!stat(tmp, &s) && S_ISDIR(s.st_mode))
-				strcat(tmp, "/");
-			else
-				strcat(tmp, " ");
-			string_list_add_sorted(sl, tmp);
+		if (strncmp(base, d->d_name, strlen(base)))
+			continue;
+
+		strcpy(tmp, instr);
+		strcat(tmp, d->d_name + strlen(base));
+		if (!stat(tmp, &s) && S_ISDIR(s.st_mode)) {
+			strcat(tmp, "/");
+		} else {
+			if (exec && !S_ISREG(s.st_mode))
+				continue;
+			strcat(tmp, " ");
 		}
+
+		string_list_add_sorted(sl, tmp);
 	}
 
 	closedir(dir);
@@ -316,9 +321,12 @@ int complete(char *instr, char **outstr)
 	instr = cmd_complete_lookup(&sl, t);
 	if (!instr) {
 		instr = t;
-		if ((t = strrchr(t, ' '))) {
+		if (t && (t[0] == '/' || !strncmp(t, "./", 2))) {
+			file_complete(&sl, t, 1);
+			instr = t;
+		} else if ((t = strrchr(t, ' '))) {
 			t++;
-			file_complete(&sl, t);
+			file_complete(&sl, t, 0);
 			instr = t;
 		} else {
 			command_complete(&sl, instr);
Signature · 7 lines
1.7.9.1


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

Hi,

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

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

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

The following changes since commit a7ddbc40865a8ffe716aca686763780febad575c:

Merge branch 'binfmt' of git://git.jcrosoft.org/barebox into next (2012-04-18 20:42:17 +0200)

Quoted 8 lines

are available in the git repository at:

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

for you to fetch changes up to fcbc878be12d1c8d2bf839255b1bb7bd465adb96:

complete: add executable file support (2012-04-19 13:49:42 +0800)

Looks interesting, I just gave it a try. I didn't have a close look at it yet. The variable completion feels strange. Pressing a<tab><tab> expands to

barebox@Phytec phyCORE-i.MX27:/ a
addpart autoboot_timeout=
a= armlinux_architecture=

I really don't expect this and it seems quite non standard. Not sure if I like it.

Another thing is, does it make sense to add a CONFIG_AUTO_COMPLETE_ADVANCED for the more obscure completions?

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
#18 lore raw
Quoted 29 lines · Sascha Hauer
Quoted 15 lines · Jean-Christophe PLAGNIOL-VILLARD

Hi,

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

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

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

The following changes since commit a7ddbc40865a8ffe716aca686763780febad575c:

Merge branch 'binfmt' of git://git.jcrosoft.org/barebox into next (2012-04-18 20:42:17 +0200)

Quoted 8 lines

are available in the git repository at:

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

for you to fetch changes up to fcbc878be12d1c8d2bf839255b1bb7bd465adb96:

complete: add executable file support (2012-04-19 13:49:42 +0800)

Looks interesting, I just gave it a try. I didn't have a close look at it yet. The variable completion feels strange. Pressing a<tab><tab> expands to

Quoted 6 lines

barebox@Phytec phyCORE-i.MX27:/ a
addpart autoboot_timeout=
a= armlinux_architecture=

I really don't expect this and it seems quite non standard. Not sure if I like it.

Agreed it's not standard but after using it you become quite used to it

Quoted 3 lines

Another thing is, does it make sense to add a CONFIG_AUTO_COMPLETE_ADVANCED for the more obscure completions?

yeah was not sure aout it too
but as the auto complete is here to help I choose to don't do so

as exmple devinfo you surch for display the current param of a device the complete help you to go to it more quick see the param with 2 <tab> with typing devinfo fb0

And them see that this driver have a probe or not etc...

when you do echo $eth0<tab><tab> you can easly choose and see the available param

Best Regards,
J.

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