mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Cc: ukl@pengutronix.de
Subject: [PATCH] completion: fix device parameter completion
Date: Thu,  6 Aug 2015 16:27:24 +0200	[thread overview]
Message-ID: <1438871244-16849-1-git-send-email-s.hauer@pengutronix.de> (raw)

With device parameter completion the '.' separator between the device
name and the parameter was not handled correctly. For example with
a device named global a completion starting with "g." was completed to
"g.obal.". fix this.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/complete.c | 35 +++++++++++++++++++----------------
 1 file changed, 19 insertions(+), 16 deletions(-)

diff --git a/common/complete.c b/common/complete.c
index f0ef576..aee21ea 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -169,15 +169,12 @@ int device_complete(struct string_list *sl, char *instr)
 }
 EXPORT_SYMBOL(device_complete);
 
-static int device_param_complete(char *begin, struct device_d *dev,
-				 struct string_list *sl, char *instr)
+static int device_param_complete(struct device_d *dev, struct string_list *sl,
+				 char *instr, int eval)
 {
 	struct param_d *param;
 	int len;
 
-	if (!instr)
-		instr = "";
-
 	len = strlen(instr);
 
 	list_for_each_entry(param, &dev->parameters, list) {
@@ -185,8 +182,8 @@ static int device_param_complete(char *begin, struct device_d *dev,
 			continue;
 
 		string_list_add_asprintf(sl, "%s%s.%s%c",
-			begin ? begin : "", dev_name(dev), param->name,
-			begin ? ' ' : '=');
+			eval ? "$" : "", dev_name(dev), param->name,
+			eval ? ' ' : '=');
 	}
 
 	return 0;
@@ -316,20 +313,26 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
 	}
 
 	if (instr_param) {
+		char *devname;
+
 		len = (instr_param - instr);
+
+		devname = xstrndup(instr, len);
+
 		instr_param++;
-	} else {
-		len = strlen(instr);
-		instr_param = "";
+
+		dev = get_device_by_name(devname);
+		free(devname);
+		if (dev)
+			device_param_complete(dev, sl, instr_param, eval);
+		return 0;
 	}
 
+	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(NULL, dev, sl, instr_param);
-		}
+		if (!strncmp(instr, dev_name(dev), len))
+			device_param_complete(dev, sl, "", eval);
 	}
 
 	return 0;
-- 
2.4.6


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

                 reply	other threads:[~2015-08-06 14:27 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1438871244-16849-1-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    --cc=ukl@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox