<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
<tt>Michael Brown wrote:</tt>
<blockquote type="cite" cite="mid:201003051553.49780.mbrown@fensystems.co.uk">
<title>Re: [gPXE-devel] Minor Scripting Improvements</title>
<!-- Converted from text/plain format -->
<p><tt><font size="2">"Exit just the currently executing script"
feels cleanest to me.<br>
<br>
Maybe "loopif" rather than "loop", to make it more intuitively obvious
that<br>
the argument is required?<br>
<br>
In the bazaar spirit, 69 bytes seems worth it to me.</font></tt></p>
</blockquote>
<tt><br>
Thanks for your feedback, Michael. Attached are both features as one
patch. Of course, 'loopif' now brings the cost to 71 bytes, versus the
69 for 'loop'. ;) I agree that 'loopif' makes more sense to the user.<br>
<br>
I'll tear down the 'loop' staging branch shortly and put a 'loopif'
version there, instead.<br>
<br>
</tt><tt>I value further feedback from anyone interested. </tt><br>
<tt><br>
- Shao Miller<br>
-----<br>
<br>
diff --git a/src/hci/shell.c b/src/hci/shell.c<br>
index 5bedbdc..825dac3 100644<br>
--- a/src/hci/shell.c<br>
+++ b/src/hci/shell.c<br>
@@ -35,13 +35,13 @@ FILE_LICENCE ( GPL2_OR_LATER );<br>
static const char shell_prompt[] = "gPXE> ";<br>
<br>
/** Flag set in order to exit shell */<br>
-static int exit_flag = 0;<br>
+int shell_exit_flag = 0;<br>
<br>
/** "exit" command body */<br>
static int exit_exec ( int argc, char **argv __unused ) {<br>
<br>
if ( argc == 1 ) {<br>
- exit_flag = 1;<br>
+ shell_exit_flag = 1;<br>
} else {<br>
printf ( "Usage: exit\n"<br>
"Exits the command shell\n" );<br>
@@ -91,8 +91,8 @@ struct command help_command __command = {<br>
void shell ( void ) {<br>
char *line;<br>
<br>
- exit_flag = 0;<br>
- while ( ! exit_flag ) {<br>
+ shell_exit_flag = 0;<br>
+ while ( ! shell_exit_flag ) {<br>
line = readline ( shell_prompt );<br>
if ( line ) {<br>
system ( line );<br>
diff --git a/src/image/script.c b/src/image/script.c<br>
index 0835ecb..0597228 100644<br>
--- a/src/image/script.c<br>
+++ b/src/image/script.c<br>
@@ -29,7 +29,9 @@ FILE_LICENCE ( GPL2_OR_LATER );<br>
#include <stdlib.h><br>
#include <ctype.h><br>
#include <errno.h><br>
+#include <gpxe/command.h><br>
#include <gpxe/image.h><br>
+#include <gpxe/shell.h><br>
<br>
struct image_type script_image_type __image_type ( PROBE_NORMAL );<br>
<br>
@@ -40,7 +42,7 @@ struct image_type script_image_type __image_type (
PROBE_NORMAL );<br>
* @ret rc Return status code<br>
*/<br>
static int script_exec ( struct image *image ) {<br>
- size_t offset = 0;<br>
+ size_t offset;<br>
off_t eol;<br>
size_t len;<br>
int rc;<br>
@@ -50,6 +52,8 @@ static int script_exec ( struct image *image ) {<br>
*/<br>
unregister_image ( image );<br>
<br>
+ start_script:<br>
+ offset = 0;<br>
while ( offset < image->len ) {<br>
<br>
/* Find length of next line, excluding any terminating '\n' */<br>
@@ -73,12 +77,24 @@ static int script_exec ( struct image *image ) {<br>
}<br>
}<br>
<br>
+ if ( shell_exit_flag )<br>
+ /* "exit" command should exit this script */<br>
+ goto done;<br>
/* Move to next line */<br>
offset += ( len + 1 );<br>
}<br>
<br>
rc = 0;<br>
done:<br>
+ /* Reset exit flag */<br>
+ shell_exit_flag = 0;<br>
+<br>
+ /* Check if we should loop. We might as well use ENOTSUP,<br>
+ * since we don't use it for anything else in this file<br>
+ */<br>
+ if ( rc == -ENOTSUP )<br>
+ goto start_script;<br>
+<br>
/* Re-register image and return */<br>
register_image ( image );<br>
return rc;<br>
@@ -124,3 +140,20 @@ struct image_type script_image_type __image_type (
PROBE_NORMAL ) = {<br>
.load = script_load,<br>
.exec = script_exec,<br>
};<br>
+<br>
+/** "loopif" command body */<br>
+static int loopif_exec ( int argc, char **argv ) {<br>
+ /* We use ENOTSUP, since we don't use it<br>
+ * for anything else in this file<br>
+ */<br>
+ if ( argc > 1 && strtoul ( argv[1], NULL, 0 ) )<br>
+ return -ENOTSUP;<br>
+ return 0;<br>
+}<br>
+<br>
+/** "loopif" command definition */<br>
+struct command loop_command __command = {<br>
+ .name = "loopif",<br>
+ .exec = loopif_exec,<br>
+};<br>
+<br>
diff --git a/src/include/gpxe/shell.h b/src/include/gpxe/shell.h<br>
index a65a344..148ea83 100644<br>
--- a/src/include/gpxe/shell.h<br>
+++ b/src/include/gpxe/shell.h<br>
@@ -9,6 +9,7 @@<br>
<br>
FILE_LICENCE ( GPL2_OR_LATER );<br>
<br>
+extern int shell_exit_flag;<br>
extern void shell ( void );<br>
<br>
#endif /* _GPXE_SHELL_H */<br>
<br>
</tt>
</body>
</html>