u-boot readline是模仿GNU中的Readline库编写的,实现的功能也类似:provides a set of functions for use by applications that allow users to edit command lines as they are typed in. Both Emacs and vi editing modes are available. It includes additional functions to maintain a list of previously-entered command lines, to recall and perhaps reedit those lines, and perform csh-like history expansion on previous commands.
/*
* Prompt for input and read a line.
* Return: number of read characters
* -1 if break
* -2 if timed out
*/
int readline (const char *const prompt)
{
char *p = console_buffer;
unsigned int len=MAX_CMDBUF_SIZE;
int rc;
static int initted = 0;
if (!initted) {
hist_init();
initted = 1;
}
puts (prompt);
rc = cread_line(p, &len);
return rc < 0 ? rc : len;
}
现在的关键就是cread_line这个函数了。
本文介绍了U-Boot中的Readline模块,该模块模仿GNU Readline库,为用户提供命令行编辑功能,支持Emacs和vi两种编辑模式,并提供历史命令记录和回溯等功能。文章重点解析了关键函数cread_line。
962

被折叠的 条评论
为什么被折叠?



