Skip to content

Commit

Permalink
core: cfg - added cfg_get_group_id to the config var framework api
Browse files Browse the repository at this point in the history
  • Loading branch information
miconda committed May 14, 2021
1 parent 5e3f7e1 commit 899a104
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/core/cfg/cfg.c
Expand Up @@ -285,3 +285,39 @@ void **cfg_get_handle(char *gname)

return group->handle;
}


/* Set the group_id pointer based on the group string.
* The string is either "group_name", or "group_name[group_id]"
* *group_id is set to null in the former case.
* Warning: changes the group string
*/
int cfg_get_group_id(str *group, unsigned int **group_id)
{
static unsigned int id;
str s;

if (!group->s || (group->s[group->len-1] != ']')) {
*group_id = NULL;
return 0;
}

s.s = group->s + group->len - 2;
s.len = 0;
while ((s.s > group->s) && (*s.s != '[')) {
s.s--;
s.len++;
}
if (s.s == group->s) /* '[' not found */
return -1;
group->len = s.s - group->s;
s.s++;
if (!group->len || !s.len)
return -1;
if (str2int(&s, &id))
return -1;

*group_id = &id;
return 0;
}

3 changes: 3 additions & 0 deletions src/core/cfg/cfg.h
Expand Up @@ -102,4 +102,7 @@ int cfg_new_ginst(char *group_name, unsigned int group_id);
/*! \brief returns the handle of a cfg group */
void **cfg_get_handle(char *gname);

/*! \brief get the id of a cfg group */
int cfg_get_group_id(str *group, unsigned int **group_id);

#endif /* _CFG_H */

0 comments on commit 899a104

Please sign in to comment.