13.2 Using the Low-level Resource Manager Routines

As you can see, handling program options properly with XGetDefault() is not trivial, even though XGetDefault() is supposed to be the simple interface to the resource manager. Also, XGetDefault() does not read all the resource files and properties that an application should use. It is not any easier to use the low-level resource manager calls, but they do a more thorough job.

For one, there is a single routine that takes care of parsing the command line and loading the values found there into the resource database. Secondly, there are several more resource files that XGetDefault() does not read but that an application really should. You can mechanize the whole process of handling program options by turning every set of options into a database, merging them into a single database, and then extracting the correct values. The resulting code is easier to expand or modify than code that uses XGetDefault().

First, let’s describe the additional resource files that we will handle with the low-level resource manager routines.

13.2.1 Resource Files and Merging

All applications need fallback settings for all configurable options in case the user does not set these options. Instead of hardcoding these as defined constants, they can be placed in another resource file. Then if they need to be changed by the application writer, only the resource file needs editing, and the application does not need to be recompiled. Another advantage of this approach ...

Get XLIB Programming Manual, Rel. 5, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.