[PATCH v2 1/3] complete: give device_param_complete a flags parameter

Ahmad Fatoum a.fatoum at pengutronix.de
Wed Mar 19 22:20:57 PDT 2025


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 at 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




More information about the barebox mailing list