... | ... |
@@ -285,3 +285,39 @@ void **cfg_get_handle(char *gname) |
285 | 285 |
|
286 | 286 |
return group->handle; |
287 | 287 |
} |
288 |
+ |
|
289 |
+ |
|
290 |
+/* Set the group_id pointer based on the group string. |
|
291 |
+ * The string is either "group_name", or "group_name[group_id]" |
|
292 |
+ * *group_id is set to null in the former case. |
|
293 |
+ * Warning: changes the group string |
|
294 |
+ */ |
|
295 |
+int cfg_get_group_id(str *group, unsigned int **group_id) |
|
296 |
+{ |
|
297 |
+ static unsigned int id; |
|
298 |
+ str s; |
|
299 |
+ |
|
300 |
+ if (!group->s || (group->s[group->len-1] != ']')) { |
|
301 |
+ *group_id = NULL; |
|
302 |
+ return 0; |
|
303 |
+ } |
|
304 |
+ |
|
305 |
+ s.s = group->s + group->len - 2; |
|
306 |
+ s.len = 0; |
|
307 |
+ while ((s.s > group->s) && (*s.s != '[')) { |
|
308 |
+ s.s--; |
|
309 |
+ s.len++; |
|
310 |
+ } |
|
311 |
+ if (s.s == group->s) /* '[' not found */ |
|
312 |
+ return -1; |
|
313 |
+ group->len = s.s - group->s; |
|
314 |
+ s.s++; |
|
315 |
+ if (!group->len || !s.len) |
|
316 |
+ return -1; |
|
317 |
+ if (str2int(&s, &id)) |
|
318 |
+ return -1; |
|
319 |
+ |
|
320 |
+ *group_id = &id; |
|
321 |
+ return 0; |
|
322 |
+} |
|
323 |
+ |
... | ... |
@@ -102,4 +102,7 @@ int cfg_new_ginst(char *group_name, unsigned int group_id); |
102 | 102 |
/*! \brief returns the handle of a cfg group */ |
103 | 103 |
void **cfg_get_handle(char *gname); |
104 | 104 |
|
105 |
+/*! \brief get the id of a cfg group */ |
|
106 |
+int cfg_get_group_id(str *group, unsigned int **group_id); |
|
107 |
+ |
|
105 | 108 |
#endif /* _CFG_H */ |