|
@@ -1,3 +1,21 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
|
|
3
|
+ *
|
|
4
|
+ * This program is free software; you can redistribute it and/or
|
|
5
|
+ * modify it under the terms of the GNU General Public License as
|
|
6
|
+ * published by the Free Software Foundation; either version 2 of the
|
|
7
|
+ * License, or any later version.
|
|
8
|
+ *
|
|
9
|
+ * This program is distributed in the hope that it will be useful, but
|
|
10
|
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
12
|
+ * General Public License for more details.
|
|
13
|
+ *
|
|
14
|
+ * You should have received a copy of the GNU General Public License
|
|
15
|
+ * along with this program; if not, write to the Free Software
|
|
16
|
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17
|
+ */
|
|
18
|
+
|
1
|
19
|
#include <stdint.h>
|
2
|
20
|
#include <stdlib.h>
|
3
|
21
|
#include <stdio.h>
|
|
@@ -6,42 +24,96 @@
|
6
|
24
|
#include <getopt.h>
|
7
|
25
|
#include <ipxe/settings.h>
|
8
|
26
|
#include <ipxe/command.h>
|
|
27
|
+#include <ipxe/parseopt.h>
|
9
|
28
|
|
10
|
29
|
FILE_LICENCE ( GPL2_OR_LATER );
|
11
|
30
|
|
|
31
|
+/** @file
|
|
32
|
+ *
|
|
33
|
+ * Non-volatile option commands
|
|
34
|
+ *
|
|
35
|
+ */
|
|
36
|
+
|
|
37
|
+/** "show" options */
|
|
38
|
+struct show_options {};
|
|
39
|
+
|
|
40
|
+/** "show" option list */
|
|
41
|
+static struct option_descriptor show_opts[] = {};
|
|
42
|
+
|
|
43
|
+/** "show" command descriptor */
|
|
44
|
+static struct command_descriptor show_cmd =
|
|
45
|
+ COMMAND_DESC ( struct show_options, show_opts, 1, 1,
|
|
46
|
+ "<setting>", "" );
|
|
47
|
+
|
|
48
|
+/**
|
|
49
|
+ * "show" command
|
|
50
|
+ *
|
|
51
|
+ * @v argc Argument count
|
|
52
|
+ * @v argv Argument list
|
|
53
|
+ * @ret rc Return status code
|
|
54
|
+ */
|
12
|
55
|
static int show_exec ( int argc, char **argv ) {
|
|
56
|
+ struct show_options opts;
|
|
57
|
+ const char *name;
|
13
|
58
|
char buf[256];
|
14
|
59
|
int rc;
|
15
|
60
|
|
16
|
|
- if ( argc != 2 ) {
|
17
|
|
- printf ( "Syntax: %s <identifier>\n", argv[0] );
|
18
|
|
- return 1;
|
19
|
|
- }
|
|
61
|
+ /* Parse options */
|
|
62
|
+ if ( ( rc = parse_options ( argc, argv, &show_cmd, &opts ) ) != 0 )
|
|
63
|
+ return rc;
|
20
|
64
|
|
21
|
|
- if ( ( rc = fetchf_named_setting ( argv[1], buf,
|
22
|
|
- sizeof ( buf ) ) ) < 0 ){
|
|
65
|
+ /* Parse setting name */
|
|
66
|
+ name = argv[optind];
|
|
67
|
+
|
|
68
|
+ /* Fetch setting */
|
|
69
|
+ if ( ( rc = fetchf_named_setting ( name, buf,
|
|
70
|
+ sizeof ( buf ) ) ) < 0 ) {
|
23
|
71
|
printf ( "Could not find \"%s\": %s\n",
|
24
|
|
- argv[1], strerror ( rc ) );
|
25
|
|
- return 1;
|
|
72
|
+ name, strerror ( rc ) );
|
|
73
|
+ return rc;
|
26
|
74
|
}
|
27
|
75
|
|
28
|
|
- printf ( "%s = %s\n", argv[1], buf );
|
|
76
|
+ /* Print setting value */
|
|
77
|
+ printf ( "%s = %s\n", name, buf );
|
|
78
|
+
|
29
|
79
|
return 0;
|
30
|
80
|
}
|
31
|
81
|
|
|
82
|
+/** "set" options */
|
|
83
|
+struct set_options {};
|
|
84
|
+
|
|
85
|
+/** "set" option list */
|
|
86
|
+static struct option_descriptor set_opts[] = {};
|
|
87
|
+
|
|
88
|
+/** "set" command descriptor */
|
|
89
|
+static struct command_descriptor set_cmd =
|
|
90
|
+ COMMAND_DESC ( struct set_options, set_opts, 2, MAX_ARGUMENTS,
|
|
91
|
+ "<setting> <value>", "" );
|
|
92
|
+
|
|
93
|
+/**
|
|
94
|
+ * "set" command
|
|
95
|
+ *
|
|
96
|
+ * @v argc Argument count
|
|
97
|
+ * @v argv Argument list
|
|
98
|
+ * @ret rc Return status code
|
|
99
|
+ */
|
32
|
100
|
static int set_exec ( int argc, char **argv ) {
|
|
101
|
+ struct set_options opts;
|
|
102
|
+ const char *name;
|
33
|
103
|
size_t len;
|
34
|
104
|
int i;
|
35
|
105
|
int rc;
|
36
|
106
|
|
37
|
|
- if ( argc < 3 ) {
|
38
|
|
- printf ( "Syntax: %s <identifier> <value>\n", argv[0] );
|
39
|
|
- return 1;
|
40
|
|
- }
|
|
107
|
+ /* Parse options */
|
|
108
|
+ if ( ( rc = parse_options ( argc, argv, &set_cmd, &opts ) ) != 0 )
|
|
109
|
+ return rc;
|
|
110
|
+
|
|
111
|
+ /* Parse setting name */
|
|
112
|
+ name = argv[optind];
|
41
|
113
|
|
42
|
114
|
/* Determine total length of command line */
|
43
|
115
|
len = 1; /* NUL */
|
44
|
|
- for ( i = 2 ; i < argc ; i++ )
|
|
116
|
+ for ( i = optind + 1 ; i < argc ; i++ )
|
45
|
117
|
len += ( 1 /* possible space */ + strlen ( argv[i] ) );
|
46
|
118
|
|
47
|
119
|
{
|
|
@@ -50,39 +122,63 @@ static int set_exec ( int argc, char **argv ) {
|
50
|
122
|
|
51
|
123
|
/* Assemble command line */
|
52
|
124
|
buf[0] = '\0';
|
53
|
|
- for ( i = 2 ; i < argc ; i++ ) {
|
|
125
|
+ for ( i = optind + 1 ; i < argc ; i++ ) {
|
54
|
126
|
ptr += sprintf ( ptr, "%s%s", ( buf[0] ? " " : "" ),
|
55
|
127
|
argv[i] );
|
56
|
128
|
}
|
57
|
129
|
assert ( ptr < ( buf + len ) );
|
58
|
130
|
|
59
|
|
- if ( ( rc = storef_named_setting ( argv[1], buf ) ) != 0 ) {
|
|
131
|
+ if ( ( rc = storef_named_setting ( name, buf ) ) != 0 ) {
|
60
|
132
|
printf ( "Could not set \"%s\"=\"%s\": %s\n",
|
61
|
|
- argv[1], buf, strerror ( rc ) );
|
62
|
|
- return 1;
|
|
133
|
+ name, buf, strerror ( rc ) );
|
|
134
|
+ return rc;
|
63
|
135
|
}
|
64
|
136
|
}
|
65
|
137
|
|
66
|
138
|
return 0;
|
67
|
139
|
}
|
68
|
140
|
|
|
141
|
+/** "clear" options */
|
|
142
|
+struct clear_options {};
|
|
143
|
+
|
|
144
|
+/** "clear" option list */
|
|
145
|
+static struct option_descriptor clear_opts[] = {};
|
|
146
|
+
|
|
147
|
+/** "clear" command descriptor */
|
|
148
|
+static struct command_descriptor clear_cmd =
|
|
149
|
+ COMMAND_DESC ( struct clear_options, clear_opts, 1, 1,
|
|
150
|
+ "<setting>", "" );
|
|
151
|
+
|
|
152
|
+/**
|
|
153
|
+ * "clear" command
|
|
154
|
+ *
|
|
155
|
+ * @v argc Argument count
|
|
156
|
+ * @v argv Argument list
|
|
157
|
+ * @ret rc Return status code
|
|
158
|
+ */
|
69
|
159
|
static int clear_exec ( int argc, char **argv ) {
|
|
160
|
+ struct clear_options opts;
|
|
161
|
+ const char *name;
|
70
|
162
|
int rc;
|
71
|
163
|
|
72
|
|
- if ( argc != 2 ) {
|
73
|
|
- printf ( "Syntax: %s <identifier>\n", argv[0] );
|
74
|
|
- return 1;
|
75
|
|
- }
|
|
164
|
+ /* Parse options */
|
|
165
|
+ if ( ( rc = parse_options ( argc, argv, &clear_cmd, &opts ) ) != 0 )
|
|
166
|
+ return rc;
|
|
167
|
+
|
|
168
|
+ /* Parse setting name */
|
|
169
|
+ name = argv[optind];
|
76
|
170
|
|
77
|
|
- if ( ( rc = delete_named_setting ( argv[1] ) ) != 0 ) {
|
|
171
|
+ /* Clear setting */
|
|
172
|
+ if ( ( rc = delete_named_setting ( name ) ) != 0 ) {
|
78
|
173
|
printf ( "Could not clear \"%s\": %s\n",
|
79
|
|
- argv[1], strerror ( rc ) );
|
80
|
|
- return 1;
|
|
174
|
+ name, strerror ( rc ) );
|
|
175
|
+ return rc;
|
81
|
176
|
}
|
82
|
177
|
|
83
|
178
|
return 0;
|
84
|
179
|
}
|
85
|
180
|
|
|
181
|
+/** Non-volatile option commands */
|
86
|
182
|
struct command nvo_commands[] __command = {
|
87
|
183
|
{
|
88
|
184
|
.name = "show",
|