From mboxrd@z Thu Jan 1 00:00:00 1970 From: Pantelis Antoniou Date: Sun, 03 Dec 2006 00:15:50 +0200 Subject: [U-Boot-Users] [PATCH 1/8] Make autocomplete work with HUSH parser too. Message-ID: <20061202221550.652.71435.stgit@pantathon.hol.gr> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Auto complete did not work when the HUSH parser was selected. Fix this obvious problem. --- Signed-off-by: Pantelis Antoniou --- README | 4 ---- common/main.c | 25 +++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/README b/README index ecfd1f8..e28f935 100644 --- a/README +++ b/README @@ -1511,10 +1511,6 @@ The following options need to be configured: Enable auto completion of commands using TAB. - Note that this feature has NOT been implemented yet - for the "hush" shell. - - CFG_HUSH_PARSER Define this variable to enable the "hush" shell (from diff --git a/common/main.c b/common/main.c index cc4b50f..a8ae07c 100644 --- a/common/main.c +++ b/common/main.c @@ -718,10 +718,11 @@ static void cread_add_str(char *str, int strsize, int insert, unsigned long *num } } -static int cread_line(char *buf, unsigned int *len) +static int cread_line(const char *const prompt, char *buf, unsigned int *len) { unsigned long num = 0; unsigned long eol_num = 0; + int num2, col; unsigned long rlen; unsigned long wlen; char ichar; @@ -840,6 +841,7 @@ static int cread_line(char *buf, unsigned int *len) insert = !insert; break; case CTL_CH('x'): + case CTL_CH('u'): /* like that too */ BEGINNING_OF_LINE(); ERASE_TO_EOL(); break; @@ -889,6 +891,25 @@ static int cread_line(char *buf, unsigned int *len) REFRESH_TO_EOL(); continue; } +#ifdef CONFIG_AUTO_COMPLETE + case '\t': + + /* do not autocomplete when in the middle */ + if (num < eol_num) { + getcmd_cbeep(); + break; + } + + buf[num] = '\0'; + col = strlen(prompt) + eol_num; + num2 = num; + if (cmd_auto_complete(prompt, buf, &num2, &col)) { + col = num2 - num; + num += col; + eol_num += col; + } + break; +#endif default: cread_add_char(ichar, insert, &num, &eol_num, buf, *len); break; @@ -931,7 +952,7 @@ int readline (const char *const prompt) puts (prompt); - rc = cread_line(p, &len); + rc = cread_line(prompt, p, &len); return rc < 0 ? rc : len; #else char *p = console_buffer;