From e5e88fd9f26f59d0ae95ace84f211b01a3e1aa80 Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Sun, 31 Oct 2004 13:20:30 +0000
Subject: [PATCH] fix problem found by Rocco: make search_last_line static to
 search.c instead of local to findnextstr() so that search wrapping detection
 works properly again

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@2037 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog    | 12 ++++++------
 src/nano.c   |  1 +
 src/proto.h  |  1 +
 src/search.c | 13 +++++++++++--
 4 files changed, 19 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index c3c75d9a..a05622bf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -80,12 +80,12 @@ CVS code -
 	- Add support for reading in UTF-8 sequences to the low-level
 	  input routines.  Changes to get_kbinput() and
 	  get_translated_kbinput(). (DLR)
-	- Reduce search_last_line to a local variable in findnextstr(),
-	  since it's always set to FALSE just before and after
-	  findnextstr() is called and isn't used anywhere except in
-	  findnextstr().  Changes to do_int_spell_fix(), findnextstr(),
-	  do_search(), do_research(), do_replace(), and
-	  do_find_bracket(). (DLR)
+	- Reduce search_last_line to a static variable in search.c, and
+	  allow it to be set to FALSE via a function.  New function
+	  findnextstr_wrap_reset(); changes to do_int_spell_fix(),
+	  findnextstr(), do_search(), do_research(), do_replace_loop(),
+	  do_replace(), and do_find_bracket(). (DLR, problem with making
+	  search_last_line local to findnextstr() found by Rocco)
 	- When saving or changing file positions, be sure not to ignore
 	  placewewant.  Changes to do_int_spell_fix(), findnextstr(),
 	  do_replace_loop(), and do_replace(). (DLR)
diff --git a/src/nano.c b/src/nano.c
index 31e558a0..da9c192d 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1471,6 +1471,7 @@ bool do_int_spell_fix(const char *word)
     placewewant = 0;
 
     /* Find the first whole-word occurrence of word. */
+    findnextstr_wrap_reset();
     while (findnextstr(TRUE, TRUE, FALSE, fileage, 0, word, NULL)) {
 	if (is_whole_word(current_x, current->data, word)) {
 	    edit_refresh();
diff --git a/src/proto.h b/src/proto.h
index b290673a..bf8a7e19 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -408,6 +408,7 @@ bool is_whole_word(int curr_pos, const char *datastr, const char
 bool findnextstr(bool can_display_wrap, bool wholeword, bool
 	no_sameline, const filestruct *begin, size_t beginx, const char
 	*needle, size_t *needle_len);
+void findnextstr_wrap_reset(void);
 void do_search(void);
 #ifndef NANO_SMALL
 void do_research(void);
diff --git a/src/search.c b/src/search.c
index 6e8d268e..7cea9f2b 100644
--- a/src/search.c
+++ b/src/search.c
@@ -31,6 +31,8 @@
 #include "proto.h"
 #include "nano.h"
 
+static bool search_last_line = FALSE;
+	/* Have we gone past the last line while searching? */
 #ifdef HAVE_REGEX_H
 static bool regexp_compiled = FALSE;
 	/* Have we compiled any regular expressions? */
@@ -281,8 +283,6 @@ bool findnextstr(bool can_display_wrap, bool wholeword, bool
     size_t current_x_find = 0;
 	/* The location of the match we found. */
     int current_y_find = current_y;
-    bool search_last_line = FALSE;
-	/* Have we gone past the last line while searching? */
 
     /* rev_start might end up 1 character before the start or after the
      * end of the line.  This won't be a problem because strstrwrapper()
@@ -415,6 +415,11 @@ bool findnextstr(bool can_display_wrap, bool wholeword, bool
     return TRUE;
 }
 
+void findnextstr_wrap_reset(void)
+{
+    search_last_line = FALSE;
+}
+
 /* Search for a string. */
 void do_search(void)
 {
@@ -455,6 +460,7 @@ void do_search(void)
 	update_history(&search_history, answer);
 #endif
 
+    findnextstr_wrap_reset();
     didfind = findnextstr(TRUE, FALSE, FALSE, current, current_x,
 	answer, NULL);
 
@@ -508,6 +514,7 @@ void do_research(void)
 	    return;
 #endif
 
+	findnextstr_wrap_reset();
 	didfind = findnextstr(TRUE, FALSE, FALSE, current, current_x,
 		last_search, NULL);
 
@@ -672,6 +679,7 @@ ssize_t do_replace_loop(const char *needle, filestruct *real_current,
     if (canceled != NULL)
 	*canceled = FALSE;
 
+    findnextstr_wrap_reset();
     while (findnextstr(TRUE, wholewords,
 #ifdef HAVE_REGEX_H
 	/* We should find a bol and/or eol regex only once per line.  If
@@ -1030,6 +1038,7 @@ void do_find_bracket(void)
     /* We constructed regexp_pat to be a valid expression. */
     assert(regexp_compiled);
 
+    findnextstr_wrap_reset();
     while (TRUE) {
 	if (findnextstr(FALSE, FALSE, FALSE, current, current_x,
 		regexp_pat, NULL)) {
-- 
GitLab