使用 gperf 时遇到问题:不允许输入空关键字
command_options.gperf:
%{
#include "command_options.h"
typedef struct CommandOptionCode CommandOptionCode;
%}
struct CommandOption
{
const char *Option;
int OptionCode;
};
%%
+helpverbose, CommandOptionCode::HELPVERBOSE
+password, CommandOptionCode::PASSWORD
+nocopyright, CommandOptionCode::NOCOPYRIGHT
+nolog, CommandOptionCode::NOLOG
+_64bit, CommandOptionCode::_64BIT
command_options.h:
#ifndef __COMMANDOPTIONS_H
#define __COMMANDOPTIONS_H
struct CommandOptionCode
{
enum
{
HELPVERBOSE = 1,
PASSWORD = 2,
NOCOPYRIGHT = 3,
NOLOG = 4,
_64BIT = 5
};
};
#endif
当我运行时:
gperf -L C++ -t --output-file=perfecthash.hpp command_options.gperf
仅获取:
不允许输入空关键字。到 识别空输入关键字,您的 代码应该在之前检查 len == 0 调用 gperf 生成的查找 功能。
版本:GNU gperf 3.0.1 为什么?
command_options.gperf:
%{
#include "command_options.h"
typedef struct CommandOptionCode CommandOptionCode;
%}
struct CommandOption
{
const char *Option;
int OptionCode;
};
%%
+helpverbose, CommandOptionCode::HELPVERBOSE
+password, CommandOptionCode::PASSWORD
+nocopyright, CommandOptionCode::NOCOPYRIGHT
+nolog, CommandOptionCode::NOLOG
+_64bit, CommandOptionCode::_64BIT
command_options.h:
#ifndef __COMMANDOPTIONS_H
#define __COMMANDOPTIONS_H
struct CommandOptionCode
{
enum
{
HELPVERBOSE = 1,
PASSWORD = 2,
NOCOPYRIGHT = 3,
NOLOG = 4,
_64BIT = 5
};
};
#endif
When I run:
gperf -L C++ -t --output-file=perfecthash.hpp command_options.gperf
Only to get :
Empty input keyword is not allowed. To
recognize an empty input keyword, your
code should check for len == 0 before
calling the gperf generated lookup
function.
Version: GNU gperf 3.0.1
Why?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我发现 gperf 2.7 不关心第一部分和关键字之间是否有“%%”分隔符。 3.0.1 严格执行这一点。因此,就我而言,我进行了修改:
我相信,您的情况有所
不同,因为手册规定结构的第一个字段必须称为“名称”:
-charlie
I discovered that gperf 2.7 did not care if there was a '%%' delimiter between the first section and the keywords. 3.0.1 strictly enforces this. So, in my case I had modify:
to be
Your case is different, I belive, in that the manual states that the first field of the struct must be called 'name':
-charlie
我发现 gperf 不喜欢关键字部分中的空行。我猜它将空行视为空字符串,因为它不是注释,并抱怨它是“空”并且 len=0。由于我有总是以空行结束文件的习惯(有一些汇编器和编译器不愿意没有空行),所以它总是会成为一个问题!
I discovered that gperf does not like empty lines in the keyword section. It treats a blank line as a null string I guess, since it is not a comment, and complains about it being 'empty' and having len=0. Since I have a habit of always ending a file with an empty line (there are some assemblers and compilers that baulk at not having it) it was always going to be a problem!
除了 Richard 提到的空行问题之外,gperf 也不喜欢某些标记前面的空格。 (我剪切并粘贴了一个简单的 gperf 示例,该示例在用户输入中查找“粗鲁”单词。示例的名称是 rude-1.gperf。该示例有一些缩进,引发了同样的错误。)
In addition to the blank line issue mentioned by Richard, gperf also does not like spaces preceding certain tokens. (I had cut and pasted a simple gperf sample that looked for "rude" words in a user's input. The name of the sample was rude-1.gperf. The sample had some indentation that triggered this same error.)