list_config_entries(3)

πŸ“¦ version 4.4.3.1, in fedora 43, fedora 44

πŸŽ€ hey bestie, welcome to the list_config_entries(3) page πŸŽ€

okay so real talk: this is from the Allegro manual, aka the Allegro game programming library, and today we're learning how to snoop on every single entry in a config section. it's giving detective energy, and honestly? slay. πŸ’…


🌸 NAME 🌸

list_config_entries β€” lists the names of all entries in a config section, courtesy of the Allegro game programming library. periodt. πŸ‘‘


✨ SYNOPSIS ✨

#include <allegro.h>

int list_config_entries(const char *section, const char ***names);

πŸ’– DESCRIPTION πŸ’–

so the way this works is, bestie, this function gets you a list of literally every entry chillin' in the config section you name. 🫢

the names parameter is a pointer to an array of strings. and here's the lil plot twist: if it points to a NULL pointer, the list gets allocated; otherwise it gets re-allocated. no cap.

when you're done with the list, you should free it again with free_config_entries β€” OR, iconic alternative, you can just pass it right back into list_config_entries and the memory will be re-used. recycling queen behavior. ♻️

wanna see it in action? here's an example that prints out the complete contents of the current configuration. it's lowkey beautiful:

int i, n;
char const **sections = NULL;
char const **entries = NULL;

/* List all entries not in any section. */
n = list_config_entries(NULL, &entries);
for (i = 0; i
   printf(" %s=\"%s\"\n", entries[i], get_config_string(
          NULL, entries[i], "-"));

/* List all sections (and entries in them). */
n = list_config_sections(&sections);
/* loop through all section names */
for (i = 0; i
{
   int j, m;
   printf("%s\n", sections[i]);
   m = list_config_entries(sections[i], &entries);
   /* loop through all entries in the section */
   for (j = 0; j
   {
       printf(" %s=\"%s\"\n", entries[j], get_config_string(
          sections[i], entries[j], "-"));
   }
}
/* It is enough to free the arrays once at the end. */
free_config_entries(&sections);
free_config_entries(&entries);

and yes, the comment is right there in the original β€” it is enough to free the arrays once at the end. so don't be out here freeing things twice, that's not the vibe. 😭


πŸ”₯ RETURN VALUE πŸ”₯

returns the number of valid strings in the names array. that's it, that's the number, fr fr. ⭐


🌈 SEE ALSO 🌈

go be nosy elsewhere too, bestie:


🧚 remember: if you allocated it (or re-allocated it), you free it β€” or hand it back to list_config_entries so the memory gets re-used. that's the whole cycle, and it's iconic. πŸ’œ

and that's the whole page, bestie!! πŸ¦‹ courtesy of Allegro, version 4.4.3 β€” mwah, go forth and list those entries, you absolute main character. πŸ’–βœ¨πŸŒΈ

πŸ“¦ where this page comes from