if (*buf != '#')
{
int err;
- char* rxstart = strchr (buf, ':') + 1;
+ char* rxstart = strchr (buf, ':');
- err = regcomp (&self->rx, rxstart, REG_EXTENDED|REG_ICASE|REG_NOSUB);
-
- if (!err)
- {
- self->string = strdup (buf);
- if (!self->string) abort();
- }
+ if (!rxstart)
+ self->string = strdup ("#ERROR: Syntax error, line was neither a comment nor a rule");
else
{
- regfree (&self->rx);
- char ebuf[256];
- size_t len = regerror (err, NULL, ebuf, 256);
- self->string = malloc(len + strlen(buf) + 14);
- if (!self->string) abort();
- strcpy (self->string, "#ERROR: ");
- strcat (self->string, ebuf);
- strcat (self->string, " in '");
- strcat (self->string, buf);
- strcat (self->string, "'");
+ err = regcomp (&self->rx, rxstart+1, REG_EXTENDED|REG_ICASE|REG_NOSUB);
+
+ if (!err)
+ {
+ self->string = strdup (buf);
+ if (!self->string) abort();
+ }
+ else
+ {
+ regfree (&self->rx);
+ char ebuf[256];
+ size_t len = regerror (err, NULL, ebuf, 256);
+ self->string = malloc(len + strlen(buf) + 14);
+ if (!self->string) abort();
+ strcpy (self->string, "#ERROR: ");
+ strcat (self->string, ebuf);
+ strcat (self->string, " in '");
+ strcat (self->string, buf);
+ strcat (self->string, "'");
+ }
}
}
else