[U-Boot-Users] [PATCH 1/5] Make autocomplete work with HUSH parser too.

Pantelis Antoniou pantelis at embeddedalley.com
Wed Nov 29 18:25:27 CET 2006


CHANGELOG entry:

    Auto complete did not work when the HUSH parser was selected.
    Fix this obvious problem.

---
Signed-off-by: Pantelis Antoniou <pantelis at embeddedalley.com>
---

 README        |    4 ----
 common/main.c |   25 +++++++++++++++++++++++--
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/README b/README
index f78bf50..0aab04c 100644
--- a/README
+++ b/README
@@ -1470,10 +1470,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;




More information about the U-Boot mailing list