# Resource Manager Functions

A program often needs a variety of options in the X environment (for example, fonts, colors, icons, and cursors). Specifying all of these options on the command line is awkward because users may want to customize many aspects of the program and need a convenient way to establish these customizations as the default settings. The resource manager is provided for this purpose. Resource specifications are usually stored in human-readable files and in server properties.

The resource manager is a database manager with a twist. In most database systems, you perform a query using an imprecise specification, and you get back a set of records. The resource manager, however, allows you to specify a large set of values with an imprecise specification, to query the database with a precise specification, and to get back only a single value. This should be used by applications that need to know what the user prefers for colors, fonts, and other resources. It is this use as a database for dealing with X resources that inspired the name "Resource Manager," although the resource manager can be and is used in other ways.

For example, a user of your application may want to specify that all windows should have a blue background but that all mail-reading windows should have a red background. With well-engineered and coordinated applications, a user can define this information using only two lines of specifications.

As an example of how the resource manager works, consider a mail-reading application called xmh. Assume that it is designed so that it uses a complex window hierarchy all the way down to individual command buttons, which may be actual small subwindows in some toolkits. These are often called objects or widgets. In such toolkit systems, each user interface object can be composed of other objects and can be assigned a name and a class. Fully qualified names or classes can have arbitrary numbers of component names, but a fully qualified name always has the same number of component names as a fully qualified class. This generally reflects the structure of the application as composed of these objects, starting with the application itself.

For example, the xmh mail program has a name "xmh" and is one of a class of "Mail" programs. By convention, the first character of class components is capitalized, and the first letter of name components is in lowercase. Each name and class finally has an attribute (for example, "foreground" or "font"). If each window is properly assigned a name and class, it is easy for the user to specify attributes of any portion of the application.

At the top level, the application might consist of a paned window (that is, a window divided into several sections) named "toc". One pane of the paned window is a button box window named "buttons" and is filled with command buttons. One of these command buttons is used to incorporate new mail and has the name "incorporate". This window has a fully qualified name, "xmh.toc.buttons.incorporate", and a fully qualified class, "Xmh.Paned.Box.Command". Its fully qualified name is the name of its parent, "xmh.toc.buttons", followed by its name, "incorporate". Its class is the class of its parent, "Xmh.Paned.Box", followed by its particular class, "Command". The fully qualified name of a resource is the attribute's name appended to the object's fully qualified name, and the fully qualified class is its class appended to the object's class.

The incorporate button might need the following resources: Title string, Font, Foreground color for its inactive state, Background color for its inactive state, Foreground color for its active state, and Background color for its active state. Each resource is considered to be an attribute of the button and, as such, has a name and a class. For example, the foreground color for the button in its active state might be named "activeForeground", and its class might be "Foreground".

When an application looks up a resource (for example, a color), it passes the complete name and complete class of the resource to a look-up routine. The resource manager compares this complete specification against the incomplete specifications of entries in the resource database, finds the best match, and returns the corresponding value for that entry.

The definitions for the resource manager are contained in `<X11/Xresource.h>`.

## Resource File Syntax

The syntax of a resource file is a sequence of resource lines terminated by newline characters or the end of the file. The syntax of an individual resource line is:

    ResourceLine     =     Comment | IncludeFile | ResourceSpec | <empty line>
    Comment     =     "!" {<any character except null or newline>}
    IncludeFile     =     "#" WhiteSpace "include" WhiteSpace FileName WhiteSpace
    FileName     =     <valid filename for operating system>
    ResourceSpec     =     WhiteSpace ResourceName WhiteSpace ":" WhiteSpace Value
    ResourceName     =     [Binding] {Component Binding} ComponentName
    Binding     =     "." | "*"
    WhiteSpace     =     {<space> | <horizontal tab>}
    Component     =     "?" | ComponentName
    ComponentName     =     NameChar {NameChar}
    NameChar     =     "a"-"z" | "A"-"Z" | "0"-"9" | "_" | "-"
    Value     =     {<any character except null or unescaped newline>}

Elements separated by vertical bar (|) are alternatives. Curly braces ({......}) indicate zero or more repetitions of the enclosed elements. Square brackets ([......]) indicate that the enclosed element is optional. Quotes ("......") are used around literal characters.

IncludeFile lines are interpreted by replacing the line with the contents of the specified file. The word "include" must be in lowercase. The file name is interpreted relative to the directory of the file in which the line occurs (for example, if the file name contains no directory or contains a relative directory specification).

If a ResourceName contains a contiguous sequence of two or more Binding characters, the sequence will be replaced with a single ".." character if the sequence contains only ".." characters; otherwise, the sequence will be replaced with a single "*" character.

A resource database never contains more than one entry for a given ResourceName. If a resource file contains multiple lines with the same ResourceName, the last line in the file is used.

Any white space characters before or after the name or colon in a ResourceSpec are ignored. To allow a Value to begin with white space, the two-character sequence "\\space" (backslash followed by space) is recognized and replaced by a space character, and the two-character sequence "\\tab" (backslash followed by horizontal tab) is recognized and replaced by a horizontal tab character. To allow a Value to contain embedded newline characters, the two-character sequence "\\n" is recognized and replaced by a newline character. To allow a Value to be broken across multiple lines in a text file, the two-character sequence "\\newline" (backslash followed by newline) is recognized and removed from the value. To allow a Value to contain arbitrary character codes, the four-character sequence "\\nnn", where each n is a digit character in the range of "0"-"7", is recognized and replaced with a single byte that contains the octal value specified by the sequence. Finally, the two-character sequence "\newline" is recognized and replaced with a single backslash.

As an example of these sequences, the following resource line contains a value consisting of four characters: a backslash, a null, a "z", and a newline:

    magic.values: \\000\
    z\n

## Resource Manager Matching Rules

The algorithm for determining which resource database entry matches a given query is the heart of the resource manager. All queries must fully specify the name and class of the desired resource (use of the characters "*" and "?" is not permitted). The library supports up to 100 components in a full name or class. Resources are stored in the database with only partially specified names and classes, using pattern matching constructs. An asterisk (*) is a loose binding and is used to represent any number of intervening components, including none. A period (.) is a tight binding and is used to separate immediately adjacent components. A question mark (?) is used to match any single component name or class. A database entry cannot end in a loose binding; the final component (which cannot be the character "?") must be specified. The lookup algorithm searches the database for the entry that most closely matches (is most specific for) the full name and class being queried. When more than one database entry matches the full name and class, precedence rules are used to select just one.

The full name and class are scanned from left to right (from highest level in the hierarchy to lowest), one component at a time. At each level, the corresponding component and/or binding of each matching entry is determined, and these matching components and bindings are compared according to precedence rules. Each of the rules is applied at each level before moving to the next level, until a rule selects a single entry over all others. The rules, in order of precedence, are:

- An entry that contains a matching component (whether name, class, or the character "?") takes precedence over entries that elide the level (that is, entries that match the level in a loose binding).

- An entry with a matching name takes precedence over both entries with a matching class and entries that match using the character "?". An entry with a matching class takes precedence over entries that match using the character "?".

- An entry preceded by a tight binding takes precedence over entries preceded by a loose binding.

To illustrate these rules, consider the following resource database entries:

    xmh*Paned*activeForeground:     red     (entry A)
    *incorporate.Foreground:     blue     (entry B)
    xmh.toc*Command*activeForeground:     green     (entry C)
    xmh.toc*?.Foreground:     white     (entry D)
    xmh.toc*Command.activeForeground:     black     (entry E)

Consider a query for the resource:

    xmh.toc.messagefunctions.incorporate.activeForeground     (name)
    Xmh.Paned.Box.Command.Foreground     (class)

At the first level (xmh, Xmh), rule 1 eliminates entry B. At the second level (toc, Paned), rule 2 eliminates entry A. At the third level (messagefunctions, Box), no entries are eliminated. At the fourth level (incorporate, Command), rule 2 eliminates entry D. At the fifth level (activeForeground, Foreground), rule 3 eliminates entry C.

## Quarks

Most uses of the resource manager involve defining names, classes, and representation types as string constants. However, always referring to strings in the resource manager can be slow, because it is so heavily used in some toolkits. To solve this problem, a shorthand for a string is used in place of the string in many of the resource manager functions. Simple comparisons can be performed rather than string comparisons. The shorthand name for a string is called a quark and is the type XrmQuark. On some occasions, you may want to allocate a quark that has no string equivalent.

A quark is to a string what an atom is to a string in the server, but its use is entirely local to your application.

To allocate a new quark, use `XrmUniqueQuark`.

XrmQuark XrmUniqueQuark()

The `XrmUniqueQuark` function allocates a quark that is guaranteed not to represent any string that is known to the resource manager.

Each name, class, and representation type is typedef'd as an XrmQuark.

    typedef int XrmQuark, *XrmQuarkList;
    typedef XrmQuark XrmName;
    typedef XrmQuark XrmClass;
    typedef XrmQuark XrmRepresentation;
    #define NULLQUARK ((XrmQuark) 0)

Lists are represented as null-terminated arrays of quarks. The size of the array must be large enough for the number of components used.

    typedef XrmQuarkList XrmNameList;
    typedef XrmQuarkList XrmClassList;

To convert a string to a quark, use or `XrmPermStringToQuark`.

    #define XrmStringToName(string) XrmStringToQuark(string)
    #define XrmStringToClass(string) XrmStringToQuark(string)
    #define XrmStringToRepresentation(string) XrmStringToQuark(string)

      XrmQuark XrmStringToQuark
      char *string

string

  Specifies the string for which a quark(Ql is to be allocated.

These functions can be used to convert from string to quark representation. If the string is not in the Host Portable Character Encoding, the conversion is implementation-dependent. The string argument to need not be permanently allocated storage. `XrmPermStringToQuark` is just like , except that Xlib is permitted to assume the string argument is permanently allocated, and, hence, that it can be used as the value to be returned by .

For any given quark, if returns a non-NULL value, all future calls will return the same value (identical address).

To convert a quark to a string, use .

    #define XrmNameToString(name)  XrmQuarkToString(name)
    #define XrmClassToString(class)  XrmQuarkToString(name)
    #define XrmRepresentationToString(type)  XrmQuarkToString(type)

      char *XrmQuarkToString
      XrmQuark quark

quark

  Specifies the quark for which the equivalent string is desired.

These functions can be used to convert from quark representation to string. The string pointed to by the return value must not be modified or freed. The returned string is byte-for-byte equal to the original string passed to one of the string-to-quark routines. If no string exists for that quark, returns NULL. For any given quark, if returns a non-NULL value, all future calls will return the same value (identical address).

To convert a string with one or more components to a quark list, use .

    #define XrmStringToNameList(str,name)  XrmStringToQuarkList((str), (name))
    #define XrmStringToClassList(str,class)  XrmStringToQuarkList((str), (class))

      void XrmStringToQuarkList
      char *string
      XrmQuarkList quarks_return

string

  Specifies the string for which a quark(Ql is to be allocated.

quarks_return

  Returns the list of quarks. The caller must allocate sufficient space for the quarks list before calling .

The function converts the null-terminated string (generally a fully qualified name) to a list of quarks. Note that the string must be in the valid ResourceName format (see section 15.1). If the string is not in the Host Portable Character Encoding, the conversion is implementation-dependent.

A binding list is a list of type XrmBindingList and indicates if components of name or class lists are bound tightly or loosely (that is, if wildcarding of intermediate components is specified).

    typedef enum {XrmBindTightly, XrmBindLoosely} XrmBinding, *XrmBindingList;

`XrmBindTightly` indicates that a period separates the components, and `XrmBindLoosely` indicates that an asterisk separates the components.

To convert a string with one or more components to a binding list and a quark list, use .

      XrmStringToBindingQuarkList
      char *string
      XrmBindingList bindings_return
      XrmQuarkList quarks_return

string

  Specifies the string for which a quark(Ql is to be allocated.

bindings_return

  Returns the binding list. The caller must allocate sufficient space for the binding list before calling .

quarks_return

  Returns the list of quarks. The caller must allocate sufficient space for the quarks list before calling .

Component names in the list are separated by a period or an asterisk character. The string must be in the format of a valid ResourceName (see section 15.1). If the string does not start with a period or an asterisk, a tight binding is assumed. For example, the string ``*a.b*c'' becomes:

    quarks:       a         b         c
    bindings:     loose     tight     loose

## Creating and Storing Databases

A resource database is an opaque type, XrmDatabase. Each database value is stored in an XrmValue structure. This structure consists of a size, an address, and a representation type. The size is specified in bytes. The representation type is a way for you to store data tagged by some application-defined type (for example, the strings ``font'' or ``color''). It has nothing to do with the C data type or with its class. The XrmValue structure is defined as:

    typedef struct {
         unsigned int size;
         XPointer addr;
    } XrmValue, *XrmValuePtr;

To initialize the resource manager, use .

      void XrmInitialize
      void XrmInitialize(\|)

To retrieve a database from disk, use .

      XrmDatabase XrmGetFileDatabase
      char *filename

filename

  Specifies the resource database file name.

The function opens the specified file, creates a new resource database, and loads it with the specifications read in from the specified file. The specified file should contain a sequence of entries in valid ResourceLine format (see section 15.1); the database that results from reading a file with incorrect syntax is implementation-dependent. The file is parsed in the current locale, and the database is created in the current locale. If it cannot open the specified file, returns NULL.

To store a copy of a database to disk, use .

      void XrmPutFileDatabase
      XrmDatabase database
      char *stored_db

database

  Specifies the database that is to be used.

stored_db

  Specifies the file name for the stored database.

The function stores a copy of the specified database in the specified file. Text is written to the file as a sequence of entries in valid ResourceLine format (see section 15.1). The file is written in the locale of the database. Entries containing resource names that are not in the Host Portable Character Encoding or containing values that are not in the encoding of the database locale, are written in an implementation-dependent manner. The order in which entries are written is implementation-dependent. Entries with representation types other than ``String'' are ignored.

To obtain a pointer to the screen-independent resources of a display, use .

      char *XResourceManagerString
      Display *display

display

  Specifies the connection to the X server.

The function returns the RESOURCE_MANAGER property from the server's root window of screen zero, which was returned when the connection was opened using . The property is converted from type STRING to the current locale. The conversion is identical to that produced by for a single element STRING property. The returned string is owned by Xlib and should not be freed by the client. The property value must be in a format that is acceptable to . If no property exists, NULL is returned.

To obtain a pointer to the screen-specific resources of a screen, use .

      char *XScreenResourceString
      Screen *screen

screen

  Specifies the screen.

The function returns the SCREEN_RESOURCES property from the root window of the specified screen. The property is converted from type STRING to the current locale. The conversion is identical to that produced by for a single element STRING property. The property value must be in a format that is acceptable to . If no property exists, NULL is returned. The caller is responsible for freeing the returned string by using .

To create a database from a string, use .

      XrmDatabase XrmGetStringDatabase
      char *data

data

  Specifies the database contents using a string.

The function creates a new database and stores the resources specified in the specified null-terminated string. is similar to except that it reads the information out of a string instead of out of a file. The string should contain a sequence of entries in valid ResourceLine format (see section 15.1) terminated by a null character; the database that results from using a string with incorrect syntax is implementation-dependent. The string is parsed in the current locale, and the database is created in the current locale.

To obtain the locale name of a database, use .

      char *XrmLocaleOfDatabase
      XrmDatabase database

database

  Specifies the resource database.

The function returns the name of the locale bound to the specified database, as a null-terminated string. The returned locale name string is owned by Xlib and should not be modified or freed by the client. Xlib is not permitted to free the string until the database is destroyed. Until the string is freed, it will not be modified by Xlib.

To destroy a resource database and free its allocated memory, use .

      void XrmDestroyDatabase
      XrmDatabase database

database

  Specifies the resource database.

If database is NULL, returns immediately.

To associate a resource database with a display, use .

      void XrmSetDatabase
      Display *display
      XrmDatabase database

display

  Specifies the connection to the X server.

database

  Specifies the resource database.

The function associates the specified resource database (or NULL) with the specified display. The database previously associated with the display (if any) is not destroyed. A client or toolkit may find this function convenient for retaining a database once it is constructed.

To get the resource database associated with a display, use .

      XrmDatabase XrmGetDatabase
      Display *display

display

  Specifies the connection to the X server.

The function returns the database associated with the specified display. It returns NULL if a database has not yet been set.

## Merging Resource Databases

To merge the contents of a resource file into a database, use .

      Status XrmCombineFileDatabase
      char *filename
      XrmDatabase *target_db
      Bool override

filename

  Specifies the resource database file name.

target_db

  Specifies the resource database into which the source database is to be merged.

override

  Specifies whether source entries override target ones.

The function merges the contents of a resource file into a database. If the same specifier is used for an entry in both the file and the database, the entry in the file will replace the entry in the database if override is True; otherwise, the entry in the file is discarded. The file is parsed in the current locale. If the file cannot be read, a zero status is returned; otherwise, a nonzero status is returned. If target_db contains NULL, creates and returns a new database to it. Otherwise, the database pointed to by target_db is not destroyed by the merge. The database entries are merged without changing values or types, regardless of the locale of the database. The locale of the target database is not modified.

To merge the contents of one database into another database, use .

      void XrmCombineDatabase
      XrmDatabasesource_db, *target_db
      Bool override

source_db

  Specifies the resource database that is to be merged into the target database.

target_db

  Specifies the resource database into which the source database is to be merged.

override

  Specifies whether source entries override target ones.

The function merges the contents of one database into another. If the same specifier is used for an entry in both databases, the entry in the source_db will replace the entry in the target_db if override is True; otherwise, the entry in source_db is discarded. If target_db contains NULL, simply stores source_db in it. Otherwise, source_db is destroyed by the merge, but the database pointed to by target_db is not destroyed. The database entries are merged without changing values or types, regardless of the locales of the databases. The locale of the target database is not modified.

To merge the contents of one database into another database with override semantics, use .

      void XrmMergeDatabases
      XrmDatabasesource_db, *target_db

source_db

  Specifies the resource database that is to be merged into the target database.

target_db

  Specifies the resource database into which the source database is to be merged.

Calling the function is equivalent to calling the function with an override argument of True.

## Looking Up Resources

To retrieve a resource from a resource database, use , , or .

      Bool XrmGetResource
      XrmDatabase database
      char *str_name
      char *str_class
      char **str_type_return
      XrmValue *value_return

database

  Specifies the database that is to be used.

str_name

  Specifies the fully qualified name of the value being retrieved (as a string).

str_class

  Specifies the fully qualified class of the value being retrieved (as a string).

str_type_return

  Returns the representation type of the destination (as a string).

value_return

  Returns the value in the database.

      Bool XrmQGetResource
      XrmDatabase database
      XrmNameList quark_name
      XrmClassList quark_class
      XrmRepresentation *quark_type_return
      XrmValue *value_return

database

  Specifies the database that is to be used.

quark_name

  Specifies the fully qualified name of the value being retrieved (as a quark).

quark_class

  Specifies the fully qualified class of the value being retrieved (as a quark).

quark_type_return

  Returns the representation type of the destination (as a quark).

value_return

  Returns the value in the database.

The and functions retrieve a resource from the specified database. Both take a fully qualified name/class pair, a destination resource representation, and the address of a value (size/address pair). The value and returned type point into database memory; therefore, you must not modify the data.

The database only frees or overwrites entries on , , or . A client that is not storing new values into the database or is not merging the database should be safe using the address passed back at any time until it exits. If a resource was found, both and return True; otherwise, they return False.

Most applications and toolkits do not make random probes into a resource database to fetch resources. The X toolkit access pattern for a resource database is quite stylized. A series of from 1 to 20 probes is made with only the last name/class differing in each probe. The function is at worst a 2n algorithm, where n is the length of the name/class list. This can be improved upon by the application programmer by prefetching a list of database levels that might match the first part of a name/class list.

To obtain a list of database levels, use `XrmQGetSearchList`.

      Bool XrmQGetSearchResource
      XrmDatabase database
      XrmNameList names
      XrmClassList classes
      XrmSearchList list_return
      int list_length

database

  Specifies the database that is to be used.

names

  Specifies a list of resource names.

classes

  Specifies a list of resource classes.

list_return

  Returns a search list for further use. The caller must allocate sufficient space for the list before calling `XrmQGetSearchList`.

list_length

  Specifies the number of entries (not the byte size) allocated for list_return.

The `XrmQGetSearchList` function takes a list of names and classes and returns a list of database levels where a match might occur. The returned list is in best-to-worst order and uses the same algorithm as for determining precedence. If list_return was large enough for the search list, `XrmQGetSearchList` returns True; otherwise, it returns False.

The size of the search list that the caller must allocate is dependent upon the number of levels and wildcards in the resource specifiers that are stored in the database. The worst case length is 3n, where n is the number of name or class components in names or classes.

When using `XrmQGetSearchList` followed by multiple probes for resources with a common name and class prefix, only the common prefix should be specified in the name and class list to `XrmQGetSearchList`.

To search resource database levels for a given resource, use .

      Bool XrmQGetSearchResource
      XrmSearchList list
      XrmName name
      XrmClass class
      XrmRepresentation *type_return
      XrmValue *value_return

list

  Specifies the search list returned by `XrmQGetSearchList`.

name

  Specifies the resource name.

class

  Specifies the resource class.

type_return

  Returns data representation type.

value_return

  Returns the value in the database.

The function searches the specified database levels for the resource that is fully identified by the specified name and class. The search stops with the first match. returns True if the resource was found; otherwise, it returns False.

A call to `XrmQGetSearchList` with a name and class list containing all but the last component of a resource name followed by a call to with the last component name and class returns the same database entry as and with the fully qualified name and class.

## Storing into a Resource Database

To store resources into the database, use or . Both functions take a partial resource specification, a representation type, and a value. This value is copied into the specified database.

      void XrmPutResource
      XrmDatabase *database
      char *specifier
      char *type
      XrmValue *value

database

  Specifies the resource database.

specifier

  Specifies a complete or partial specification of the resource.

type

  Specifies the type of the resource.

value

  Specifies the value of the resource, which is specified as a string.

If database contains NULL, creates a new database and returns a pointer to it. is a convenience function that calls followed by:

    XrmQPutResource(database, bindings, quarks, XrmStringToQuark(type), value)

If the specifier and type are not in the Host Portable Character Encoding, the result is implementation-dependent. The value is stored in the database without modification.

      void XrmQPutResource
      XrmDatabase *database
      XrmBindingList bindings
      XrmQuarkList quarks
      XrmRepresentation type
      XrmValue *value

database

  Specifies the resource database.

bindings

  Specifies a list of bindings.

quarks

  Specifies the complete or partial name or the class list of the resource.

type

  Specifies the type of the resource.

value

  Specifies the value of the resource, which is specified as a string.

If database contains NULL, creates a new database and returns a pointer to it. If a resource entry with the identical bindings and quarks already exists in the database, the previous type and value are replaced by the new specified type and value. The value is stored in the database without modification.

To add a resource that is specified as a string, use .

      void XrmPutStringResource
      XrmDatabase *database
      char *specifier
      char *value

database

  Specifies the resource database.

specifier

  Specifies a complete or partial specification of the resource.

value

  Specifies the value of the resource, which is specified as a string.

If database contains NULL, creates a new database and returns a pointer to it. adds a resource with the specified value to the specified database. is a convenience function that first calls on the specifier and then calls , using a ``String'' representation type. If the specifier is not in the Host Portable Character Encoding, the result is implementation-dependent. The value is stored in the database without modification.

To add a string resource using quarks as a specification, use .

      void XrmQPutStringResource
      XrmDatabase *database
      XrmBindingList bindings
      XrmQuarkList quarks
      char *value

database

  Specifies the resource database.

bindings

  Specifies a list of bindings.

quarks

  Specifies the complete or partial name or the class list of the resource.

value

  Specifies the value of the resource, which is specified as a string.

If database contains NULL, creates a new database and returns a pointer to it. is a convenience routine that constructs an XrmValue for the value string (by calling `strlen` to compute the size) and then calls , using a ``String'' representation type. The value is stored in the database without modification.

To add a single resource entry that is specified as a string that contains both a name and a value, use .

      void XrmPutLineResource
      XrmDatabase *database
      char *line

database

  Specifies the resource database.

line

  Specifies the resource name and value pair as a single string.

If database contains NULL, creates a new database and returns a pointer to it. adds a single resource entry to the specified database. The line should be in valid ResourceLine format (see section 15.1) terminated by a newline or null character; the database that results from using a string with incorrect syntax is implementation-dependent. The string is parsed in the locale of the database. If the ResourceName is not in the Host Portable Character Encoding, the result is implementation-dependent. Note that comment lines are not stored.

## Enumerating Database Entries

To enumerate the entries of a database, use .

    #define       XrmEnumAllLevels       0
    #define       XrmEnumOneLevel        0

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

database

  Specifies the resource database.

name_prefix

  Specifies the resource name prefix.

class_prefix

  Specifies the resource class prefix.

mode

  Specifies the number of levels to enumerate.

proc

  Specifies the procedure that is to be called for each matching entry.

arg

  Specifies the user-supplied argument that will be passed to the procedure.

The function calls the specified procedure for each resource in the database that would match some completion of the given name/class resource prefix. The order in which resources are found is implementation-dependent. If mode is XrmEnumOneLevel, a resource must match the given name/class prefix with just a single name and class appended. If mode is XrmEnumAllLevels, the resource must match the given name/class prefix with one or more names and classes appended. If the procedure returns True, the enumeration terminates and the function returns True. If the procedure always returns False, all matching resources are enumerated and the function returns False.

The procedure is called with the following arguments:

    (*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. Note that pointers to the database and type are passed, but these values should not be modified.

The procedure must not modify the database. 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.

## Parsing Command Line Options

The function can be used to parse the command line arguments to a program and modify a resource database with selected entries from the command line.

    typedef enum {
         XrmoptionNoArg,     /* Value is specified in XrmOptionDescRec.value */
         XrmoptionIsArg,     /* Value is the option string itself */
         XrmoptionStickyArg,     /* Value is characters immediately following option */
         XrmoptionSepArg,     /* Value is next argument in argv */
         XrmoptionResArg,     /* Resource and value in next argument in argv */
         XrmoptionSkipArg,     /* Ignore this option and the next argument in argv */
         XrmoptionSkipLine,     /* Ignore this option and the rest of argv */
         XrmoptionSkipNArgs     /* Ignore this option and the next
              \ \ \ XrmOptionDescRec.value arguments in argv */
    } XrmOptionKind;

Note that `XrmoptionSkipArg` is equivalent to `XrmoptionSkipNArgs` with the XrmOptionDescRec.value field containing the value one. Note also that the value zero for `XrmoptionSkipNArgs` indicates that only the option itself is to be skipped.

    typedef struct {
         char *option;     /* Option specification string in argv              */
         char *specifier;     /* Binding and resource name (sans application name)    */
         XrmOptionKind argKind;     /* Which style of option it is         */
         XPointer value;     /* Value to provide if XrmoptionNoArg or
              \ \ \ XrmoptionSkipNArgs   */
    } XrmOptionDescRec, *XrmOptionDescList;

To load a resource database from a C command line, use .

      void XrmParseCommand
      XrmDatabase *database
      XrmOptionDescList table
      int table_count
      char *name
      int *argc_in_out
      char **argv_in_out

database

  Specifies the resource database.

table

  Specifies the table of command line arguments to be parsed.

table_count

  Specifies the number of entries in the table.

name

  Specifies the application name.

argc_in_out

  Specifies the number of arguments and returns the number of remaining arguments.

argv_in_out

  Specifies the command line arguments and returns the remaining arguments.

The function parses an (argc, argv) pair according to the specified option table, loads recognized options into the specified database with type ``String,'' and modifies the (argc, argv) pair to remove all recognized options. If database contains NULL, creates a new database and returns a pointer to it. Otherwise, entries are added to the database specified. If a database is created, it is created in the current locale.

The specified table is used to parse the command line. Recognized options in the table are removed from argv, and entries are added to the specified resource database in the order they occur in argv. The table entries contain information on the option string, the option name, the style of option, and a value to provide if the option kind is `XrmoptionNoArg`. The option names are compared byte-for-byte to arguments in argv, independent of any locale. The resource values given in the table are stored in the resource database without modification. All resource database entries are created using a ``String'' representation type. The argc argument specifies the number of arguments in argv and is set on return to the remaining number of arguments that were not parsed. The name argument should be the name of your application for use in building the database entry. The name argument is prefixed to the resourceName in the option table before storing a database entry. The name argument is treated as a single component, even if it has embedded periods. No separating (binding) character is inserted, so the table must contain either a period (.) or an asterisk (*) as the first character in each resourceName entry. To specify a more completely qualified resource name, the resourceName entry can contain multiple components. If the name argument and the resourceNames are not in the Host Portable Character Encoding, the result is implementation-dependent.

The following provides a sample option table:

    static XrmOptionDescRec opTable[] = {
    {"-background",     "*background",                 XrmoptionSepArg,    (XPointer) NULL},
    {"-bd",             "*borderColor",                XrmoptionSepArg,    (XPointer) NULL},
    {"-bg",             "*background",                 XrmoptionSepArg,    (XPointer) NULL},
    {"-borderwidth",    "*TopLevelShell.borderWidth",  XrmoptionSepArg,    (XPointer) NULL},
    {"-bordercolor",    "*borderColor",                XrmoptionSepArg,    (XPointer) NULL},
    {"-bw",             "*TopLevelShell.borderWidth",  XrmoptionSepArg,    (XPointer) NULL},
    {"-display",        ".display",                    XrmoptionSepArg,    (XPointer) NULL},
    {"-fg",             "*foreground",                 XrmoptionSepArg,    (XPointer) NULL},
    {"-fn",             "*font",                       XrmoptionSepArg,    (XPointer) NULL},
    {"-font",           "*font",                       XrmoptionSepArg,    (XPointer) NULL},
    {"-foreground",     "*foreground",                 XrmoptionSepArg,    (XPointer) NULL},
    {"-geometry",       ".TopLevelShell.geometry",     XrmoptionSepArg,    (XPointer) NULL},
    {"-iconic",         ".TopLevelShell.iconic",       XrmoptionNoArg,     (XPointer) "on"},
    {"-name",           ".name",                       XrmoptionSepArg,    (XPointer) NULL},
    {"-reverse",        "*reverseVideo",               XrmoptionNoArg,     (XPointer) "on"},
    {"-rv",             "*reverseVideo",               XrmoptionNoArg,     (XPointer) "on"},
    {"-synchronous",    "*synchronous",                XrmoptionNoArg,     (XPointer) "on"},
    {"-title",          ".TopLevelShell.title",        XrmoptionSepArg,    (XPointer) NULL},
    {"-xrm",            NULL,                          XrmoptionResArg,    (XPointer) NULL},
    };

In this table, if the -background (or -bg) option is used to set background colors, the stored resource specifier matches all resources of attribute background. If the -borderwidth option is used, the stored resource specifier applies only to border width attributes of class TopLevelShell (that is, outer-most windows, including pop-up windows). If the -title option is used to set a window name, only the topmost application windows receive the resource.

When parsing the command line, any unique unambiguous abbreviation for an option name in the table is considered a match for the option. Note that uppercase and lowercase matter.