summaryrefslogtreecommitdiffstats
path: root/src/hci/shell.c
diff options
context:
space:
mode:
authorMichael Brown2010-11-22 21:20:33 +0100
committerMichael Brown2010-11-22 21:29:01 +0100
commit84aa702ff8b66f883e9ac5792b26d4e9d0760573 (patch)
tree5984913a1a1a773775adaf6ead880fefb46f3a72 /src/hci/shell.c
parent[script] Implement "goto" in iPXE scripts (diff)
downloadipxe-84aa702ff8b66f883e9ac5792b26d4e9d0760573.tar.gz
ipxe-84aa702ff8b66f883e9ac5792b26d4e9d0760573.tar.xz
ipxe-84aa702ff8b66f883e9ac5792b26d4e9d0760573.zip
[script] Allow "exit" to exit a script
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/hci/shell.c')
-rw-r--r--src/hci/shell.c39
1 files changed, 12 insertions, 27 deletions
diff --git a/src/hci/shell.c b/src/hci/shell.c
index 3fc25727..f9cd3af2 100644
--- a/src/hci/shell.c
+++ b/src/hci/shell.c
@@ -21,8 +21,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
+#include <getopt.h>
#include <readline/readline.h>
#include <ipxe/command.h>
+#include <ipxe/parseopt.h>
#include <ipxe/shell.h>
/** @file
@@ -34,29 +36,13 @@ FILE_LICENCE ( GPL2_OR_LATER );
/** The shell prompt string */
static const char shell_prompt[] = "iPXE> ";
-/** Flag set in order to exit shell */
-static int exit_flag = 0;
-
-/** "exit" command body */
-static int exit_exec ( int argc, char **argv __unused ) {
-
- if ( argc == 1 ) {
- exit_flag = 1;
- } else {
- printf ( "Usage: exit\n"
- "Exits the command shell\n" );
- }
-
- return 0;
-}
-
-/** "exit" command definition */
-struct command exit_command __command = {
- .name = "exit",
- .exec = exit_exec,
-};
-
-/** "help" command body */
+/**
+ * "help" command
+ *
+ * @v argc Argument count
+ * @v argv Argument list
+ * @ret rc Return status code
+ */
static int help_exec ( int argc __unused, char **argv __unused ) {
struct command *command;
unsigned int hpos = 0;
@@ -78,7 +64,7 @@ static int help_exec ( int argc __unused, char **argv __unused ) {
return 0;
}
-/** "help" command definition */
+/** "help" command */
struct command help_command __command = {
.name = "help",
.exec = help_exec,
@@ -91,12 +77,11 @@ struct command help_command __command = {
void shell ( void ) {
char *line;
- exit_flag = 0;
- while ( ! exit_flag ) {
+ do {
line = readline ( shell_prompt );
if ( line ) {
system ( line );
free ( line );
}
- }
+ } while ( shell_exit == 0 );
}