cli: Add a function to set up a new cread
Create a init function so that it is easy to use command-line reading. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -424,28 +424,34 @@ int cread_line_process_ch(struct cli_line_state *cls, char ichar)
|
||||
return -EAGAIN;
|
||||
}
|
||||
|
||||
void cli_cread_init(struct cli_line_state *cls, char *buf, uint buf_size)
|
||||
{
|
||||
int init_len = strlen(buf);
|
||||
|
||||
memset(cls, '\0', sizeof(struct cli_line_state));
|
||||
cls->insert = true;
|
||||
cls->buf = buf;
|
||||
cls->len = buf_size;
|
||||
|
||||
if (init_len)
|
||||
cread_add_str(buf, init_len, 0, &cls->num, &cls->eol_num, buf,
|
||||
buf_size);
|
||||
}
|
||||
|
||||
static int cread_line(const char *const prompt, char *buf, unsigned int *len,
|
||||
int timeout)
|
||||
{
|
||||
struct cli_ch_state s_cch, *cch = &s_cch;
|
||||
struct cli_line_state s_cls, *cls = &s_cls;
|
||||
char ichar;
|
||||
int init_len = strlen(buf);
|
||||
int first = 1;
|
||||
|
||||
cli_ch_init(cch);
|
||||
memset(cls, '\0', sizeof(struct cli_line_state));
|
||||
cls->insert = true;
|
||||
cls->len = *len;
|
||||
cli_cread_init(cls, buf, *len);
|
||||
cls->prompt = prompt;
|
||||
cls->buf = buf;
|
||||
cls->history = true;
|
||||
cls->cmd_complete = true;
|
||||
|
||||
if (init_len)
|
||||
cread_add_str(buf, init_len, 1, &cls->num, &cls->eol_num, buf,
|
||||
*len);
|
||||
|
||||
while (1) {
|
||||
int ret;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user