From e99223dd256bfb3f66416cbab8164bae398c11df Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Thu, 10 Nov 2005 04:27:30 +0000
Subject: [PATCH] tweak do_wrap(), remove_magicline(), edit_scroll(), and
 edit_update() to rely on fileage and filebot instead of NULL for their checks
 to detect the top or bottom of the file

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3143 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog   | 3 ++-
 src/text.c  | 2 +-
 src/utils.c | 2 +-
 src/winio.c | 6 +++---
 4 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index e9e24933..d0fdaa2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -49,7 +49,8 @@ CVS code -
 	  do_page_down(), do_para_end(), do_next_word(), do_prev_word(),
 	  do_up(), do_down(), do_scroll_down(), do_right(), do_mouse(),
 	  do_gotolinecolumn(), do_delete(), begpar(), find_paragraph(),
-	  and do_justify(). (DLR)
+	  do_justify(), do_wrap(), remove_magicline(), edit_scroll(),
+	  and edit_update(). (DLR)
 	- Add new -L/--nonewlines command line option, and new
 	  "nonewlines" rcfile option, to control whether nano adds
 	  magiclines to the ends of files.  Changes to read_file(),
diff --git a/src/text.c b/src/text.c
index a2623155..e23f5548 100644
--- a/src/text.c
+++ b/src/text.c
@@ -432,7 +432,7 @@ bool do_wrap(filestruct *line)
     /* We prepend the wrapped text to the next line, if the
      * same_line_wrap flag is set, there is a next line, and prepending
      * would not make the line too long. */
-    if (same_line_wrap && line->next != NULL) {
+    if (same_line_wrap && line != openfile->filebot) {
 	const char *end = after_break + move_mbleft(after_break,
 		after_break_len);
 
diff --git a/src/utils.c b/src/utils.c
index 95cbdfa0..71949849 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -494,7 +494,7 @@ void new_magicline(void)
 void remove_magicline(void)
 {
     if (openfile->filebot->data[0] == '\0' &&
-	openfile->filebot->prev != NULL) {
+	openfile->filebot != openfile->fileage) {
 	openfile->filebot = openfile->filebot->prev;
 	free_filestruct(openfile->filebot->next);
 	openfile->filebot->next = NULL;
diff --git a/src/winio.c b/src/winio.c
index 4b7c9f9f..f7de0578 100644
--- a/src/winio.c
+++ b/src/winio.c
@@ -2634,11 +2634,11 @@ void edit_scroll(scroll_dir direction, ssize_t nlines)
      * there are fewer than nlines lines available. */
     for (i = nlines; i > 0; i--) {
 	if (direction == UP) {
-	    if (openfile->edittop->prev == NULL)
+	    if (openfile->edittop == openfile->fileage)
 		break;
 	    openfile->edittop = openfile->edittop->prev;
 	} else {
-	    if (openfile->edittop->next == NULL)
+	    if (openfile->edittop == openfile->filebot)
 		break;
 	    openfile->edittop = openfile->edittop->next;
 	}
@@ -2842,7 +2842,7 @@ void edit_update(update_type location)
 	    goal = editwinrows - 1;
     }
 
-    for (; goal > 0 && foo->prev != NULL; goal--)
+    for (; goal > 0 && foo != openfile->edittop; goal--)
 	foo = foo->prev;
 
     openfile->edittop = foo;
-- 
GitLab