mirror of https://github.com/ipxe/ipxe.git
[parseopt] Allow for pre-initialised option sets
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/5/head
parent
8e984f35e0
commit
3ca5656208
|
@ -152,15 +152,15 @@ void print_usage ( struct command_descriptor *cmd, char **argv ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse command-line options
|
* Reparse command-line options
|
||||||
*
|
*
|
||||||
* @v argc Argument count
|
* @v argc Argument count
|
||||||
* @v argv Argument list
|
* @v argv Argument list
|
||||||
* @v cmd Command descriptor
|
* @v cmd Command descriptor
|
||||||
* @v opts Options
|
* @v opts Options (already initialised with default values)
|
||||||
* @ret rc Return status code
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
int parse_options ( int argc, char **argv, struct command_descriptor *cmd,
|
int reparse_options ( int argc, char **argv, struct command_descriptor *cmd,
|
||||||
void *opts ) {
|
void *opts ) {
|
||||||
struct option longopts[ cmd->num_options + 1 /* help */ + 1 /* end */ ];
|
struct option longopts[ cmd->num_options + 1 /* help */ + 1 /* end */ ];
|
||||||
char shortopts[ cmd->num_options * 3 /* possible "::" */ + 1 /* "h" */
|
char shortopts[ cmd->num_options * 3 /* possible "::" */ + 1 /* "h" */
|
||||||
|
@ -193,9 +193,6 @@ int parse_options ( int argc, char **argv, struct command_descriptor *cmd,
|
||||||
DBGC ( cmd, "Command \"%s\" has options \"%s\", %d-%d args, len %d\n",
|
DBGC ( cmd, "Command \"%s\" has options \"%s\", %d-%d args, len %d\n",
|
||||||
argv[0], shortopts, cmd->min_args, cmd->max_args, cmd->len );
|
argv[0], shortopts, cmd->min_args, cmd->max_args, cmd->len );
|
||||||
|
|
||||||
/* Clear options */
|
|
||||||
memset ( opts, 0, cmd->len );
|
|
||||||
|
|
||||||
/* Parse options */
|
/* Parse options */
|
||||||
while ( ( c = getopt_long ( argc, argv, shortopts, longopts,
|
while ( ( c = getopt_long ( argc, argv, shortopts, longopts,
|
||||||
NULL ) ) >= 0 ) {
|
NULL ) ) >= 0 ) {
|
||||||
|
@ -233,3 +230,21 @@ int parse_options ( int argc, char **argv, struct command_descriptor *cmd,
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse command-line options
|
||||||
|
*
|
||||||
|
* @v argc Argument count
|
||||||
|
* @v argv Argument list
|
||||||
|
* @v cmd Command descriptor
|
||||||
|
* @v opts Options (may be uninitialised)
|
||||||
|
* @ret rc Return status code
|
||||||
|
*/
|
||||||
|
int parse_options ( int argc, char **argv, struct command_descriptor *cmd,
|
||||||
|
void *opts ) {
|
||||||
|
|
||||||
|
/* Clear options */
|
||||||
|
memset ( opts, 0, cmd->len );
|
||||||
|
|
||||||
|
return reparse_options ( argc, argv, cmd, opts );
|
||||||
|
}
|
||||||
|
|
|
@ -120,6 +120,8 @@ extern int parse_netdev ( const char *text, struct net_device **netdev );
|
||||||
extern int parse_image ( const char *text, struct image **image );
|
extern int parse_image ( const char *text, struct image **image );
|
||||||
extern int parse_flag ( const char *text __unused, int *flag );
|
extern int parse_flag ( const char *text __unused, int *flag );
|
||||||
extern void print_usage ( struct command_descriptor *cmd, char **argv );
|
extern void print_usage ( struct command_descriptor *cmd, char **argv );
|
||||||
|
extern int reparse_options ( int argc, char **argv,
|
||||||
|
struct command_descriptor *cmd, void *opts );
|
||||||
extern int parse_options ( int argc, char **argv,
|
extern int parse_options ( int argc, char **argv,
|
||||||
struct command_descriptor *cmd, void *opts );
|
struct command_descriptor *cmd, void *opts );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue