mirror of
https://github.com/ipxe/ipxe
synced 2025-12-19 02:50:25 +03:00
[parseopt] Add parse_timeout()
Parsing a timeout value (specified in milliseconds) into an internal timeout value measured in timer ticks is a common operation. Provide a parse_timeout() value to carry out this conversion automatically. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -28,28 +28,27 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <ipxe/console.h>
|
||||
#include <ipxe/timer.h>
|
||||
#include <usr/prompt.h>
|
||||
|
||||
/**
|
||||
* Prompt for keypress
|
||||
*
|
||||
* @v text Prompt string
|
||||
* @v wait_ms Time to wait, in milliseconds (0=indefinite)
|
||||
* @v timeout Timeout period, in ticks (0=indefinite)
|
||||
* @v key Key to wait for (0=any key)
|
||||
* @ret rc Return status code
|
||||
*
|
||||
* Returns success if the specified key was pressed within the
|
||||
* specified timeout period.
|
||||
*/
|
||||
int prompt ( const char *text, unsigned int wait_ms, int key ) {
|
||||
int prompt ( const char *text, unsigned long timeout, int key ) {
|
||||
int key_pressed;
|
||||
|
||||
/* Display prompt */
|
||||
printf ( "%s", text );
|
||||
|
||||
/* Wait for key */
|
||||
key_pressed = getkey ( ( wait_ms * TICKS_PER_SEC ) / 1000 );
|
||||
key_pressed = getkey ( timeout );
|
||||
|
||||
/* Clear the prompt line */
|
||||
while ( *(text++) )
|
||||
|
||||
Reference in New Issue
Block a user