Beispiel #1
0
static errcode_t parse_line(char *line, struct parse_state *state,
                            char **ret_modspec)
{
    char    *cp;

    if (strncmp(line, "include", 7) == 0 && isspace(line[7])) {
        cp = skip_over_blanks(line + 7);
        strip_line(cp);
        return parse_include_file(cp, state->root_section);
    }
    if (strncmp(line, "includedir", 10) == 0 && isspace(line[10])) {
        cp = skip_over_blanks(line + 10);
        strip_line(cp);
        return parse_include_dir(cp, state->root_section);
    }
    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;
    case STATE_STD_LINE:
        return parse_std_line(line, state);
    case STATE_GET_OBRACE:
        cp = skip_over_blanks(line);
        if (*cp != '{')
            return PROF_MISSING_OBRACE;
        state->state = STATE_STD_LINE;
    }
    return 0;
}
static errcode_t parse_line(char *line, struct parse_state *state)
{
    char    *cp;

    switch (state->state) {
    case STATE_INIT_COMMENT:
        if (line[0] != '[')
            return 0;
        state->state = STATE_STD_LINE;
    case STATE_STD_LINE:
        return parse_std_line(line, state);
    case STATE_GET_OBRACE:
        cp = skip_over_blanks(line);
        if (*cp != '{')
            return PROF_MISSING_OBRACE;
        state->state = STATE_STD_LINE;
    }
    return 0;
}