diff options
author | Simon Glass | 2023-10-01 19:13:17 -0600 |
---|---|---|
committer | Tom Rini | 2023-10-11 15:43:54 -0400 |
commit | 39ee32166f607d4e30a74d46f82adb39e4134ec4 (patch) | |
tree | d1540a98ede7f11262f6f82054d080299437e182 /common | |
parent | 3b487bf51115bfb9a0f85667a5608fc57788107c (diff) |
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>
Diffstat (limited to 'common')
-rw-r--r-- | common/cli_readline.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/common/cli_readline.c b/common/cli_readline.c index 23913a857a9..06b8d465044 100644 --- a/common/cli_readline.c +++ b/common/cli_readline.c @@ -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; |