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这个函数了。