mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH v2 1/3] complete: give device_param_complete a flags parameter
Date: Thu, 20 Mar 2025 06:20:57 +0100	[thread overview]
Message-ID: <20250320052059.1732184-1-a.fatoum@pengutronix.de> (raw)

We currently always complete device parameters with either a dollar sign
in front or an equal sign after. In preparation for allowing completions
with neither, give env_param_complete() a flag.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
v1 -> v2:
  - new patch
---
 common/complete.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)

diff --git a/common/complete.c b/common/complete.c
index 5b8b499ed38f..6061c8ba6ecb 100644
--- a/common/complete.c
+++ b/common/complete.c
@@ -9,11 +9,15 @@
 #include <complete.h>
 #include <xfuncs.h>
 #include <fs.h>
+#include <linux/bits.h>
 #include <linux/stat.h>
 #include <libgen.h>
 #include <command.h>
 #include <environment.h>
 
+#define DEVPARAM_COMPLETE_ASSIGNMENT	BIT(0)
+#define DEVPARAM_COMPLETE_DOLLAR	BIT(1)
+
 static bool is_valid_escape(const char *str)
 {
 	return str[0] == '\\' && (str[1] == ' ' || str[1] == '\\');
@@ -170,7 +174,8 @@ int device_complete(struct string_list *sl, char *instr)
 EXPORT_SYMBOL(device_complete);
 
 static int device_param_complete(struct device *dev, const char *devname,
-				 struct string_list *sl, char *instr, int eval)
+				 struct string_list *sl, char *instr,
+				 unsigned flags)
 {
 	struct param_d *param;
 
@@ -179,8 +184,8 @@ static int device_param_complete(struct device *dev, const char *devname,
 			continue;
 
 		string_list_add_asprintf(sl, "%s%s.%s%c",
-			eval ? "$" : "", devname, param->name,
-			eval ? ' ' : '=');
+			flags & DEVPARAM_COMPLETE_DOLLAR ? "$" : "", devname, param->name,
+			flags & DEVPARAM_COMPLETE_ASSIGNMENT ? '=' : ' ');
 	}
 
 	return 0;
@@ -292,21 +297,22 @@ int tutorial_complete(struct string_list *sl, char *instr)
 }
 EXPORT_SYMBOL(tutorial_complete);
 
-static int env_param_complete(struct string_list *sl, char *instr, int eval)
+static int env_param_complete(struct string_list *sl, char *instr, unsigned flags)
 {
 	struct device *dev;
 	struct variable_d *var;
 	struct env_context *c;
 	int len;
-	char end = '=', *pos, *dot;
+	char end = ' ', *pos, *dot;
 	char *begin = "";
 
 	if (!instr)
 		instr = "";
 
-	if (eval) {
+	if (flags & DEVPARAM_COMPLETE_DOLLAR) {
 		begin = "$";
-		end = ' ';
+	} else if (flags & DEVPARAM_COMPLETE_ASSIGNMENT) {
+		end = '=';
 	}
 
 	len = strlen(instr);
@@ -338,7 +344,7 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
 		dev = get_device_by_name(devname);
 
 		if (dev)
-			device_param_complete(dev, devname, sl, dot + 1, eval);
+			device_param_complete(dev, devname, sl, dot + 1, flags);
 
 		free(devname);
 		pos = dot + 1;
@@ -348,7 +354,7 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
 
 	for_each_device(dev) {
 		if (!strncmp(instr, dev_name(dev), len))
-			device_param_complete(dev, dev_name(dev), sl, "", eval);
+			device_param_complete(dev, dev_name(dev), sl, "", flags);
 	}
 
 	return 0;
@@ -356,7 +362,7 @@ static int env_param_complete(struct string_list *sl, char *instr, int eval)
 
 int env_param_noeval_complete(struct string_list *sl, char *instr)
 {
-	return env_param_complete(sl, instr, 0);
+	return env_param_complete(sl, instr, DEVPARAM_COMPLETE_ASSIGNMENT);
 }
 EXPORT_SYMBOL(env_param_noeval_complete);
 
@@ -415,7 +421,7 @@ static char* cmd_complete_lookup(struct string_list *sl, char *instr)
 
 end:
 	if (ret == COMPLETE_CONTINUE && *instr == '$')
-		env_param_complete(sl, instr + 1, 1);
+		env_param_complete(sl, instr + 1, DEVPARAM_COMPLETE_DOLLAR);
 
 	return res;
 }
@@ -460,7 +466,7 @@ int complete(char *instr, char **outstr)
 			env_param_complete(&sl, instr, 0);
 		}
 		if (*instr == '$')
-			env_param_complete(&sl, instr + 1, 1);
+			env_param_complete(&sl, instr + 1, DEVPARAM_COMPLETE_DOLLAR);
 	}
 
 	pos = strlen_escaped(instr);
-- 
2.39.5




             reply	other threads:[~2025-03-20  5:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-20  5:20 Ahmad Fatoum [this message]
2025-03-20  5:20 ` [PATCH v2 2/3] env: add envvar_for_each helper for variable iteration Ahmad Fatoum
2025-03-20  5:20 ` [PATCH v2 3/3] commands: add varinfo command Ahmad Fatoum

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=20250320052059.1732184-1-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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