mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Antony Pavlov <antonynpavlov@gmail.com>
To: barebox@lists.infradead.org
Subject: [RFC 1/3] readline: move backspace key handling to the DO_BACKSPACE macro
Date: Fri, 26 Oct 2012 09:58:53 +0400	[thread overview]
Message-ID: <1351231135-17324-2-git-send-email-antonynpavlov@gmail.com> (raw)
In-Reply-To: <1351231135-17324-1-git-send-email-antonynpavlov@gmail.com>

Signed-off-by: Antony Pavlov <antonynpavlov@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


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2012-10-26  5:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-26  5:58 [RFC 0/3] readline: add ctrl-w handling (cut-the-last-word) Antony Pavlov
2012-10-26  5:58 ` Antony Pavlov [this message]
2012-10-26  5:58 ` [RFC 2/3] " Antony Pavlov
2012-10-26  5:58 ` [RFC 3/3] readline: fix the 'new blank line at EOF' typo Antony Pavlov
2012-10-27 12:24 ` [RFC 0/3] readline: add ctrl-w handling (cut-the-last-word) Sascha Hauer
2012-10-28 15:11   ` Antony Pavlov
2012-10-29  9:02     ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1351231135-17324-2-git-send-email-antonynpavlov@gmail.com \
    --to=antonynpavlov@gmail.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox