Browse Source

[parseopt] Allow for pre-initialised option sets

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 years ago
parent
commit
3ca5656208
2 changed files with 24 additions and 7 deletions
  1. 22
    7
      src/core/parseopt.c
  2. 2
    0
      src/include/ipxe/parseopt.h

+ 22
- 7
src/core/parseopt.c View File

152
 }
152
 }
153
 
153
 
154
 /**
154
 /**
155
- * Parse command-line options
155
+ * Reparse command-line options
156
  *
156
  *
157
  * @v argc		Argument count
157
  * @v argc		Argument count
158
  * @v argv		Argument list
158
  * @v argv		Argument list
159
  * @v cmd		Command descriptor
159
  * @v cmd		Command descriptor
160
- * @v opts		Options
160
+ * @v opts		Options (already initialised with default values)
161
  * @ret rc		Return status code
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
 	struct option longopts[ cmd->num_options + 1 /* help */ + 1 /* end */ ];
165
 	struct option longopts[ cmd->num_options + 1 /* help */ + 1 /* end */ ];
166
 	char shortopts[ cmd->num_options * 3 /* possible "::" */ + 1 /* "h" */
166
 	char shortopts[ cmd->num_options * 3 /* possible "::" */ + 1 /* "h" */
167
 			+ 1 /* NUL */ ];
167
 			+ 1 /* NUL */ ];
193
 	DBGC ( cmd,  "Command \"%s\" has options \"%s\", %d-%d args, len %d\n",
193
 	DBGC ( cmd,  "Command \"%s\" has options \"%s\", %d-%d args, len %d\n",
194
 	       argv[0], shortopts, cmd->min_args, cmd->max_args, cmd->len );
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
 	/* Parse options */
196
 	/* Parse options */
200
 	while ( ( c = getopt_long ( argc, argv, shortopts, longopts,
197
 	while ( ( c = getopt_long ( argc, argv, shortopts, longopts,
201
 				    NULL ) ) >= 0 ) {
198
 				    NULL ) ) >= 0 ) {
233
 
230
 
234
 	return 0;
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 View File

120
 extern int parse_image ( const char *text, struct image **image );
120
 extern int parse_image ( const char *text, struct image **image );
121
 extern int parse_flag ( const char *text __unused, int *flag );
121
 extern int parse_flag ( const char *text __unused, int *flag );
122
 extern void print_usage ( struct command_descriptor *cmd, char **argv );
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
 extern int parse_options ( int argc, char **argv,
125
 extern int parse_options ( int argc, char **argv,
124
 			   struct command_descriptor *cmd, void *opts );
126
 			   struct command_descriptor *cmd, void *opts );
125
 
127
 

Loading…
Cancel
Save