【发布时间】:2011-08-30 00:57:40
【问题描述】:
我一直在尝试让标签完成工作。我很困惑,不知道该怎么做。能否请您看一下我的代码并告诉我如何修复它。
顺便说一句,我使用rl_attempted_completion_function,因为我是从在线教程中获得的,但它是一个 C++ 函数。我可以使用什么函数来替换它而不进行更改。
谢谢
static char** completion( const char * text , int start, int end){
char **matches;
matches = (char **)NULL;
if (start == 0)
matches = rl_completion_matches ((char*)text, &generator);
return (matches);
}
char* generator(const char* text, int state) {
int index, len;
char *comm;
if (!state) {
index = 0;
len = (int)strlen (text);
}
while ( (*comm = newEnv[index])) {
index++;
if (strncmp (comm, text, len) == 0)
return ((comm));
}
return NULL;
}
int main (int argc, char * argv[]) {
using_history();
rl_readline_name = basename(argv[0]);
rl_attempted_completion_function = completion;
while ( readline(">> ")!= NULL )
rl_bind_key('\t',rl_complete);
return 0;
}
【问题讨论】:
-
让选项卡完成在什么情况下工作?一个外壳、一个编辑器,还是别的什么?
-
您是否为此使用了一些库?请告诉它是哪一个,否则任何人都很难帮助你。
-
“
rl_attempted_completion_function”明确表示 Readline,例如GNU readline 库。 -
atm 按下制表符时出现分段错误
标签: c tabs readline libreadline