Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to save the input key as a variable #40

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
66 changes: 33 additions & 33 deletions src/image/script.c
Expand Up @@ -366,8 +366,8 @@ struct prompt_options {
unsigned int key;
/** Timeout */
unsigned long timeout;
/** Set */
struct named_setting set;
/** Set */
struct named_setting set;
};

/** "prompt" option list */
Expand All @@ -376,9 +376,9 @@ static struct option_descriptor prompt_opts[] = {
struct prompt_options, key, parse_key ),
OPTION_DESC ( "timeout", 't', required_argument,
struct prompt_options, timeout, parse_timeout ),
OPTION_DESC ( "set", 's', required_argument,
struct prompt_options, set,
parse_autovivified_setting ),
OPTION_DESC ( "set", 's', required_argument,
struct prompt_options, set,
parse_autovivified_setting ),
};

/** "prompt" command descriptor */
Expand All @@ -396,7 +396,7 @@ static struct command_descriptor prompt_cmd =
static int prompt_exec ( int argc, char **argv ) {
struct prompt_options opts;
char *text;
int key;
int key;
int rc;

/* Parse options */
Expand All @@ -411,34 +411,34 @@ static int prompt_exec ( int argc, char **argv ) {
}

/* Display prompt and wait for key */
key = prompt ( text, opts.timeout );
if ( key < 0 ) {
rc = key;
key = prompt ( text, opts.timeout );
if ( key < 0 ) {
rc = key;
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;
}
}
}

/* 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 ( text );
Expand Down
18 changes: 9 additions & 9 deletions src/usr/autoboot.c
Expand Up @@ -545,7 +545,7 @@ static int autoboot ( void ) {
* @ret enter_shell User wants to enter shell
*/
static int shell_banner ( void ) {
int key;
int key;

/* Skip prompt if timeout is zero */
if ( BANNER_TIMEOUT <= 0 )
Expand All @@ -554,16 +554,16 @@ static int shell_banner ( void ) {
/* Prompt user */
printf ( "\n" );
key = prompt ( "Press Ctrl-B for the " PRODUCT_SHORT_NAME
" command line...",
( ( BANNER_TIMEOUT * TICKS_PER_SEC ) / 10 ) );
if ( key < 0 )
return key;
" command line...",
( ( BANNER_TIMEOUT * TICKS_PER_SEC ) / 10 ) );
if ( key < 0 )
return key;

/* Check for correct keypress */
if ( key != CTRL_B )
return -ECANCELED;
/* Check for correct keypress */
if ( key != CTRL_B )
return -ECANCELED;

return 0;
return 0;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/usr/prompt.c
Expand Up @@ -44,7 +44,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
*
* Returns success if the specified key was pressed within the
* specified timeout period.
* @ret key Key pressed, or negative error
* @ret key Key pressed, or negative error
*/
int prompt ( const char *text, unsigned long timeout ) {
int key;
Expand All @@ -53,7 +53,7 @@ int prompt ( const char *text, unsigned long timeout ) {
printf ( "%s", text );

/* Wait for key */
key = getkey ( timeout );
key = getkey ( timeout );

/* Clear the prompt line */
while ( *(text++) )
Expand Down