mirror of https://github.com/ipxe/ipxe.git
Merge 3a5cd3640d
into 02ecb23d10
commit
9de65ac5a1
|
@ -357,6 +357,8 @@ struct prompt_options {
|
||||||
unsigned int key;
|
unsigned int key;
|
||||||
/** Timeout */
|
/** Timeout */
|
||||||
unsigned long timeout;
|
unsigned long timeout;
|
||||||
|
/** Set */
|
||||||
|
struct named_setting set;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** "prompt" option list */
|
/** "prompt" option list */
|
||||||
|
@ -365,6 +367,9 @@ static struct option_descriptor prompt_opts[] = {
|
||||||
struct prompt_options, key, parse_key ),
|
struct prompt_options, key, parse_key ),
|
||||||
OPTION_DESC ( "timeout", 't', required_argument,
|
OPTION_DESC ( "timeout", 't', required_argument,
|
||||||
struct prompt_options, timeout, parse_timeout ),
|
struct prompt_options, timeout, parse_timeout ),
|
||||||
|
OPTION_DESC ( "set", 's', required_argument,
|
||||||
|
struct prompt_options, set,
|
||||||
|
parse_autovivified_setting ),
|
||||||
};
|
};
|
||||||
|
|
||||||
/** "prompt" command descriptor */
|
/** "prompt" command descriptor */
|
||||||
|
@ -382,6 +387,7 @@ static struct command_descriptor prompt_cmd =
|
||||||
static int prompt_exec ( int argc, char **argv ) {
|
static int prompt_exec ( int argc, char **argv ) {
|
||||||
struct prompt_options opts;
|
struct prompt_options opts;
|
||||||
char *text;
|
char *text;
|
||||||
|
int key;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Parse options */
|
/* Parse options */
|
||||||
|
@ -396,14 +402,42 @@ static int prompt_exec ( int argc, char **argv ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Display prompt and wait for key */
|
/* Display prompt and wait for key */
|
||||||
if ( ( rc = prompt ( text, opts.timeout, opts.key ) ) != 0 )
|
key = prompt ( text, opts.timeout );
|
||||||
|
if ( key < 0 ) {
|
||||||
|
rc = key;
|
||||||
goto err_prompt;
|
goto err_prompt;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Check for correct key, if specified */
|
||||||
|
if ( opts.key && ( key != ( ( int ) opts.key ) ) ) {
|
||||||
|
rc = -ECANCELED;
|
||||||
|
goto err_wrong_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Store key, if specified */
|
||||||
|
if ( opts.set.settings ) {
|
||||||
|
|
||||||
|
/* Apply default type if necessary */
|
||||||
|
if ( ! opts.set.setting.type )
|
||||||
|
opts.set.setting.type = &setting_type_uint16;
|
||||||
|
|
||||||
|
/* Store setting */
|
||||||
|
if ( ( rc = storen_setting ( opts.set.settings,
|
||||||
|
&opts.set.setting,
|
||||||
|
key ) ) != 0 ) {
|
||||||
|
printf ( "Could not store \"%s\": %s\n",
|
||||||
|
opts.set.setting.name, strerror ( rc ) );
|
||||||
|
goto err_store;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Free prompt text */
|
/* Free prompt text */
|
||||||
free ( text );
|
free ( text );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err_store:
|
||||||
|
err_wrong_key:
|
||||||
err_prompt:
|
err_prompt:
|
||||||
free ( text );
|
free ( text );
|
||||||
err_concat:
|
err_concat:
|
||||||
|
|
|
@ -9,6 +9,6 @@
|
||||||
|
|
||||||
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||||
|
|
||||||
extern int prompt ( const char *text, unsigned long timeout, int key );
|
extern int prompt ( const char *text, unsigned long timeout );
|
||||||
|
|
||||||
#endif /* _USR_PROMPT_H */
|
#endif /* _USR_PROMPT_H */
|
||||||
|
|
|
@ -563,6 +563,7 @@ static int autoboot ( void ) {
|
||||||
* @ret enter_shell User wants to enter shell
|
* @ret enter_shell User wants to enter shell
|
||||||
*/
|
*/
|
||||||
static int shell_banner ( void ) {
|
static int shell_banner ( void ) {
|
||||||
|
int key;
|
||||||
|
|
||||||
/* Skip prompt if timeout is zero */
|
/* Skip prompt if timeout is zero */
|
||||||
if ( BANNER_TIMEOUT <= 0 )
|
if ( BANNER_TIMEOUT <= 0 )
|
||||||
|
@ -570,10 +571,17 @@ static int shell_banner ( void ) {
|
||||||
|
|
||||||
/* Prompt user */
|
/* Prompt user */
|
||||||
printf ( "\n" );
|
printf ( "\n" );
|
||||||
return ( prompt ( "Press Ctrl-B for the " PRODUCT_SHORT_NAME
|
key = prompt ( "Press Ctrl-B for the " PRODUCT_SHORT_NAME
|
||||||
" command line...",
|
" command line...",
|
||||||
( ( BANNER_TIMEOUT * TICKS_PER_SEC ) / 10 ),
|
( ( BANNER_TIMEOUT * TICKS_PER_SEC ) / 10 ) );
|
||||||
CTRL_B ) == 0 );
|
if ( key < 0 )
|
||||||
|
return key;
|
||||||
|
|
||||||
|
/* Check for correct keypress */
|
||||||
|
if ( key != CTRL_B )
|
||||||
|
return -ECANCELED;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -44,27 +44,24 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||||
*
|
*
|
||||||
* Returns success if the specified key was pressed within the
|
* Returns success if the specified key was pressed within the
|
||||||
* specified timeout period.
|
* specified timeout period.
|
||||||
|
* @ret key Key pressed, or negative error
|
||||||
*/
|
*/
|
||||||
int prompt ( const char *text, unsigned long timeout, int key ) {
|
int prompt ( const char *text, unsigned long timeout ) {
|
||||||
int key_pressed;
|
int key;
|
||||||
|
|
||||||
/* Display prompt */
|
/* Display prompt */
|
||||||
printf ( "%s", text );
|
printf ( "%s", text );
|
||||||
|
|
||||||
/* Wait for key */
|
/* Wait for key */
|
||||||
key_pressed = getkey ( timeout );
|
key = getkey ( timeout );
|
||||||
|
|
||||||
/* Clear the prompt line */
|
/* Clear the prompt line */
|
||||||
while ( *(text++) )
|
while ( *(text++) )
|
||||||
printf ( "\b \b" );
|
printf ( "\b \b" );
|
||||||
|
|
||||||
/* Check for timeout */
|
/* Check for timeout */
|
||||||
if ( key_pressed < 0 )
|
if ( key < 0 )
|
||||||
return -ETIMEDOUT;
|
return -ETIMEDOUT;
|
||||||
|
|
||||||
/* Check for correct key pressed */
|
return key;
|
||||||
if ( key && ( key_pressed != key ) )
|
|
||||||
return -ECANCELED;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue