| Page: | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|
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 wellengineered 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>.
| Home |
|---|
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 FileName ResourceSpec ResourceName Binding WhiteSpace Component ComponentName NameChar Value | = Comment|IncludeFile|ResourceSpec|<empty line> = "!" {<any character except null or newline>} = "#" WhiteSpace "include" WhiteSpace FileName WhiteSpace = <valid filename for operating system> = WhiteSpace ResourceName WhiteSpace ":" WhiteSpace Value = [Binding] {Component Binding} ComponentName = "."|"*" = {<space>|<horizontal tab>} = "?"|ComponentName = NameChar {NameChar} = "a"-"z"|"A"-"Z"|"0"- "9"|"_"|"-" = {<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 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 "„„" 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:
| Home |
|---|
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 "?" are 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:
| To illustrate these rules, consider the following resource database entries: | |||
| xmh*Paned*activeForeground: *incorporate.Foreground: xmh.toc*Command*activeForeground: xmh.toc*?.Foreground: xmh.toc*Command.activeForeground: | red blue green white black | (entry A) (entry B) (entry C) (entry D) (entry E) | |
| Consider a query for the resource: | ||
| xmh.toc.messagefunctions.incorporate.activeForeground Xmh.Paned.Box.Command.Foreground | (name) (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.
| Home |
|---|
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 XrmStringToQuark or XrmPermStringToQuark.
#define XrmStringToName(string) XrrnStringToQuark(string)
#define XrmStringToClass(string) XrrnStringToQuark(string)
#define XrmStringToRepresentation(string) XrmStringToQuark(string)
XrmQuark XmmStringToQuark (string)
char *string;
XrmQuark XrmPermStringToQuark (string)
char *string;
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 XrmStringToQuark need not be permanently allocated storage. XrmPermStringToQuark is just like XrmStringToQuark, 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 XrmQuarkToString.
For any given quark, if XrmStringToQuark returns a non-NULL value, all future calls will return the same value (identical address).
To convert a quark to a string, use XrmQuarkToString.
#define XrmNameToString(name) XrmQuarkToString(name)
#define XrmClassToString(class) XrmQuarkToString(class)
#define XrmRepresentationToString(type) XrmQuarkToString(type)
char *XrmQuarkToString (quark)
XrmQuark quark;
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, XrmQuarkToString returns NULL. For any given quark, if XrmQuarkToString 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 XrmStringToQuarkList.
#define XrmStringToNameList(str, name) XrmStringToQuarkList((str),
(name))
#define XrmStringToClassList(str, class) XrmStringToQuarkList((str),
(class))
void XrmStringToQuarkList(string,quarks_return)
char *string;
XrmQuarkList quarks_return;
The XrmStringToQuarkList 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.
XrmStringToBindingQuarkList(string, bindings_return, quarks_return)
char *string;
XrmBindingList bindings_return;
XrmQuarkList quarks_return;
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: bindings: | a loose | b tight | c loose |
| Home |
|---|
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 XrmInitialize.
void XrmInitialize();To retrieve a database from disk, use XrmGetFileDatabase.
XrmDatabase XrmGetFileDatabase(filename)
char *filename;
The XrmGetFileDatabase 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, XrmGetFileDatabase returns NULL.
To store a copy of a database to disk, use XrmPutFileDatabase.
void XrmPutFileDatabase(database, stored_db)
XrmDatabase database;
char *stored_db;
The XrmPutFileDatabase 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 XResourceManagerString.
char *XResourceManagerString(display)
Display *display;
The XResourceManagerString function returns the RESOURCE_MANAGER property from the server's root window of screen zero, which was returned when the connection was opened using XOpenDisplay. The property is converted from type STRING to the current locale. The conversion is identical to that produced by XmbTextPropertyToTextList 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 XrmGetStringDatabase. If no property exists, NULL is returned.
To obtain a pointer to the screen-specific resources of a screen, use XScreenResourceString.
char *XScreenResourceString(screen)
Screen *screen;
The XScreenResourceString 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 XmbTextPropertyToTextList for a single element STRING property. The property value must be in a format that is acceptable to XrmGetStringDatabase. If no property exists, NULL is returned. The caller is responsible for freeing the returned string by using XFree.
To create a database from a string, use XrmGetStringDatabase.
XrmDatabase XrmGetStringDatabase(data)
char *data;
The XrmGetStringDatabase function creates a new database and stores the resources specified in the specified null-terminated string. XrmGetStringDatabase is similar to XrmGetFileDatabase 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 locale name of a database, use XrmLocaleOfDatabase.
char *XrmLocaleOfDatabase(database)
XrmDatabase database;
The XrmLocaleOfDatabase 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 XrmDestroyDatabase.
void XrmDestroyDatabase(database)
XrmDatabase database;
If database is NULL, XrmDestroyDatabase returns immediately.
To associate a resource database with a display, use XrmSetDatabase.
void XrmSetDatabase(display, database)
Display *display;
XrmDatabase database;
The XrmSetDatabase 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 XrmGetDatabase.
XrmDatabase XrmGetDatabase(display)
Display *display;
The XrmGetDatabase function returns the database associated with the specified display. It returns NULL if a database has not yet been set.
| Home |
|---|
To merge the contents of a resource file into a database, use XrmCombineFileDatabase.
Status XrmCombineFileDatabase(filename, target_db, override)
char *filename;
XrmDatabase *target_db;
Bool override;
The XrmCombineFileDatabase 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, XrmCombineFileDatabase 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 XrmCombineDatabase.
void XrmCombineDatabase(source_db, target_db, override)
XrmDatabase source_db, *target_db;
Bool override;
The XrmCombineDatabase 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, XrmCombineDatabase 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 XrmMergeDatabases.
void XrmMergeDatabases(source_db, target_db)
XrmDatabase source_db, *target_db;
Calling the XrmMergeDatabases function is equivalent to calling the XrmCombineDatabase function with an ovenride argument of True.
| Home |
|---|
To retrieve a resource from a resource database, use XrmGetResource, XrmQGetResource, or XrmQGetSearchResource.
Bool XrmGetResource(darabase, str_name, str_class, str_type_return, value_return)
XrmDatabase database;
char *str_name;
char *str_class;
char **str_type_return;
XrmValue *value_return;
Bool XrmQGetResource(database, quark_name, quark_class, quark_type_return, value_return)
XrmDatabase database;
XrmNameList quark_name;
XrmClassList quark_class;
XrmRepresentation *quark_type_return;
XrmValue *value_return;
The XrmGetResource and XrmQGetResource 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 XrmPutResource, XrmQPutResource, or XrmMergeDatabases. 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 XrmGetResource and XrmQGetResource 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 are made with only the last name/class differing in each probe. The XrmGetResource 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.
typedef XrmHashTable *XrmSearchList;
Bool XrmQGetSearchList(database, names, classes, list_return, list_length)
XrmDatabase database;
XrmNameList names;
XrmClassList classes;
XrmSearchList list_return;
int list_length;
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 XrmGetResource 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 XrmQGetSearchResource.
Bool XrmQGetSearchResource(list, name, class, type_return, value_return)
XrmSearchList list;
XrmName name;
XrmClass class;
XrmRepresentation *type_return;
XrmValue *value_return;
The XrmQGetSearchResource 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. XrmQGetSearchResource 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 XrmQGetSearchResource with the last component name and class returns the same database entry as XrmGetResource and XrmQGetResource with the fully qualified name and class.
| Home |
|---|
To store resources into the database, use XrmPutResource or XrmQPutResource. Both functions take a partial resource specification, a representation type, and a value. This value is copied into the specified database.
void XrmPutResource(database, specifier, type, value)
XrmDatabase *database;
char *specifier;
char *type;
XrmValue *value;
If database contains NULL, XrmPutResource creates a new database and returns a pointer to it. XrmPutResource is a convenience function that calls XrmStringToBindingQuarkList followed by:
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(database, bindings, quarks, type, value)
XrmDatabase *database;
XrmBindingList bindings;
XrmQuarkList quarks;
XrmRepresentation type;
XrmValue *value;
If database contains NULL, XrmQPutResource 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 XrmPutStringResource.
void XrmPutStringResource(database, specifier, value)
XrmDatabase *database;
char *specifier;
char *value;
If database contains NULL, XrmPutStringResource creates a new database and returns a pointer to it. XrmPutStringResource adds a resource with the specified value to the specified database. XrmPutStringResource is a convenience function that first calls XrmStringToBindingQuarkList on the specifier and then calls XrmQPutResource, 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 XrmQPutStringResource.
void XrmQPutStringResource(database, bindings, quarks, value)
XrmDatabase *dambase;
XrmBindingList bindings;
XrmQuarkList quarks;
char *value;
If database contains NULL, XrmQPutStringResource creates a new database and returns a pointer to it. XrmQPutStringResource is a convenience routine that constructs an XrmValue for the value string (by calling strlen to compute the size) and then calls XrmQPutResource, 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 XrmPutLineResource.
void XrmPutLineResource(database, line) XrmDatabase *database; char *line;
If database contains NULL, XrmPutLineResource creates a new database and returns a pointer to it. XrmPutLineResourcc 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.
| Home |
|---|
To enumerate the entries of a database, use XrmEnumerateDatabase.
| #define #define | XrmEnumAllLevels XrmEnumOneLevel | 0 1 |
Bool XrmEnumerateDatabase(database, name_prefix, class_prefix, mode, proc, arg)
XrmDatabase database;
XrmNameList name_prefix;
XrmClassList class_prefix;
int mode;
Bool (*proc)();
XPointer arg;
The XrmEnumerateDatabase 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 closure; | |
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.
| Home |
|---|
The XrmParseCommand 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, XrmoptionIsArg, XrmoptionStickyArg, XrmoptionSepArg, XrmoptionResArg, XrmoptionSkipArg, XrmoptionSkipLine, XrmoptionSkipNArgs | /* Value is specified in XrmOptionDescRec.value */ /* Value is the option string itself */ /* Value is characters immediately following option */ /* Value is next argument in argv */ /* Resource and value in next argument in argv */ /* Ignore this option and the next argument in argv */ /* Ignore this option and the rest of argv */ /* Ignore this option and the next XrmOptionDeseRec.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; char *specifier; XrmOptionKind argKind; XPointer value; | /* Option specification string in argv */ /* Binding and resource name (sans application name) */ /* Which style of option it is */ /* Value to provide if XrmoptionNoArg or XrmoptionSkipNArgs */ | |
| } XrmOptionDescRec, *XrmOptionDescList; | ||
To load a resource database from a C command line, use XrmParseCommand.
void XrmParseCommand(database, table, table_count, name, argc_in_out, argv_in_out)
XrmDatabase *database;
XrmOptionDescList table;
int table_count;
char *name;
int *argc_in_out;
char **argv_in_out;
The XrmParseCommand 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,
XrmParseCommand 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", {"-bd", {"-bg", {"-borderwidth", {"-bordercolor", {"-bw", {"-display", {"-fg", {"-fn", {"-font", {"-foreground", {"-geometry", {"-iconic", {"-name", {"-reverse", {"-rv", {"-synchronous", {"-title", {"-xrm", }; | "*background", "*borderColor", "*background", "*TopLevelShell.borderWidth", "*borderColor", "*TopLevelShell.borderWidth", ".display", "*foreground", "*font", "*font", "*foreground", ".TopLevelShell.geometry", ".TopLevelShell.iconic", ".name", "*reverseVideo", "*reverseVideo", "*synchronous", ".TopLevelShell.title", NULL, | XrmoptionSepArg, XrmoptionSepArg, XrmoptionSepArg, XrmoptionSepArg, XrmoptionSepArg, XrmoptionSepArg, XrmoptionSepArg, XrmoptionSepArg, XrmoptionSepArg, XrmoptionSepArg, XrmoptionSepArg, XrmoptionSepArg, XrmoptionNoArg, XrmoptionSepArg, XrmoptionNoArg, XrmoptionNoArg, XrmoptionNoArg, XrmoptionSepArg, XrmoptionResArg, | (XPointer) NULL}, (XPointer) NULL}, (XPointer) NULL}, (XPointer) NULL}, (XPointer) NULL}, (XPointer) NULL}, (XPointer) NULL}, (XPointer) NULL}, (XPointer) NULL}, (XPointer) NULL}, (XPointer) NULL}, (XPointer) NULL}, (XPointer) "on"}, (XPointer) NULL}, (XPointer) "on"}, (XPointer) "on"}, (XPointer) "on"}, (XPointer) NULL}, (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.
| Home |
|---|
| Contents | Previous Chapter | Next Chapter |