diff options
Diffstat (limited to 'src/util/profile/prof_parse.c')
| -rw-r--r-- | src/util/profile/prof_parse.c | 37 |
1 files changed, 29 insertions, 8 deletions
diff --git a/src/util/profile/prof_parse.c b/src/util/profile/prof_parse.c index 8fab90b29..77c0adbd6 100644 --- a/src/util/profile/prof_parse.c +++ b/src/util/profile/prof_parse.c @@ -26,7 +26,8 @@ struct parse_state { struct profile_node *current_section; }; -static errcode_t parse_file(FILE *f, struct parse_state *state); +static errcode_t parse_file(FILE *f, struct parse_state *state, + char **ret_modspec); static char *skip_over_blanks(char *cp) { @@ -216,7 +217,7 @@ static errcode_t parse_include_file(char *filename, struct parse_state *state) fp = fopen(filename, "r"); if (fp == NULL) return PROF_FAIL_INCLUDE_FILE; - retval = parse_file(fp, &incstate); + retval = parse_file(fp, &incstate, NULL); fclose(fp); return retval; } @@ -302,7 +303,8 @@ cleanup: #endif /* not _WIN32 */ } -static errcode_t parse_line(char *line, struct parse_state *state) +static errcode_t parse_line(char *line, struct parse_state *state, + char **ret_modspec) { char *cp; @@ -318,6 +320,23 @@ static errcode_t parse_line(char *line, struct parse_state *state) } switch (state->state) { case STATE_INIT_COMMENT: + if (strncmp(line, "module", 6) == 0 && isspace(line[6])) { + /* + * If we are expecting a module declaration, fill in *ret_modspec + * and return PROF_MODULE, which will cause parsing to abort and + * the module to be loaded instead. If we aren't expecting a + * module declaration, return PROF_MODULE without filling in + * *ret_modspec, which will be treated as an ordinary error. + */ + if (ret_modspec) { + cp = skip_over_blanks(line + 6); + strip_line(cp); + *ret_modspec = strdup(cp); + if (!*ret_modspec) + return ENOMEM; + } + return PROF_MODULE; + } if (line[0] != '[') return 0; state->state = STATE_STD_LINE; @@ -332,7 +351,8 @@ static errcode_t parse_line(char *line, struct parse_state *state) return 0; } -static errcode_t parse_file(FILE *f, struct parse_state *state) +static errcode_t parse_file(FILE *f, struct parse_state *state, + char **ret_modspec) { #define BUF_SIZE 2048 char *bptr; @@ -346,7 +366,7 @@ static errcode_t parse_file(FILE *f, struct parse_state *state) if (fgets(bptr, BUF_SIZE, f) == NULL) break; #ifndef PROFILE_SUPPORTS_FOREIGN_NEWLINES - retval = parse_line(bptr, state); + retval = parse_line(bptr, state, ret_modspec); if (retval) { free (bptr); return retval; @@ -390,7 +410,7 @@ static errcode_t parse_file(FILE *f, struct parse_state *state) /* parse_line modifies contents of p */ newp = p + strlen (p) + 1; - retval = parse_line (p, state); + retval = parse_line (p, state, ret_modspec); if (retval) { free (bptr); return retval; @@ -406,7 +426,8 @@ static errcode_t parse_file(FILE *f, struct parse_state *state) return 0; } -errcode_t profile_parse_file(FILE *f, struct profile_node **root) +errcode_t profile_parse_file(FILE *f, struct profile_node **root, + char **ret_modspec) { struct parse_state state; errcode_t retval; @@ -421,7 +442,7 @@ errcode_t profile_parse_file(FILE *f, struct profile_node **root) if (retval) return retval; - retval = parse_file(f, &state); + retval = parse_file(f, &state, ret_modspec); if (retval) { profile_free_node(state.root_section); return retval; |
