Commit cf9c34ac authored by David Lawrence Ramsey's avatar David Lawrence Ramsey
Browse files

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