From: Peter Tyser Date: Sun, 25 Oct 2009 20:12:54 +0000 (-0500) Subject: readline(): Add ability to modify a string buffer X-Git-Tag: v2009.11-rc1~3 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=ecc5500ee487170d8af6ff893fd1e0082380a01a;p=u-boot readline(): Add ability to modify a string buffer If the 'buf' parameter is a non-0-length string, its contents will be edited. Previously, the initial contents of 'buf' were ignored and the user entered its contents from scratch. This change is necessary to support the upcoming "editenv" command but could also be used for future commands which require a user to modify an existing string. Signed-off-by: Peter Tyser --- diff --git a/common/main.c b/common/main.c index b47e443f7b..10d8904170 100644 --- a/common/main.c +++ b/common/main.c @@ -720,6 +720,10 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len) int insert = 1; int esc_len = 0; char esc_save[8]; + int init_len = strlen(buf); + + if (init_len) + cread_add_str(buf, init_len, 1, &num, &eol_num, buf, *len); while (1) { #ifdef CONFIG_BOOT_RETRY_TIME @@ -937,6 +941,12 @@ static int cread_line(const char *const prompt, char *buf, unsigned int *len) */ int readline (const char *const prompt) { + /* + * If console_buffer isn't 0-length the user will be prompted to modify + * it instead of entering it from scratch as desired. + */ + console_buffer[0] = '\0'; + return readline_into_buffer(prompt, console_buffer); }