[RFC 1/3] readline: move backspace key handling to the DO_BACKSPACE macro

Antony Pavlov antonynpavlov at gmail.com
Fri Oct 26 01:58:53 EDT 2012


Signed-off-by: Antony Pavlov <antonynpavlov at gmail.com>
---
 lib/readline.c |   23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)

diff --git a/lib/readline.c b/lib/readline.c
index 5717a17..086b7f1 100644
--- a/lib/readline.c
+++ b/lib/readline.c
@@ -137,6 +137,18 @@ static char* hist_next(void)
 	}					\
 }
 
+#define DO_BACKSPACE()						\
+		wlen = eol_num - num;				\
+		num--;						\
+		memmove(buf + num, buf + num + 1, wlen);	\
+		getcmd_putch(CTL_BACKSPACE);			\
+		putnstr(buf + num, wlen);			\
+		getcmd_putch(' ');				\
+		do {						\
+			getcmd_putch(CTL_BACKSPACE);		\
+		} while (wlen--);				\
+		eol_num--;
+
 static void cread_add_char(char ichar, int insert, unsigned long *num,
 	       unsigned long *eol_num, char *buf, unsigned long len)
 {
@@ -273,16 +285,7 @@ int readline(const char *prompt, char *buf, int len)
 		case KEY_DEL7:
 		case 8:
 			if (num) {
-				wlen = eol_num - num;
-				num--;
-				memmove(buf + num, buf + num + 1, wlen);
-				getcmd_putch(CTL_BACKSPACE);
-				putnstr(buf + num, wlen);
-				getcmd_putch(' ');
-				do {
-					getcmd_putch(CTL_BACKSPACE);
-				} while (wlen--);
-				eol_num--;
+				DO_BACKSPACE();
 			}
 			break;
 		case KEY_DEL:
-- 
1.7.10.4




More information about the barebox mailing list