[AD] al_list_config_entries |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Just a small patch I needed while abusing Allegro's config functions for
something.. currently there is no other way to get the list of keys in a
section than trying all possible string combinations :P
--
Elias Pschernig
Index: src/config.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/config.c,v
retrieving revision 1.30
diff -u -p -r1.30 config.c
--- src/config.c 25 May 2005 21:04:26 -0000 1.30
+++ src/config.c 21 Jun 2005 15:13:01 -0000
@@ -1401,3 +1401,48 @@ AL_CONST char *get_config_text(AL_CONST
return ret;
}
+
+
+/* list_config_entires:
+ * Returns all config entries in a section. The names parameter should either be a
+ * NULL pointer, or a pointer to memory allocated with malloc. It will then be
+ * allocated or re-allocated accordingly. The return value tells how many valid
+ * string pointers it contains after the function returns.
+ *
+ */
+int list_config_entries(AL_CONST char *section, AL_CONST char ***names)
+{
+ int n = 0;
+ CONFIG *conf = config[0];
+ CONFIG_ENTRY *p;
+ int in_section;
+
+ char section_name[256];
+ prettify_section_name(section, section_name, sizeof(section_name));
+
+ if (conf) {
+ p = conf->head;
+
+ /* If section is NULL, only initial, section-less entries are used. */
+ if (ugetc(section_name))
+ in_section = FALSE;
+ else
+ in_section = TRUE;
+
+ while (p) {
+ if (p->name) {
+ /* a section start is just a list entry enclosed in [] */
+ if (ugetc(p->name) == '[' && ugetat(p->name, -1) == ']') {
+ in_section = (ustricmp(section_name, p->name) == 0);
+ }
+ else if (in_section) {
+ *names = _al_sane_realloc((void *)*names, (n + 1) * sizeof **names);
+ (*names)[n] = p->name;
+ n++;
+ }
+ }
+ p = p->next;
+ }
+ }
+ return n;
+}