XrmEnumerateDatabase(3)

✨ XrmEnumerateDatabase β€” the one where we go shopping for resources πŸ’…

okay so bestie, this is a page from XLIB FUNCTIONS and it's literally called XrmEnumerateDatabase πŸ’–


🌸 NAME 🌸

XrmEnumerateDatabase β€” enumerate resource database entries. yes girl, it's the "walk through the whole database and show me what matches" function, no cap πŸ”₯


πŸŽ€ SYNTAX πŸŽ€

#include <X11/Xresource.h>
       #define   XrmEnumAllLevels       0
       #define   XrmEnumOneLevel        1

Bool XrmEnumerateDatabase(XrmDatabase database, XrmNameList name_prefix,
       XrmClassList class_prefix, int mode, Bool (*proc)(), XPointer
       arg);

those two #defines are the whole personality of the mode argument, iykyk πŸ¦‹ β€” XrmEnumAllLevels is 0 and XrmEnumOneLevel is 1, and like, remember them because you're gonna need them.


πŸ¦‹ ARGUMENTS πŸ¦‹

  • database β€” the resource database. like, the actual thing you're digging through πŸ—‚οΈ
  • name_prefix β€” the resource name prefix. your starting point, bestie ✨
  • class_prefix β€” the resource class prefix. the classy counterpart to the name prefix πŸ‘‘
  • mode β€” how many levels deep you wanna enumerate, aka your XrmEnumOneLevel vs XrmEnumAllLevels moment πŸ’…
  • proc β€” the procedure that gets called for each matching entry. your little callback bestie that does the actual work 🫢
  • arg β€” the user-supplied argument that gets passed straight through to the procedure. a little gift for your callback 🎁

πŸ’– DESCRIPTION πŸ’–

so here's the tea β˜• β€” XrmEnumerateDatabase calls the specified procedure for each resource in the database that would match some completion of the given name/class resource prefix. it's giving "scavenger hunt but the prizes are resource entries" πŸ”βœ¨

the order in which resources are found is implementation-dependent, so like... don't come for me about the order, okay? it's not defined and that's just how it is πŸ™ˆ

mode check, bestie:

  • if mode is XrmEnumOneLevel, a resource must match the given name/class prefix with just a single name and class appended. one and done, no extra layers πŸ’…
  • if mode is XrmEnumAllLevels, the resource must match the given name/class prefix with one or more names and classes appended. go as deep as you want, we love a deep dive 🌊

and the stopping condition? flawless logic honestly:

  • if the procedure returns True, the enumeration terminates and the function returns True πŸ›‘βœ…
  • if the procedure always returns False, all matching resources get enumerated and the function returns False 🏁❌

🧚 how the procedure gets called

the procedure is called with these exact arguments, and yes I'm putting the whole signature because it's important:

(*proc)(database, bindings, quarks, type, value, arg)
        XrmDatabase *database;
        XrmBindingList bindings;
        XrmQuarkList quarks;
        XrmRepresentation *type;
        XrmValue *value;
        XPointer arg;

the bindings and quarks lists are terminated by NULLQUARK β€” that's your sentinel, that's your "we're done here" marker πŸŽ€

not me reminding you that pointers to the database and type are passed, but these values should not be modified 😭 like please do not touch, look respectfully only. πŸ™


⚠️ RULES, bestie, listen up: the procedure must not modify the database. that's a hard no 🚫

and here's the spicy caveat 🌢️ β€” if Xlib has been initialized for threads, the procedure is called with the database locked, and the result of a call by the procedure to any Xlib function using the same database is not defined. yes, not defined, like, undefined-behavior kind of not defined πŸ’€ so maybe don't do that!!


🌈 SEE ALSO 🌈


okay that's the whole page, you ate that πŸ’…βœ¨ X Version 11, libX11 1.8.14 β€” go forth and enumerate your resources, queen πŸ‘‘πŸ¦‹πŸ“

πŸ“¦ where this page comes from