From 0b1fe005b36ebc3af8de0d736e4a1227ba4580f8 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Tue, 27 Mar 2012 19:49:12 +0100 Subject: [PATCH] [parseopt] Allow "prompt" command to accept character literals for --key Signed-off-by: Michael Brown --- src/core/parseopt.c | 20 +++++++++++++++++++- src/image/script.c | 2 +- src/include/ipxe/parseopt.h | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/core/parseopt.c b/src/core/parseopt.c index 2739bd87..57140690 100644 --- a/src/core/parseopt.c +++ b/src/core/parseopt.c @@ -26,7 +26,6 @@ FILE_LICENCE ( GPL2_OR_LATER ); #include #include #include -#include #include /** @file @@ -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 * diff --git a/src/image/script.c b/src/image/script.c index fb89e422..460fbf03 100644 --- a/src/image/script.c +++ b/src/image/script.c @@ -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 ), }; diff --git a/src/include/ipxe/parseopt.h b/src/include/ipxe/parseopt.h index e54dac66..b5fd2203 100644 --- a/src/include/ipxe/parseopt.h +++ b/src/include/ipxe/parseopt.h @@ -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 );