X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=config.c;fp=config.c;h=aefd80b12a079d4a3c91d43c8a2c33ed6fbd0a38;hb=099ba556d05571001293c8eda10a4fc659f83f48;hp=5a20de3fa62b46d73cc0b13bf5d50aefac78fac6;hpb=149a4211a4b8d8bbcdd72685d538d6ac7365e29e;p=git.git diff --git a/config.c b/config.c index 5a20de3fa..aefd80b12 100644 --- a/config.c +++ b/config.c @@ -1681,3 +1681,36 @@ int config_error_nonbool(const char *var) { return error("Missing value for '%s'", var); } + +int parse_config_key(const char *var, + const char *section, + const char **subsection, int *subsection_len, + const char **key) +{ + int section_len = strlen(section); + const char *dot; + + /* Does it start with "section." ? */ + if (prefixcmp(var, section) || var[section_len] != '.') + return -1; + + /* + * Find the key; we don't know yet if we have a subsection, but we must + * parse backwards from the end, since the subsection may have dots in + * it, too. + */ + dot = strrchr(var, '.'); + *key = dot + 1; + + /* Did we have a subsection at all? */ + if (dot == var + section_len) { + *subsection = NULL; + *subsection_len = 0; + } + else { + *subsection = var + section_len + 1; + *subsection_len = dot - *subsection; + } + + return 0; +}