( rc != 0 ) );
}
+/**
+ * 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
*
int rc;
/* Skip label lines */
- if ( line[0] == ':' )
+ if ( find_label ( line ) != NULL )
return 0;
/* Execute command */
*/
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;