From cf9c34acefb318c4d6d9637ef2403a8003df62aa Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Wed, 16 Nov 2005 05:59:06 +0000
Subject: [PATCH] only include code related to whole word searches when
 DISABLE_SPELLER isn't defined, as only the internal spell checker uses it

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3190 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog    |  7 ++++++
 src/proto.h  | 19 +++++++++++----
 src/search.c | 69 +++++++++++++++++++++++++++++++++++++++-------------
 src/utils.c  |  2 ++
 4 files changed, 75 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 5cdd81c8..d5ba969e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -150,10 +150,14 @@ CVS code -
 	- Remove parameter can_display_wrap, as it's always set to TRUE
 	  now, and rename parameter wholeword to whole_word, for
 	  consistency. (DLR)
+	- Only include the whole_word parameter when DISABLE_SPELLER
+	  isn't defined, as it's only used then. (DLR)
   do_replace_loop()
 	- Change order of parameters to more closely match those of
 	  findnextstr(), and rename parameter wholewords to whole_word,
 	  for consistency. (DLR)
+	- Only include the whole_word parameter when DISABLE_SPELLER
+	  isn't defined, as it's only used then. (DLR)
 - text.c:
   begpar()
 	- Return FALSE if foo is NULL, as inpar() does. (DLR)
@@ -173,6 +177,9 @@ CVS code -
 	  the text of the spell-checked file into its own function,
 	  replace_buffer(). (DLR)
 - utils.c:
+  is_whole_word()
+	- Only include when DISABLE_SPELLER isn't defined, as it's only
+	  used then. (DLR)
   get_page_start()
 	- Fix test so that we scroll through the line in 8-character
 	  chunks when COLS is greater than 8, not when COLS is greater
diff --git a/src/proto.h b/src/proto.h
index 1fe58714..1db1af71 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -496,8 +496,12 @@ void not_found_msg(const char *str);
 void search_abort(void);
 void search_init_globals(void);
 int search_init(bool replacing, bool use_answer);
-bool findnextstr(bool whole_word, bool no_sameline, const filestruct
-	*begin, size_t begin_x, const char *needle, size_t *needle_len);
+bool findnextstr(
+#ifndef DISABLE_SPELLER
+	bool whole_word,
+#endif
+	bool no_sameline, const filestruct *begin, size_t begin_x, const
+	char *needle, size_t *needle_len);
 void findnextstr_wrap_reset(void);
 void do_search(void);
 #ifndef NANO_TINY
@@ -508,9 +512,12 @@ void replace_abort(void);
 int replace_regexp(char *string, bool create);
 #endif
 char *replace_line(const char *needle);
-ssize_t do_replace_loop(bool whole_word, bool *canceled, const
-	filestruct *real_current, size_t *real_current_x, const char
-	*needle);
+ssize_t do_replace_loop(
+#ifndef DISABLE_SPELLER
+	bool whole_word,
+#endif
+	bool *canceled, const filestruct *real_current, size_t
+	*real_current_x, const char *needle);
 void do_replace(void);
 void do_gotolinecolumn(ssize_t line, ssize_t column, bool use_answer,
 	bool interactive, bool save_pos, bool allow_update);
@@ -609,7 +616,9 @@ int safe_regexec(const regex_t *preg, const char *string, size_t nmatch,
 #endif
 int regexp_bol_or_eol(const regex_t *preg, const char *string);
 #endif
+#ifndef DISABLE_SPELLER
 bool is_whole_word(size_t pos, const char *buf, const char *word);
+#endif
 const char *strstrwrapper(const char *haystack, const char *needle,
 	const char *start);
 void nperror(const char *s);
diff --git a/src/search.c b/src/search.c
index 07c494ff..5fdc5767 100644
--- a/src/search.c
+++ b/src/search.c
@@ -259,8 +259,12 @@ int search_init(bool replacing, bool use_answer)
  * where we first started searching, at column begin_x.  The return
  * value specifies whether we found anything.  If we did, set needle_len
  * to the length of the string we found if it isn't NULL. */
-bool findnextstr(bool whole_word, bool no_sameline, const filestruct
-	*begin, size_t begin_x, const char *needle, size_t *needle_len)
+bool findnextstr(
+#ifndef DISABLE_SPELLER
+	bool whole_word,
+#endif
+	bool no_sameline, const filestruct *begin, size_t begin_x, const
+	char *needle, size_t *needle_len)
 {
     filestruct *fileptr = openfile->current;
     const char *rev_start = NULL, *found = NULL;
@@ -288,8 +292,10 @@ bool findnextstr(bool whole_word, bool no_sameline, const filestruct
 
 	/* We've found a potential match. */
 	if (found != NULL) {
+#ifndef DISABLE_SPELLER
 	    bool found_whole = FALSE;
 		/* Is this potential match a whole word? */
+#endif
 
 	    /* Set found_len to the length of the potential match. */
 	    found_len =
@@ -299,6 +305,7 @@ bool findnextstr(bool whole_word, bool no_sameline, const filestruct
 #endif
 		strlen(needle);
 
+#ifndef DISABLE_SPELLER
 	    /* If we're searching for whole words, see if this potential
 	     * match is a whole word. */
 	    if (whole_word) {
@@ -309,13 +316,17 @@ bool findnextstr(bool whole_word, bool no_sameline, const filestruct
 			fileptr->data, word);
 		free(word);
 	    }
+#endif
 
 	    /* If we're searching for whole words and this potential
 	     * match isn't a whole word, or if we're not allowed to find
 	     * a match on the same line we started on and this potential
 	     * match is on that line, continue searching. */
-	    if ((!whole_word || found_whole) && (!no_sameline ||
-		fileptr != openfile->current))
+	    if (
+#ifndef DISABLE_SPELLER
+		(!whole_word || found_whole) &&
+#endif
+		(!no_sameline || fileptr != openfile->current))
 		break;
 	}
 
@@ -441,8 +452,11 @@ void do_search(void)
 #endif
 
     findnextstr_wrap_reset();
-    didfind = findnextstr(FALSE, FALSE, openfile->current,
-	openfile->current_x, answer, NULL);
+    didfind = findnextstr(
+#ifndef DISABLE_SPELLER
+	FALSE,
+#endif
+	FALSE, openfile->current, openfile->current_x, answer, NULL);
 
     /* Check to see if there's only one occurrence of the string and
      * we're on it now. */
@@ -456,7 +470,11 @@ void do_search(void)
 	 * which case it's the only occurrence. */
 	if (ISSET(USE_REGEXP) && regexp_bol_or_eol(&search_regexp,
 		last_search)) {
-	    didfind = findnextstr(FALSE, TRUE, openfile->current,
+	    didfind = findnextstr(
+#ifndef DISABLE_SPELLER
+		FALSE,
+#endif
+		TRUE, openfile->current,
 		openfile->current_x, answer, NULL);
 	    if (fileptr == openfile->current && fileptr_x ==
 		openfile->current_x && !didfind)
@@ -497,8 +515,12 @@ void do_research(void)
 #endif
 
 	findnextstr_wrap_reset();
-	didfind = findnextstr(FALSE, FALSE, openfile->current,
-		openfile->current_x, last_search, NULL);
+	didfind = findnextstr(
+#ifndef DISABLE_SPELLER
+		FALSE,
+#endif
+		FALSE, openfile->current, openfile->current_x,
+		last_search, NULL);
 
 	/* Check to see if there's only one occurrence of the string and
 	 * we're on it now. */
@@ -512,8 +534,12 @@ void do_research(void)
 	     * found again, in which case it's the only occurrence. */
 	    if (ISSET(USE_REGEXP) && regexp_bol_or_eol(&search_regexp,
 		last_search)) {
-		didfind = findnextstr(FALSE, TRUE, openfile->current,
-			openfile->current_x, answer, NULL);
+		didfind = findnextstr(
+#ifndef DISABLE_SPELLER
+			FALSE,
+#endif
+			TRUE, openfile->current, openfile->current_x,
+			answer, NULL);
 		if (fileptr == openfile->current && fileptr_x ==
 			openfile->current_x && !didfind)
 		    statusbar(_("This is the only occurrence"));
@@ -639,9 +665,12 @@ char *replace_line(const char *needle)
  * needle is the string to seek.  We replace it with answer.  Return -1
  * if needle isn't found, else the number of replacements performed.  If
  * canceled isn't NULL, set it to TRUE if we canceled. */
-ssize_t do_replace_loop(bool whole_word, bool *canceled, const
-	filestruct *real_current, size_t *real_current_x, const char
-	*needle)
+ssize_t do_replace_loop(
+#ifndef DISABLE_SPELLER
+	bool whole_word,
+#endif
+	bool *canceled, const filestruct *real_current, size_t
+	*real_current_x, const char *needle)
 {
     ssize_t numreplaced = -1;
     size_t match_len;
@@ -675,7 +704,10 @@ ssize_t do_replace_loop(bool whole_word, bool *canceled, const
 	*canceled = FALSE;
 
     findnextstr_wrap_reset();
-    while (findnextstr(whole_word,
+    while (findnextstr(
+#ifndef DISABLE_SPELLER
+	whole_word,
+#endif
 #ifdef HAVE_REGEX_H
 	/* We should find a bol and/or eol regex only once per line.  If
 	 * the bol_or_eol flag is set, it means that the last search
@@ -912,8 +944,11 @@ void do_replace(void)
     begin_x = openfile->current_x;
     pww_save = openfile->placewewant;
 
-    numreplaced = do_replace_loop(FALSE, NULL, begin, &begin_x,
-	last_search);
+    numreplaced = do_replace_loop(
+#ifndef DISABLE_SPELLER
+	FALSE,
+#endif
+	NULL, begin, &begin_x, last_search);
 
     /* Restore where we were. */
     openfile->edittop = edittop_save;
diff --git a/src/utils.c b/src/utils.c
index fa7daba6..064d97b9 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -258,6 +258,7 @@ int regexp_bol_or_eol(const regex_t *preg, const char *string)
 }
 #endif /* HAVE_REGEX_H */
 
+#ifndef DISABLE_SPELLER
 /* Is the word starting at position pos in buf a whole word? */
 bool is_whole_word(size_t pos, const char *buf, const char *word)
 {
@@ -282,6 +283,7 @@ bool is_whole_word(size_t pos, const char *buf, const char *word)
 
     return retval;
 }
+#endif /* !DISABLE_SPELLER */
 
 /* If we are searching backwards, we will find the last match that
  * starts no later than start.  Otherwise we find the first match
-- 
GitLab