소스 검색

[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…
취소
저장