瀏覽代碼

[settings] Modify "set" command to allow space separated values

Allow multiple, space separated values (such as kernel arguments,
passed via DHCP) to be assigned to an identifier using the "set"
command.

Originally-implemented-by: Aaron Brooks <aaron@brooks1.net>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 年之前
父節點
當前提交
c4af205cf0
共有 1 個檔案被更改,包括 25 行新增5 行删除
  1. 25
    5
      src/hci/commands/nvo_cmd.c

+ 25
- 5
src/hci/commands/nvo_cmd.c 查看文件

@@ -30,17 +30,37 @@ static int show_exec ( int argc, char **argv ) {
30 30
 }
31 31
 
32 32
 static int set_exec ( int argc, char **argv ) {
33
+	size_t len;
34
+	int i;
33 35
 	int rc;
34 36
 
35
-	if ( argc != 3 ) {
37
+	if ( argc < 3 ) {
36 38
 		printf ( "Syntax: %s <identifier> <value>\n", argv[0] );
37 39
 		return 1;
38 40
 	}
39 41
 
40
-	if ( ( rc = storef_named_setting ( argv[1], argv[2] ) ) != 0 ) {
41
-		printf ( "Could not set \"%s\"=\"%s\": %s\n",
42
-			 argv[1], argv[2], strerror ( rc ) );
43
-		return 1;
42
+	/* Determine total length of command line */
43
+	len = 1; /* NUL */
44
+	for ( i = 2 ; i < argc ; i++ )
45
+		len += ( 1 /* possible space */ + strlen ( argv[i] ) );
46
+
47
+	{
48
+		char buf[len];
49
+		char *ptr = buf;
50
+
51
+		/* Assemble command line */
52
+		buf[0] = '\0';
53
+		for ( i = 2 ; i < argc ; i++ ) {
54
+			ptr += sprintf ( ptr, "%s%s", ( buf[0] ? " " : "" ),
55
+					 argv[i] );
56
+		}
57
+		assert ( ptr < ( buf + len ) );
58
+
59
+		if ( ( rc = storef_named_setting ( argv[1], buf ) ) != 0 ) {
60
+			printf ( "Could not set \"%s\"=\"%s\": %s\n",
61
+				 argv[1], buf, strerror ( rc ) );
62
+			return 1;
63
+		}
44 64
 	}
45 65
 
46 66
 	return 0;

Loading…
取消
儲存