svn commit: trunk/busybox/libbb

vda at busybox.net vda at busybox.net
Sun May 25 21:52:04 UTC 2008


Author: vda
Date: 2008-05-25 14:52:03 -0700 (Sun, 25 May 2008)
New Revision: 22077

Log:
lineedit: correctly handle prompt longer than screen width. closes bug 3414



Modified:
   trunk/busybox/libbb/lineedit.c


Changeset:
Modified: trunk/busybox/libbb/lineedit.c
===================================================================
--- trunk/busybox/libbb/lineedit.c	2008-05-25 21:50:55 UTC (rev 22076)
+++ trunk/busybox/libbb/lineedit.c	2008-05-25 21:52:03 UTC (rev 22077)
@@ -80,11 +80,10 @@
 	volatile unsigned cmdedit_termw; /* = 80; */ /* actual terminal width */
 	sighandler_t previous_SIGWINCH_handler;
 
+	unsigned cmdedit_x;        /* real x terminal position */
+	unsigned cmdedit_y;        /* pseudoreal y terminal position */
+	unsigned cmdedit_prmt_len; /* length of prompt (without colors etc) */
 
-	int cmdedit_x;           /* real x terminal position */
-	int cmdedit_y;           /* pseudoreal y terminal position */
-	int cmdedit_prmt_len;    /* length of prompt (without colors etc) */
-
 	unsigned cursor;
 	unsigned command_len;
 	char *command_ps;
@@ -199,7 +198,7 @@
 	{
 		bb_putchar(c);
 	}
-	if (++cmdedit_x >= (int)cmdedit_termw) {
+	if (++cmdedit_x >= cmdedit_termw) {
 		/* terminal is scrolled down */
 		cmdedit_y++;
 		cmdedit_x = 0;
@@ -262,12 +261,12 @@
 		return;
 	cursor -= num;
 
-	if ((unsigned)cmdedit_x >= num) {
+	if (cmdedit_x >= num) {
 		cmdedit_x -= num;
 		if (num <= 4) {
 			/* This is longer by 5 bytes on x86.
-			 * Also gets mysteriously
-			 * miscompiled for some ARM users.
+			 * Also gets miscompiled for ARM users
+			 * (busybox.net/bugs/view.php?id=2274).
 			 * printf(("\b\b\b\b" + 4) - num);
 			 * return;
 			 */
@@ -282,9 +281,12 @@
 
 	/* Need to go one or more lines up */
 	num -= cmdedit_x;
-	count_y = 1 + (num / cmdedit_termw);
-	cmdedit_y -= count_y;
-	cmdedit_x = cmdedit_termw * count_y - num;
+	{
+		unsigned w = cmdedit_termw; /* volatile var */
+		count_y = 1 + (num / w);
+		cmdedit_y -= count_y;
+		cmdedit_x = w * count_y - num;
+	}
 	/* go to 1st column; go up; go to correct column */
 	printf("\r" "\033[%dA" "\033[%dC", count_y, cmdedit_x);
 }
@@ -292,10 +294,12 @@
 static void put_prompt(void)
 {
 	out1str(cmdedit_prompt);
-	cmdedit_x = cmdedit_prmt_len;
 	cursor = 0;
-// Huh? what if cmdedit_prmt_len >= width?
-	cmdedit_y = 0;                  /* new quasireal y */
+	{
+		unsigned w = cmdedit_termw; /* volatile var */
+		cmdedit_y = cmdedit_prmt_len / w; /* new quasireal y */
+		cmdedit_x = cmdedit_prmt_len % w;
+	}
 }
 
 /* draw prompt, editor line, and clear tail */




More information about the busybox-cvs mailing list