[comp.windows.x] XtGetApplicationResources seems to fail under X11R4

huisjes@cs.vu.nl (Michiel Huisjes) (09/27/90)

It took me three hours to figure out that the sample program below is
correct according to the docs available.
The problem is, that XtAppInitialize accepts an XrmOptionDescRec options
structure list, but XtGetApplicationResources fails to retrieve the right
values afterwards.
Calling the program with parameters "-nolabel -h galjas.cs.vu.nl -port 13
-update 400" will show that XtAppInitialize does indeed parse the options
(i.e. argc == 1 after the call), but XtGetApplicationResources fails to
give me anything else than the specified default values of
{ TRUE, NULL, NULL, "60" };

Am I really doing something wrong, or is this a bug?

P.S. We're running SUN/OS 4.0.1 on a SPARC station using X11R4.
--
			Michiel Huisjes.  (huisjes@cs.vu.nl)
			       ..!uunet!cs.vu.nl!huisjes
-- cut here --
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#include <X11/Cardinals.h>

typedef struct s_resources {
        Boolean show_label;
        String  host_name;
        String  port_number;
        String  update_time;
} XPingResources;

/*
 * I tried "showLabel", "*showLabel", ".showLabel" and "Xping.showLabel"
 * but alas
 */
static XrmOptionDescRec options[] = {
        { "-nolabel", ".showLabel",  XrmoptionNoArg,  "False" },
        { "-host",    ".hostName",   XrmoptionSepArg, NULL },
        { "-h",       "*hostName",   XrmoptionSepArg, NULL },
        { "-port",    ".portName",   XrmoptionSepArg, NULL },
        { "-p",       "*portName",   XrmoptionSepArg, NULL },
        { "-update",  ".updateTime", XrmoptionSepArg, NULL },
        { "-u",       "*updateTime", XrmoptionSepArg, NULL },
};

static XtResource resource_specs[] = {
  { "showLabel", XtCBoolean, XtRBoolean, sizeof (Boolean),
    XtOffsetOf (XPingResources, show_label), XtRImmediate, (caddr_t) TRUE },

  { "hostName", XtCString, XtRString, sizeof (String),
    XtOffsetOf (XPingResources, host_name),   XtRString, NULL },

  { "portName", XtCString, XtRString, sizeof (String),
    XtOffsetOf (XPingResources, port_number), XtRString, NULL },

  { "updateTime", XtCString, XtRString, sizeof (String),
    XtOffsetOf (XPingResources, update_time), XtRString, "60" }
};

static String fallback_resources[] = { 
        "*highlightThickness: 0",
        "*font: devps.cb.10.75",
        NULL
};

main (argc, argv)
int argc;
char *argv[];
{
	XtAppContext app_con;
        Widget Toplevel;
	XPingResources resources;

        Toplevel = XtAppInitialize (&app_con, "Xping",
                                    options, XtNumber (options),
                                    &argc, argv, fallback_resources,
				    NULL, ZERO);

        XtGetApplicationResources (Toplevel, &resources, resource_specs,
                                   XtNumber (resource_specs), NULL, ZERO);
	
	printf ("argc = %d\n\n", argc);
	printf ("resources.show_label = %s\n",
		(resources.show_label == TRUE) ? "True" : "False");
	printf ("resources.host_name = %s\n",
		(resources.host_name == NULL) ? "<none>" : resources.host_name);
	printf ("resources.port_number = %s\n",
		(resources.port_number == NULL) ?
					     "<none>" : resources.port_number);
	printf ("resources.update_time = %s\n", resources.update_time);
}

converse@EXPO.LCS.MIT.EDU (09/28/90)

> The problem is, that XtAppInitialize accepts an XrmOptionDescRec options
> structure list, but XtGetApplicationResources fails to retrieve the right
> values afterwards.

Your program worked properly here after I changed <X11/Cardinals.h> to
<X11/Xaw/Cardinals.h>.   But that's probably not the problem.

> P.S. We're running SUN/OS 4.0.1 on a SPARC station using X11R4.

It ran on SunOS Release 4.1 on a SPARCstation, X11R4 + all public patches + more.