move build_varname above parse_section

This commit is contained in:
Carlos Martín Nieto 2011-03-30 18:51:02 +02:00
parent d7354d70b0
commit 6482929b5f

View File

@ -497,6 +497,34 @@ static inline int config_keychar(int c)
return isalnum(c) || c == '-';
}
/*
* Returns $section.$name, using only name_len chars from the name,
* which is useful so we don't have to copy the variable name
* twice. The name of the variable is set to lowercase.
* Don't forget to free the buffer.
*/
static char *build_varname(const char *section, const char *name)
{
char *varname;
int section_len, ret;
int name_len;
size_t total_len;
name_len = strlen(name);
section_len = strlen(section);
total_len = section_len + name_len + 2;
varname = malloc(total_len);
if(varname == NULL)
return NULL;
ret = snprintf(varname, total_len, "%s.%s", section, name);
if(ret >= 0){
strtolower(varname + section_len + 1);
}
return varname;
}
static char *parse_section_header_ext(char *base_name, git_config *cfg)
{
return base_name;
@ -685,32 +713,6 @@ static int config_parse(git_config *cfg_file)
return error;
}
/*
* Returns $section.$name, using only name_len chars from the name,
* which is useful so we don't have to copy the variable name
* twice. The name of the variable is set to lowercase.
*Don't forget to free the buffer.
*/
static char *build_varname(const char *section, const char *name, int name_len)
{
char *varname;
int section_len, ret;
size_t total_len;
section_len = strlen(section);
total_len = section_len + name_len + 2;
varname = malloc(total_len);
if(varname == NULL)
return NULL;
ret = snprintf(varname, total_len, "%s.%s", section, name);
if(ret >= 0){
strtolower(varname + section_len + 1);
}
return varname;
}
static int parse_variable(git_config *cfg, const char *section_name, const char *line)
{
int error = GIT_SUCCESS;