您可以使用 struct XrmOptionDescRec 数组将非 Motif 相关参数传递给应用程序吗? [英] Can you use struct XrmOptionDescRec array to pass non-Motif related parameters to an application?

查看:23
本文介绍了您可以使用 struct XrmOptionDescRec 数组将非 Motif 相关参数传递给应用程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到如何通过 XrmOptionDescRec 结构数组配置 xrm 资源名称.一个例子可以在this问题中找到.>

我想知道我是否也可以通过这种方式传递非 X11 相关参数.

特别是,如果我想将命名管道的名称传递给应用程序,以便 X11 应用程序打开该特定命名管道,

  1. 是否可以选择使用 XrmOptionDescRec 结构数组?
  2. 我可以设置和检索任意资源名称吗?
  3. 如果是这样,我如何检索参数值?

#include #include #include #include 静态 XrmOptionDescRec 选项 [] = {{ "-namedpipe", "namedpipe", XrmoptionSepArg, NULL },};int main(int argc, char *argv[]) {小部件顶层;/* 顶层按钮 */XtAppContext 应用程序;/* 应用上下文 */字符 *window_title = NULL;/* 顶层窗口标题 *//* 初始化顶层窗口 */XtSetLanguageProc(NULL, NULL, NULL);toplevel = XtVaOpenApplication( &app, argv[0], options, XtNumber(options), &argc, argv, NULL, sessionShellWidgetClass, NULL);/* 我怎么到这里named_pipe ASSIGNED ?????*/字符命名管道[256];.../* 实现顶层窗口并启动应用程序循环 */XtRealizeWidget(顶层);XtAppMainLoop(app);返回0;}

解决方案

仅供任何感兴趣的人使用.在 Xt/Motif 应用程序中,这似乎是将应用程序命令行参数作为资源处理的方式(它们的优点是可以被 Xlib 资源管理器功能周围的 Xt 包装器顺利处理).因此,基本上您将能够在用户、应用程序和系统范围的资源文件中以及通过命令行定义参数.

#define XtNnamedPipe "namedPipe";#define XtCNamedPipe "NamedPipe";类型定义结构{字符串named_pipe;} 应用程序数据;AppData app_data;静态 XtResource 资源 [] = {{XtNnamedPipe,XtCNamedPipe,XtRString,大小(字符串),XtOffsetOf(AppData,named_pipe),XtRString,空值},};静态 XrmOptionDescRec 选项 [] = {{-namedpipe"、namedPipe"、XrmoptionSepArg、/tmp/namedpipe0"}、};...int main(int argc, char *argv[]) {...顶层 = XtVaOpenApplication(&app, argv[0], options, XtNumber(options), &argc, argv, NULL, sessionShellWidgetClass,XmNwidth, 400, XmNheight, 300, NULL);.../* 获取应用资源 */XtGetApplicationResources(顶层,&app_data,资源,XtNumber(资源),空值,0);printf("调试:%s\n",app_data.named_pipe);...}

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;

}

解决方案

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);       

    ...
}

这篇关于您可以使用 struct XrmOptionDescRec 数组将非 Motif 相关参数传递给应用程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆