diff options
author | Michael Brown | 2011-04-24 16:19:31 +0200 |
---|---|---|
committer | Michael Brown | 2011-04-24 16:32:06 +0200 |
commit | 3ca5656208d532b74d7ceecae1760d118e96a172 (patch) | |
tree | bde80cc37e55b3da14548bf4d66466ace26e6966 /src/core/parseopt.c | |
parent | [undi] Assume that interrupts are not supported if IRQ=0 (diff) | |
download | ipxe-3ca5656208d532b74d7ceecae1760d118e96a172.tar.gz ipxe-3ca5656208d532b74d7ceecae1760d118e96a172.tar.xz ipxe-3ca5656208d532b74d7ceecae1760d118e96a172.zip |
[parseopt] Allow for pre-initialised option sets
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/core/parseopt.c')
-rw-r--r-- | src/core/parseopt.c | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/src/core/parseopt.c b/src/core/parseopt.c index 24a57624..a399d221 100644 --- a/src/core/parseopt.c +++ b/src/core/parseopt.c @@ -152,16 +152,16 @@ void print_usage ( struct command_descriptor *cmd, char **argv ) { } /** - * Parse command-line options + * Reparse command-line options * * @v argc Argument count * @v argv Argument list * @v cmd Command descriptor - * @v opts Options + * @v opts Options (already initialised with default values) * @ret rc Return status code */ -int parse_options ( int argc, char **argv, struct command_descriptor *cmd, - void *opts ) { +int reparse_options ( int argc, char **argv, struct command_descriptor *cmd, + void *opts ) { struct option longopts[ cmd->num_options + 1 /* help */ + 1 /* end */ ]; char shortopts[ cmd->num_options * 3 /* possible "::" */ + 1 /* "h" */ + 1 /* NUL */ ]; @@ -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", argv[0], shortopts, cmd->min_args, cmd->max_args, cmd->len ); - /* Clear options */ - memset ( opts, 0, cmd->len ); - /* Parse options */ while ( ( c = getopt_long ( argc, argv, shortopts, longopts, NULL ) ) >= 0 ) { @@ -233,3 +230,21 @@ int parse_options ( int argc, char **argv, struct command_descriptor *cmd, 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 ); +} |