浏览代码

[parseopt] Allow for pre-initialised option sets

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 年前
父节点
当前提交
3ca5656208
共有 2 个文件被更改,包括 24 次插入7 次删除
  1. 22
    7
      src/core/parseopt.c
  2. 2
    0
      src/include/ipxe/parseopt.h

+ 22
- 7
src/core/parseopt.c 查看文件

@@ -152,16 +152,16 @@ void print_usage ( struct command_descriptor *cmd, char **argv ) {
152 152
 }
153 153
 
154 154
 /**
155
- * Parse command-line options
155
+ * Reparse command-line options
156 156
  *
157 157
  * @v argc		Argument count
158 158
  * @v argv		Argument list
159 159
  * @v cmd		Command descriptor
160
- * @v opts		Options
160
+ * @v opts		Options (already initialised with default values)
161 161
  * @ret rc		Return status code
162 162
  */
163
-int parse_options ( int argc, char **argv, struct command_descriptor *cmd,
164
-		    void *opts ) {
163
+int reparse_options ( int argc, char **argv, struct command_descriptor *cmd,
164
+		      void *opts ) {
165 165
 	struct option longopts[ cmd->num_options + 1 /* help */ + 1 /* end */ ];
166 166
 	char shortopts[ cmd->num_options * 3 /* possible "::" */ + 1 /* "h" */
167 167
 			+ 1 /* NUL */ ];
@@ -193,9 +193,6 @@ int parse_options ( int argc, char **argv, struct command_descriptor *cmd,
193 193
 	DBGC ( cmd,  "Command \"%s\" has options \"%s\", %d-%d args, len %d\n",
194 194
 	       argv[0], shortopts, cmd->min_args, cmd->max_args, cmd->len );
195 195
 
196
-	/* Clear options */
197
-	memset ( opts, 0, cmd->len );
198
-
199 196
 	/* Parse options */
200 197
 	while ( ( c = getopt_long ( argc, argv, shortopts, longopts,
201 198
 				    NULL ) ) >= 0 ) {
@@ -233,3 +230,21 @@ int parse_options ( int argc, char **argv, struct command_descriptor *cmd,
233 230
 
234 231
 	return 0;
235 232
 }
233
+
234
+/**
235
+ * Parse command-line options
236
+ *
237
+ * @v argc		Argument count
238
+ * @v argv		Argument list
239
+ * @v cmd		Command descriptor
240
+ * @v opts		Options (may be uninitialised)
241
+ * @ret rc		Return status code
242
+ */
243
+int parse_options ( int argc, char **argv, struct command_descriptor *cmd,
244
+		    void *opts ) {
245
+
246
+	/* Clear options */
247
+	memset ( opts, 0, cmd->len );
248
+
249
+	return reparse_options ( argc, argv, cmd, opts );
250
+}

+ 2
- 0
src/include/ipxe/parseopt.h 查看文件

@@ -120,6 +120,8 @@ extern int parse_netdev ( const char *text, struct net_device **netdev );
120 120
 extern int parse_image ( const char *text, struct image **image );
121 121
 extern int parse_flag ( const char *text __unused, int *flag );
122 122
 extern void print_usage ( struct command_descriptor *cmd, char **argv );
123
+extern int reparse_options ( int argc, char **argv,
124
+			     struct command_descriptor *cmd, void *opts );
123 125
 extern int parse_options ( int argc, char **argv,
124 126
 			   struct command_descriptor *cmd, void *opts );
125 127
 

正在加载...
取消
保存