[U-Boot-Users] command compleation in latest u-boot?

Mike Frysinger vapier at gentoo.org
Tue Dec 18 05:19:54 CET 2007


On Wednesday 28 November 2007, Stefan Roese wrote:
> On Wednesday 28 November 2007, Joakim Tjernlund wrote:
> > > IIRC, then you have to choose to enable either command completion
> > > (CONFIG_AUTO_COMPLETE) or command history (CONFIG_CMDLINE_EDITING).
> > > Command history is my choice here.
> >
> > Ahh, I can only use one. In my old boot I can use both because I applied
> > a patch from Pantelis that I thought was in uboot already. Can you
> > have a look at Pantelis patch an apply if appropriate?
>
> Yes, would be good if both is possible. Could you do me a favor and redo
> this patch against the current source code. Also it seems that this will
> trigger some compile warning for unused variables "num2, col" when
> CONFIG_AUTO_COMPLETE is not defined. Please check and resend a fixed
> version and I'll make sure that it gets applied when the next merge window
> opens.

the patch posted still applies cleanly (ignoring offsets and the crappy word
wrapping).  for sake of completeness, ive attached patch against current
mainline git after giving it a spin against a recent version.
-mike

diff --git a/common/main.c b/common/main.c
index 379695c..4253eac 100644
--- a/common/main.c
+++ b/common/main.c
@@ -696,7 +696,7 @@ 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;
@@ -818,6 +818,7 @@ static int cread_line(char *buf, unsigned int *len)
 			insert = !insert;
 			break;
 		case CTL_CH('x'):
+		case CTL_CH('u'):
 			BEGINNING_OF_LINE();
 			ERASE_TO_EOL();
 			break;
@@ -867,6 +868,27 @@ static int cread_line(char *buf, unsigned int *len)
 			REFRESH_TO_EOL();
 			continue;
 		}
+#ifdef CONFIG_AUTO_COMPLETE
+		case '\t': {
+			int num2, col;
+
+			/* 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;
@@ -909,7 +931,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