[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH 2/2] vi: fix reading of file after last line
From:       Ron Yorston <rmy () tigress ! co ! uk>
Date:       2014-11-30 20:39:53
Message-ID: 201411302039.sAUKdsqf026231 () helium ! internal ! tigress ! co ! uk
[Download RAW message or body]

If the :r command is used to read a file after the last line of the
buffer the last line of the buffer and the first line of the file
are joined.  An extra blank line appears at the end of the buffer.

   file 1
   file 1
   file 1file 2
   file 2
   file 2

	~
	~

The insertion point is normally at the start of the line following the
specified line.  When the specified line is the last one the next_line
function baulks at moving to the non-existent following line.

Signed-off-by: Ron Yorston <rmy@tigress.co.uk>
---
 editors/vi.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/editors/vi.c b/editors/vi.c
index 7b88e8e..77535be 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -1318,8 +1318,12 @@ static void colon(char *buf)
 			q = begin_line(dot);	// assume "dot"
 		}
 		// read after current line- unless user said ":0r foo"
-		if (b != 0)
+		if (b != 0) {
 			q = next_line(q);
+			// read after last line
+			if (q == end-1)
+				++q;
+		}
 		{ // dance around potentially-reallocated text[]
 			uintptr_t ofs = q - text;
 			size = file_insert(fn, q, 0);
-- 
1.9.3

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic