Can you use struct XrmOptionDescRec array to pass non-Motif related parameters to an application?

68 views Asked by At

I have seen how to configure xrm resource names via XrmOptionDescRec struct array. An example of this can be found in this question.

I am wondering if I can also pass non-X11 related arguments via this way.

In particular, if I want to pass the name of a named pipe to the application so the X11 application opens that particular named pipe,

  1. would it be using XrmOptionDescRec struct array an option?
  2. Can I set up and retrieve arbitrary resource names?
  3. If so, how do I retrieve the argument value?
#include <stdlib.h>
#include <stdio.h>
 
#include <Xm/Xm.h>
#include <Xm/PushB.h>
 
static XrmOptionDescRec options[] = {
    { "-namedpipe", "namedpipe", XrmoptionSepArg, NULL },
};
 
int main(int argc, char *argv[]) {

    Widget          toplevel;             /* Top Level Button */
    XtAppContext    app;                  /* Application Context */
    char            *window_title = NULL; /* Top Level Window Title */
    
    /* INITIALIZE TOP LEVEL WINDOW */
    XtSetLanguageProc(NULL, NULL, NULL);
    toplevel = XtVaOpenApplication( &app, argv[0], options, XtNumber(options), &argc, argv, NULL, sessionShellWidgetClass, NULL);

    /* HOW WOULD I GET HERE named_pipe ASSIGNED ????? */
    char named_pipe[256];
    ...
    
    /* REALIZE TOPLEVEL WINDOW AND LAUNCH APPLICATION LOOP */
    XtRealizeWidget(toplevel);
    XtAppMainLoop(app);
    
    return 0;

}
1

There are 1 answers

0
M.E. On

Just for anyone interested. In Xt/Motif applications this seems to be the way to handle application command line parameters as resources (they have the advantage of being handled smoothly by the Xt wrappers around Xlib resource manager functions). So basically you will be able to define the argument in user, application and system-wide resource files, and also via command line.

#define XtNnamedPipe "namedPipe"
#define XtCNamedPipe "NamedPipe"

typedef struct {
    String named_pipe;
} AppData;

AppData app_data;

static XtResource resources[] = {
    {
        XtNnamedPipe,
        XtCNamedPipe,
        XtRString,
        sizeof(String),
        XtOffsetOf(AppData, named_pipe),
        XtRString,
        NULL
    },
};

static XrmOptionDescRec options[] = {
    {"-namedpipe",  "namedPipe",    XrmoptionSepArg,    "/tmp/namedpipe0"},
};

...


int main(int argc, char *argv[]) {

    ...

    toplevel = XtVaOpenApplication( 
        &app, argv[0], options, XtNumber(options), &argc, argv, NULL, sessionShellWidgetClass,
        XmNwidth, 400, XmNheight, 300, NULL
    );

    ...

    /* GET APPLICATION RESOURCES */
    XtGetApplicationResources(
        toplevel,
        &app_data,
        resources,
        XtNumber(resources),
        NULL,
        0);

    printf("DEBUG: %s\n", app_data.named_pipe);       

    ...
}