Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[parseopt] Allow "prompt" command to accept character literals for --key
Signed-off-by: Michael Brown <mcb30@ipxe.org>
  • Loading branch information
mcb30 committed Mar 28, 2012
1 parent aac9718 commit 0b1fe00
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
20 changes: 19 additions & 1 deletion src/core/parseopt.c
Expand Up @@ -26,7 +26,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <errno.h>
#include <getopt.h>
#include <ipxe/netdevice.h>
#include <ipxe/image.h>
#include <ipxe/parseopt.h>

/** @file
Expand Down Expand Up @@ -129,6 +128,25 @@ int parse_flag ( const char *text __unused, int *flag ) {
return 0;
}

/**
* Parse key
*
* @v text Text
* @ret key Key
* @ret rc Return status code
*/
int parse_key ( const char *text, unsigned int *key ) {

/* Interpret single characters as being a literal key character */
if ( text[0] && ! text[1] ) {
*key = text[0];
return 0;
}

/* Otherwise, interpret as an integer */
return parse_integer ( text, key );
}

/**
* Print command usage message
*
Expand Down
2 changes: 1 addition & 1 deletion src/image/script.c
Expand Up @@ -302,7 +302,7 @@ struct prompt_options {
/** "prompt" option list */
static struct option_descriptor prompt_opts[] = {
OPTION_DESC ( "key", 'k', required_argument,
struct prompt_options, key, parse_integer ),
struct prompt_options, key, parse_key ),
OPTION_DESC ( "timeout", 't', required_argument,
struct prompt_options, timeout, parse_integer ),
};
Expand Down
1 change: 1 addition & 0 deletions src/include/ipxe/parseopt.h
Expand Up @@ -117,6 +117,7 @@ extern int parse_string ( const char *text, const char **value );
extern int parse_integer ( const char *text, unsigned int *value );
extern int parse_netdev ( const char *text, struct net_device **netdev );
extern int parse_flag ( const char *text __unused, int *flag );
extern int parse_key ( const char *text, unsigned int *key );
extern void print_usage ( struct command_descriptor *cmd, char **argv );
extern int reparse_options ( int argc, char **argv,
struct command_descriptor *cmd, void *opts );
Expand Down

0 comments on commit 0b1fe00

Please sign in to comment.