|
@@ -136,6 +136,26 @@ static int terminate_on_exit_or_failure ( int rc ) {
|
136
|
136
|
( rc != 0 ) );
|
137
|
137
|
}
|
138
|
138
|
|
|
139
|
+/**
|
|
140
|
+ * Find label within script line
|
|
141
|
+ *
|
|
142
|
+ * @v line Line of script
|
|
143
|
+ * @ret label Start of label name, or NULL if not found
|
|
144
|
+ */
|
|
145
|
+static const char * find_label ( const char *line ) {
|
|
146
|
+
|
|
147
|
+ /* Skip any leading whitespace */
|
|
148
|
+ while ( isspace ( *line ) )
|
|
149
|
+ line++;
|
|
150
|
+
|
|
151
|
+ /* If first non-whitespace character is a ':', then we have a label */
|
|
152
|
+ if ( *line == ':' ) {
|
|
153
|
+ return ( line + 1 );
|
|
154
|
+ } else {
|
|
155
|
+ return NULL;
|
|
156
|
+ }
|
|
157
|
+}
|
|
158
|
+
|
139
|
159
|
/**
|
140
|
160
|
* Execute script line
|
141
|
161
|
*
|
|
@@ -146,7 +166,7 @@ static int script_exec_line ( const char *line ) {
|
146
|
166
|
int rc;
|
147
|
167
|
|
148
|
168
|
/* Skip label lines */
|
149
|
|
- if ( line[0] == ':' )
|
|
169
|
+ if ( find_label ( line ) != NULL )
|
150
|
170
|
return 0;
|
151
|
171
|
|
152
|
172
|
/* Execute command */
|
|
@@ -252,14 +272,19 @@ static const char *goto_label;
|
252
|
272
|
*/
|
253
|
273
|
static int goto_find_label ( const char *line ) {
|
254
|
274
|
size_t len = strlen ( goto_label );
|
|
275
|
+ const char *label;
|
255
|
276
|
|
256
|
|
- if ( line[0] != ':' )
|
|
277
|
+ /* Find label */
|
|
278
|
+ label = find_label ( line );
|
|
279
|
+ if ( ! label )
|
257
|
280
|
return -ENOENT;
|
258
|
281
|
|
259
|
|
- if ( strncmp ( goto_label, &line[1], len ) != 0 )
|
|
282
|
+ /* Check if label matches */
|
|
283
|
+ if ( strncmp ( goto_label, label, len ) != 0 )
|
260
|
284
|
return -ENOENT;
|
261
|
285
|
|
262
|
|
- if ( line[ 1 + len ] && ! isspace ( line[ 1 + len ] ) )
|
|
286
|
+ /* Check label is terminated by a NUL or whitespace */
|
|
287
|
+ if ( label[len] && ! isspace ( label[len] ) )
|
263
|
288
|
return -ENOENT;
|
264
|
289
|
|
265
|
290
|
return 0;
|