Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C GNU argp:仅接受带有长选项的可选参数_C_Gnu_Glibc_Argp - Fatal编程技术网

C GNU argp:仅接受带有长选项的可选参数

C GNU argp:仅接受带有长选项的可选参数,c,gnu,glibc,argp,C,Gnu,Glibc,Argp,我想接受一个选项的可选参数,该参数只有长格式 这是一种选择 假设我使用argp的可选参数定义选项-v,-verbose: static struct argp_option opt_global[] = { { "verbose", 'v' , "level", OPTION_ARG_OPTIONAL, "Increase or set the verbosity level.", -1}, ... } 现在,我只想在使用长

我想接受一个选项的可选参数,该参数只有长格式 这是一种选择

假设我使用argp的可选参数定义选项
-v
-verbose

static struct argp_option opt_global[] =
{
  { "verbose", 'v' , "level", OPTION_ARG_OPTIONAL,  "Increase or set the verbosity level.", -1},
  ...
}
现在,我只想在使用长选项表单时接受可选参数

所以

将接受
4
作为verbose的可选参数

但对于短选项形式,不应接受可选参数:

| Command Line |  Handled as       |
|==============|===================|
| -vv          | -v -v             |
| -vx          | -v -x             |
| -v4          | -v -4             |
假设我还有
-o file
来定义输出文件:

| Command Line |  Handled as       |
|==============|===================|
| -vo file     | -v -o file        |
| -vofile      | -v -o file        |
无论如何,我仍然希望帮助输出如下所示:

  -v, --verbose[=level]      Increase or set the verbosity level.
这对GNU argp可行吗

通过阅读文档和玩游戏,我会认为“不”,但也许我 错过了一些东西。

来自(重点是我的):

整数键

当前选项向选项分析器提供的整数键如果key的值是可打印的ASCII字符(即isascii(key)为true),它还指定一个短选项'-char',其中char是带有代码键的ASCII字符

换句话说,要设置没有缩写形式的选项,请使用非ascii字符的键

例如,在您的情况下,可能是:

/* This is not an ascii value so no short form */
#define OPT_VERBOSE_KEY 500

static struct argp_option opt_global[] =
{
  { "verbose", OPT_VERBOSE_KEY , "level", OPTION_ARG_OPTIONAL,  "Increase or set the verbosity level.", -1},
  ...
}
从(重点是我的):

整数键

当前选项向选项分析器提供的整数键如果key的值是可打印的ASCII字符(即isascii(key)为true),它还指定一个短选项'-char',其中char是带有代码键的ASCII字符

换句话说,要设置没有缩写形式的选项,请使用非ascii字符的键

例如,在您的情况下,可能是:

/* This is not an ascii value so no short form */
#define OPT_VERBOSE_KEY 500

static struct argp_option opt_global[] =
{
  { "verbose", OPT_VERBOSE_KEY , "level", OPTION_ARG_OPTIONAL,  "Increase or set the verbosity level.", -1},
  ...
}

这在GNU argp上可行吗?
这到底是什么?是否将
-vo
处理为
-v-o
?@KamilCuk我试图澄清。希望这更好。
这在GNU argp上可行吗?
这到底是什么?是否将
-vo
处理为
-v-o
?@KamilCuk我试图澄清。希望这样更好。然后我可以添加
{NULL,'v',NULL,0,“…”,-1}
,但是在
--help
输出中有两个条目,我希望避免。很抱歉,这个问题不清楚(已更新)。然后我可以添加
{NULL,'v',NULL,0,“…”,-1}
,但是在
--help
输出中我会有两个条目,这是我想要避免的。抱歉,此问题不清楚(已更新)。