summaryrefslogtreecommitdiffstats
path: root/src/image
diff options
context:
space:
mode:
authorMichael Brown2013-07-23 15:46:45 +0200
committerMichael Brown2013-07-25 14:03:42 +0200
commit7fc18ea8ab845da3e252abb7d78060182b0342a3 (patch)
treeba3f122164d5b523dca0622aefed3f485582b1c5 /src/image
parent[settings] Remove now-unused fetchf_named_setting() and storef_named_setting() (diff)
downloadipxe-7fc18ea8ab845da3e252abb7d78060182b0342a3.tar.gz
ipxe-7fc18ea8ab845da3e252abb7d78060182b0342a3.tar.xz
ipxe-7fc18ea8ab845da3e252abb7d78060182b0342a3.zip
[script] Allow initial whitespace on lines containing labels
Initial whitespace is already accepted on lines containing commands, since it gets ignored by the system() call. Minimise surprise and allow for neater indentation of scripts by also allowing whitespace on lines containing labels. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/image')
-rw-r--r--src/image/script.c33
1 files changed, 29 insertions, 4 deletions
diff --git a/src/image/script.c b/src/image/script.c
index ceccd901..d30f2613 100644
--- a/src/image/script.c
+++ b/src/image/script.c
@@ -137,6 +137,26 @@ static int terminate_on_exit_or_failure ( int rc ) {
}
/**
+ * Find label within script line
+ *
+ * @v line Line of script
+ * @ret label Start of label name, or NULL if not found
+ */
+static const char * find_label ( const char *line ) {
+
+ /* Skip any leading whitespace */
+ while ( isspace ( *line ) )
+ line++;
+
+ /* If first non-whitespace character is a ':', then we have a label */
+ if ( *line == ':' ) {
+ return ( line + 1 );
+ } else {
+ return NULL;
+ }
+}
+
+/**
* Execute script line
*
* @v line Line of script
@@ -146,7 +166,7 @@ static int script_exec_line ( const char *line ) {
int rc;
/* Skip label lines */
- if ( line[0] == ':' )
+ if ( find_label ( line ) != NULL )
return 0;
/* Execute command */
@@ -252,14 +272,19 @@ static const char *goto_label;
*/
static int goto_find_label ( const char *line ) {
size_t len = strlen ( goto_label );
+ const char *label;
- if ( line[0] != ':' )
+ /* Find label */
+ label = find_label ( line );
+ if ( ! label )
return -ENOENT;
- if ( strncmp ( goto_label, &line[1], len ) != 0 )
+ /* Check if label matches */
+ if ( strncmp ( goto_label, label, len ) != 0 )
return -ENOENT;
- if ( line[ 1 + len ] && ! isspace ( line[ 1 + len ] ) )
+ /* Check label is terminated by a NUL or whitespace */
+ if ( label[len] && ! isspace ( label[len] ) )
return -ENOENT;
return 0;