diff options
-rw-r--r-- | includes.c | 17 |
1 files changed, 8 insertions, 9 deletions
@@ -51,19 +51,18 @@ static struct majefile * find_inc(const struct majefile *file, const regex_t * r struct majefile *find_includes(const struct majefile *source) { - regex_t re; - int rc = regcomp(&re, - "#[[:space:]]*include[[:space:]]+.*\"(.*)\"", - REG_EXTENDED | REG_NEWLINE); - if (rc != 0) { - fprintf(stderr, "maje: regcomp() failed\n"); - abort(); + static regex_t re = { .re_nsub = (size_t)-1 }; + if (re.re_nsub == (size_t)-1) { + if (regcomp(&re, + "#[[:space:]]*include[[:space:]]+.*\"(.*)\"", + REG_EXTENDED | REG_NEWLINE) != 0) { + fprintf(stderr, "maje: regcomp(#include) failed\n"); + abort(); + } } struct majefile *ret = find_inc(source, &re); - regfree(&re); - if (ret != NULL) { while (ret->prev != NULL) { ret = ret->prev; |