[comp.windows.x] I can't get XGetDefault to work

bill@polygen.uucp (Bill Poitras) (09/26/90)

I am running X11R4 on a Sun 3/60 under SunOS 4.1.  In one of my appications,
lets call "XYZ" for argument sake.  I make a the following calls:

    sprintf(appstring, "%s.geometry", "test");
    geostr = XGetDefault(surface->display, "XYZ", appstring);

geostr is a char pointer, appstring is a 80 element character array.  geostr
is always null in all of the applications that use this code.  I am running
Twm with UsePPosition set to "on" in my .twmrc.  WHAT IS WRONG!!! Is there
AFM that I can R to help me?  Any help would greatly be appreciated.


+-----------------+---------------------------+-----------------------------+
| Bill Poitras    | Polygen Corporation       | {princeton mit-eddie        |
|     (bill)      | Waltham, MA USA           |  bu sunne}!polygen!bill     |
|                 |                           | bill@polygen.com            |
+-----------------+---------------------------+-----------------------------+

rws@EXPO.LCS.MIT.EDU (Bob Scheifler) (09/26/90)

    sprintf(appstring, "%s.geometry", "test");
    geostr = XGetDefault(surface->display, "XYZ", appstring);

The R4 XGetDefault only accepts a singleton name in the third argument,
not a compound name.  This matches the intention of the specification.
The R3 version worked with a compound name, although it shouldn't have.
Many have flamed about this, you probably will too. :-)  I suppose you
can either "fix" XGetDefault to work the way you want it to, or recode
to use real Xrm interfaces instead of this X10 pseudo-compatibility
interface.

casey@gauss.llnl.gov (Casey Leedom) (10/02/90)

  [[I tried replying to Bill directly but neither his path nor reply-to
address worked.]]

  I was one of the people who flamed and still have yet to receive a
rational answer why we can't back support the old XGetDefault behavior.
We now have a backward compatibility routine which isn't backwards
compatible.  Oh well.

  Here's a patch to XGetDefault that will make it work the way it used to.
Note, as Bob points out, you should change your code to use the Xrm stuff
directly for compatibility reasons.

Casey

P.S.  The following patch is relative to MIT patch level 14.

-----
%%% mit/lib/X/XGetDflt.c:
%%% 
%%% Fix XGetDefault so that XGetDefault(dpy, program, name) works when name
%%% containing a compound string (``foo.bar'', etc.)

*** mit/lib/X/XGetDflt.c-dist	Tue Jan 30 18:35:20 1990
--- mit/lib/X/XGetDflt.c	Sun Feb 11 22:32:00 1990
***************
*** 124,134 ****
  	register char *name;		/* name of option program wants */
  #endif
  {					/* to get, for example, "font"  */
! 	XrmName names[3];
! 	XrmClass classes[3];
  	XrmRepresentation fromType;
  	XrmValue result;
  	char *progname;
  
  	/*
  	 * strip path off of program name (XXX - this is OS specific)
--- 124,136 ----
  	register char *name;		/* name of option program wants */
  #endif
  {					/* to get, for example, "font"  */
! 	XrmName names[100];	/* 100: YECH -- and XrmStringToNameList */
! 	XrmClass classes[100];	/* does not even let us pass in this limit */
  	XrmRepresentation fromType;
  	XrmValue result;
  	char *progname;
+ 	register XrmClass classp;
+ 	register int i;
  
  	/*
  	 * strip path off of program name (XXX - this is OS specific)
***************
*** 150,160 ****
  	UnlockDisplay(dpy);
  
  	names[0] = XrmStringToName(progname);
- 	names[1] = XrmStringToName(name);
- 	names[2] = NULLQUARK;
  	classes[0] = XrmStringToClass("Program");
! 	classes[1] = XrmStringToClass("Name");
! 	classes[2] = NULLQUARK;
  	(void)XrmQGetResource(dpy->db, names, classes, &fromType, &result);
  	return (result.addr);
  }
--- 152,163 ----
  	UnlockDisplay(dpy);
  
  	names[0] = XrmStringToName(progname);
  	classes[0] = XrmStringToClass("Program");
! 	XrmStringToNameList(name, &names[1]);
! 	classp = XrmStringToClass("Name");
! 	for (i = 1; names[i] != NULLQUARK; i++)
! 		classes[i] = classp;
! 	classes[i] = NULLQUARK;
  	(void)XrmQGetResource(dpy->db, names, classes, &fromType, &result);
  	return (result.addr);
  }