* [PATCH 1/2] Allow device parameters for devices with dots in name
@ 2016-10-07 7:09 Sascha Hauer
2016-10-07 7:09 ` [PATCH 2/2] completion: Fix completion for devices with a dot in the name Sascha Hauer
0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2016-10-07 7:09 UTC (permalink / raw)
To: Barebox List
Devices can have a dot in the name, so we can't expect to find the
full device name before the first dot. Currently parameters of devices
with a dot in the name are inaccessible from the shell.
Fix this by iterating over the possible device name / parameter name
combinations to find a existing combination.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/env.c | 48 ++++++++++++++++++++++++++++++++++--------------
1 file changed, 34 insertions(+), 14 deletions(-)
diff --git a/common/env.c b/common/env.c
index 6f736d5..df8a4df 100644
--- a/common/env.c
+++ b/common/env.c
@@ -135,26 +135,46 @@ static const char *getenv_raw(struct list_head *l, const char *name)
return NULL;
}
-const char *getenv (const char *name)
+static const char *dev_getenv(const char *name)
{
- struct env_context *c;
- const char *val;
+ const char *pos, *val, *dot, *varname;
+ char *devname;
+ struct device_d *dev;
+
+ pos = name;
+
+ while (1) {
+ dot = strchr(pos, '.');
+ if (!dot)
+ break;
+
+ devname = xstrndup(name, dot - name);
+ varname = dot + 1;
+
+ dev = get_device_by_name(devname);
+
+ free(devname);
- if (strchr(name, '.')) {
- const char *ret = NULL;
- char *devstr = strdup(name);
- char *par = strchr(devstr, '.');
- struct device_d *dev;
- *par = 0;
- dev = get_device_by_name(devstr);
if (dev) {
- par++;
- ret = dev_get_param(dev, par);
+ val = dev_get_param(dev, varname);
+ if (val)
+ return val;
}
- free(devstr);
- return ret;
+
+ pos = dot + 1;
}
+ return NULL;
+}
+
+const char *getenv(const char *name)
+{
+ struct env_context *c;
+ const char *val;
+
+ if (strchr(name, '.'))
+ return dev_getenv(name);
+
c = context;
val = getenv_raw(&c->local, name);
--
2.9.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] completion: Fix completion for devices with a dot in the name
2016-10-07 7:09 [PATCH 1/2] Allow device parameters for devices with dots in name Sascha Hauer
@ 2016-10-07 7:09 ` Sascha Hauer
0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2016-10-07 7:09 UTC (permalink / raw)
To: Barebox List
Devices can have a dot in the name, so do not expect the full
device name before the first dot.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
common/complete.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/common/complete.c b/common/complete.c
index aee21ea..2dab7d1 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -279,7 +279,7 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
struct env_context *c;
char *instr_param;
int len;
- char end = '=';
+ char end = '=', *pos, *dot;
char *begin = "";
if (!instr)
@@ -290,7 +290,6 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
end = ' ';
}
- instr_param = strchr(instr, '.');
len = strlen(instr);
c = get_current_context();
@@ -312,20 +311,21 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
c = c->parent;
}
- if (instr_param) {
+ pos = instr;
+ while ((dot = strchr(pos, '.'))) {
char *devname;
- len = (instr_param - instr);
-
- devname = xstrndup(instr, len);
+ devname = xstrndup(instr, dot - instr);
instr_param++;
dev = get_device_by_name(devname);
free(devname);
+
if (dev)
- device_param_complete(dev, sl, instr_param, eval);
- return 0;
+ device_param_complete(dev, sl, dot + 1, eval);
+
+ pos = dot + 1;
}
len = strlen(instr);
--
2.9.3
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-10-07 7:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-07 7:09 [PATCH 1/2] Allow device parameters for devices with dots in name Sascha Hauer
2016-10-07 7:09 ` [PATCH 2/2] completion: Fix completion for devices with a dot in the name Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox