ms@cerc.wvu.wvnet.edu (Mark Starvaggi) (02/21/91)
I am having a problem retrieving resources from the resource manager database. I am able to load a file into the database using XrmGetFileDatabase, but I cannot retrieve the information from the database. I am getting a segmentation fault upon using the XrmGetResource function. If anyone has successfully used these Xrm functions please send me email. An example of code would also be greatly appreciated. Thank You Mark Starvaggi (email address: ms@cerc.wvu.wvnet.edu)
dfs@bellcore.com (Deborah Swayne) (02/21/91)
ms@cerc.wvu.wvnet.edu (Mark Starvaggi) posts: > I am having a problem retrieving resources from the resource manager database. > I am able to load a file into the database using XrmGetFileDatabase, but I > cannot retrieve the information from the database. What he said. I'm successful at reading in a resource file, but when I then initiate, as a subroutine, the program I want to use those resources, they are ignored. I must be doing something wrong, or more likely failing to do something, but I don't know what. More details available to anyone who's willing to listen. Debby Swayne dfs@bellcore.com
david@jpl-devvax.JPL.NASA.GOV (David E. Smyth) (02/21/91)
dfs@bellcore.com (Deborah Swayne) writes: >ms@cerc.wvu.wvnet.edu (Mark Starvaggi) posts: > >> I am having a problem retrieving resources from the resource manager database. >> I am able to load a file into the database using XrmGetFileDatabase, but I >> cannot retrieve the information from the database. > >What he said. I'm successful at reading in a resource file, but >when I then initiate, as a subroutine, the program I want to use >those resources, they are ignored. I must be doing something >wrong, or more likely failing to do something, but I don't know what. I'm guessing at your problems: You must merge the database into the display structure, and you must load the resource values you are getting from the Xrm database into a structure - don't put them straight into variables (some machines barf). Here is some excerpts from Wcl (the Widget Creation Library): if ((rdb = XrmGetFileDatabase( name )) != NULL ) XrmMergeDatabases (rdb, &(dpy->db) ); else /* do some error processing - file was not a readable resource file */ Note that the database must be merged with the existing database on the display connection. The original database is built during toolkit initialization. Here is an example of pulling data from the database for a widget: XtGetApplicationResources ( root, &res, wc_resources, XtNumber(wc_resources), NULL, 0 ); root is the widget I'm getting resources for, res is a structure whose members are loaded with values due to this call, wc_resources is the XtResources structure which describes the resource name and type, the final NULL and O are args and numArgs which I never use (I put the default values in the wc_resources struct). Specifically, here is the res struct and wc_resources struct declatations: typedef struct _ResourceRec { String resFile; /* additional resource file name */ String children; /* list of children names to create */ String popups; /* list of popup children to create */ WidgetClass class; /* widget class pointer */ WidgetClass classFromName; /* widget class pointer */ ConCacheRec* constructor; /* ptr to Constructo cache record */ Boolean managed; /* created managed (default TRUE) */ Boolean deferred; /* deferred creation, (def FALSE) */ Boolean trace; /* creation trace required */ XtCallbackList callback; /* creation callback list */ } ResourceRec, *ResourceRecPtr; ResourceRec res; XtResource wc_resources[] = { { WcNwcResFile, WcCWcResFile, XtRString, sizeof(String), XtOffset(ResourceRecPtr, resFile ), XtRImmediate, (caddr_t) NULL }, { WcNwcChildren, WcCWcChildren, XtRString, sizeof(String), XtOffset(ResourceRecPtr, children ), XtRImmediate, (caddr_t) NULL }, { WcNwcPopups, WcCWcPopups, XtRString, sizeof(String), XtOffset(ResourceRecPtr, popups ), XtRImmediate, (caddr_t) NULL }, { WcNwcClass, WcCWcClass, WcRClassPtr, sizeof(caddr_t), XtOffset(ResourceRecPtr, class ), XtRImmediate, (caddr_t) NULL }, { WcNwcClassName, WcCWcClassName, WcRClassName, sizeof(caddr_t), XtOffset(ResourceRecPtr, classFromName ), XtRImmediate, (caddr_t) NULL }, { WcNwcConstructor, WcCWcConstructor, WcRConstructor, sizeof(caddr_t), XtOffset(ResourceRecPtr, constructor ), XtRImmediate, (caddr_t) NULL }, { WcNwcManaged, WcCWcManaged, XtRBoolean, sizeof(Boolean), XtOffset(ResourceRecPtr, managed), XtRImmediate, (caddr_t) TRUE }, { WcNwcTrace, WcCWcTrace, XtRBoolean, sizeof(Boolean), XtOffset(ResourceRecPtr, trace), XtRImmediate, (caddr_t) FALSE }, { WcNwcCallback, WcCWcCallback, XtRCallback, sizeof(XtCallbackList), XtOffset(ResourceRecPtr, callback ), XtRImmediate, (caddr_t) NULL } };
mouse@lightning.mcrcim.mcgill.EDU (02/21/91)
> I am having a problem retrieving resources from the resource manager > database. I am able to load a file into the database using > XrmGetFileDatabase, but I cannot retrieve the information from the > database. I am getting a segmentation fault upon using the > XrmGetResource function. I can't really guess why this might be without seeing the code. > If anyone has successfully used these Xrm functions please send me > email. An example of code would also be greatly appreciated. My code does things like this. (This is highly condensed; lots of irrelevant code has been stripped out.) char *defaults = "..."; /* hardwired default defaults */ XrmDatabase db; .... char *str; XrmDatabase db2; db = XrmGetStringDatabase(defaults); str = XResourceManagerString(disp); if (str) { db2 = XrmGetStringDatabase(str); XrmMergeDatabases(db2,&db); } else { /* ...construct a filename based on $HOME... */ db2 = XrmGetFileDatabase(str); if (db2) { XrmMergeDatabases(db2,&db); } } .... char *name; char *class; char *type; XrmValue value; if (XrmGetResource(db,name,class,&type,&value) == False) { /* ...failure... */ } else { /* value.addr points to the thing found in the database */ } If you're still having trouble, I'd be willing to look at a small test program.... der Mouse old: mcgill-vision!mouse new: mouse@larry.mcrcim.mcgill.edu
marra@samuel.enet.dec.com (Dave Marra) (02/21/91)
> I am having a problem retrieving resources from the resource manager > database. I am able to load a file into the database using > XrmGetFileDatabase, but I cannot retrieve the information from the > database. I am getting a segmentation fault upon using the > XrmGetResource function. ... Can you folks send or post a sample of your code? I wrote the tests that you can find on the T7 release of the X11r4 tapes for the Xrm stuff. In the process we debugged a lot of the MIT code. I know how this stuff works... .dave. + Dave Marra + TMF Engineering + X11/Motif/Shared Library Performance, Regression, and Validation suites + 37 Carlene Drive, Nashua New Hampshire 03062-1480 + + Currently working AT DEC in Merrimack, NH