Cleaning up, improving comments, and renaming a variable.

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5761 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2016-03-23 10:19:01 +00:00
parent 8704dde873
commit 4b2751c3b9
3 changed files with 19 additions and 23 deletions

View File

@ -2,6 +2,7 @@
* src/search.c (findnextstr): Prevent the internal spell checker from * src/search.c (findnextstr): Prevent the internal spell checker from
finding the first occurrence twice. And delete the piece of dead code finding the first occurrence twice. And delete the piece of dead code
that was meant to do this. This fixes Savannah bug #47188. that was meant to do this. This fixes Savannah bug #47188.
* src/search.c (findnextstr): Clean up and rename a variable.
2016-03-22 Thomas Rosenau <thomasr@fantasymail.de> 2016-03-22 Thomas Rosenau <thomasr@fantasymail.de>
* configure.ac, src/*.c: Check for the existence of the REG_ENHANCED * configure.ac, src/*.c: Check for the existence of the REG_ENHANCED

View File

@ -588,7 +588,7 @@ bool findnextstr(
bool whole_word_only, bool whole_word_only,
#endif #endif
const filestruct *begin, size_t begin_x, const filestruct *begin, size_t begin_x,
const char *needle, size_t *needle_len); const char *needle, size_t *match_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

View File

@ -249,19 +249,17 @@ int search_init(bool replacing, bool use_answer)
/* Look for needle, starting at (current, current_x). begin is the line /* Look for needle, starting at (current, current_x). begin is the line
* 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 match_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 findnextstr(
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
bool whole_word_only, bool whole_word_only,
#endif #endif
const filestruct *begin, size_t begin_x, const filestruct *begin, size_t begin_x,
const char *needle, size_t *needle_len) const char *needle, size_t *match_len)
{ {
size_t found_len; size_t found_len;
/* The length of the match we find. */ /* The length of the match we find. */
size_t current_x_find = 0;
/* The location in the current line of the match we find. */
ssize_t current_y_find = openfile->current_y; ssize_t current_y_find = openfile->current_y;
filestruct *fileptr = openfile->current; filestruct *fileptr = openfile->current;
const char *rev_start = fileptr->data, *found = NULL; const char *rev_start = fileptr->data, *found = NULL;
@ -279,8 +277,9 @@ bool findnextstr(
#endif #endif
move_mbright(fileptr->data, openfile->current_x); move_mbright(fileptr->data, openfile->current_x);
/* Look for needle in the current line we're searching. */
enable_nodelay(); enable_nodelay();
/* Start searching through the lines, looking for the needle. */
while (TRUE) { while (TRUE) {
if (time(NULL) - lastkbcheck > 1) { if (time(NULL) - lastkbcheck > 1) {
int input = parse_kbinput(edit); int input = parse_kbinput(edit);
@ -293,9 +292,9 @@ bool findnextstr(
} }
} }
/* Search for the needle in the current line. */
found = strstrwrapper(fileptr->data, needle, rev_start); found = strstrwrapper(fileptr->data, needle, rev_start);
/* We've found a potential match. */
if (found != NULL) { if (found != NULL) {
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
bool found_whole = FALSE; bool found_whole = FALSE;
@ -308,8 +307,7 @@ bool findnextstr(
return FALSE; return FALSE;
} }
#endif #endif
/* Remember the length of the potential match. */
/* Set found_len to the length of the potential match. */
found_len = found_len =
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
ISSET(USE_REGEXP) ? ISSET(USE_REGEXP) ?
@ -318,14 +316,13 @@ bool findnextstr(
strlen(needle); strlen(needle);
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
/* If we're searching for whole words, see if this potential /* If we're searching for whole words, see if it is. */
* match is a whole word. */
if (whole_word_only) { if (whole_word_only) {
char *word = mallocstrncpy(NULL, found, found_len + 1); char *word = mallocstrncpy(NULL, found, found_len + 1);
word[found_len] = '\0'; word[found_len] = '\0';
found_whole = is_whole_word(found - fileptr->data, found_whole = is_whole_word(found - fileptr->data,
fileptr->data, word); fileptr->data, word);
free(word); free(word);
} }
@ -336,8 +333,8 @@ bool findnextstr(
break; break;
} }
/* If we're back at the beginning, then there is no needle. */
if (search_last_line) { if (search_last_line) {
/* We've finished processing the file, so get out. */
not_found_msg(needle); not_found_msg(needle);
disable_nodelay(); disable_nodelay();
return FALSE; return FALSE;
@ -355,8 +352,8 @@ bool findnextstr(
current_y_find++; current_y_find++;
} }
/* If we've reached the start or end of the buffer, wrap around. */
if (fileptr == NULL) { if (fileptr == NULL) {
/* We've reached the start or end of the buffer, so wrap around. */
#ifndef NANO_TINY #ifndef NANO_TINY
if (ISSET(BACKWARDS_SEARCH)) { if (ISSET(BACKWARDS_SEARCH)) {
fileptr = openfile->filebot; fileptr = openfile->filebot;
@ -370,10 +367,11 @@ bool findnextstr(
statusbar(_("Search Wrapped")); statusbar(_("Search Wrapped"));
} }
/* If we've reached the original starting line, take note. */
if (fileptr == begin) if (fileptr == begin)
/* We've reached the original starting line. */
search_last_line = TRUE; search_last_line = TRUE;
/* Set the starting x to the start or end of the line. */
rev_start = fileptr->data; rev_start = fileptr->data;
#ifndef NANO_TINY #ifndef NANO_TINY
if (ISSET(BACKWARDS_SEARCH)) if (ISSET(BACKWARDS_SEARCH))
@ -381,20 +379,17 @@ bool findnextstr(
#endif #endif
} }
/* We found an instance. */
current_x_find = found - fileptr->data;
disable_nodelay(); disable_nodelay();
/* We've definitely found something. */ /* Set the current position to point at what we found. */
openfile->current = fileptr; openfile->current = fileptr;
openfile->current_x = current_x_find; openfile->current_x = found - fileptr->data;
openfile->placewewant = xplustabs(); openfile->placewewant = xplustabs();
openfile->current_y = current_y_find; openfile->current_y = current_y_find;
/* needle_len holds the length of needle. */ /* When requested, pass back the length of the match. */
if (needle_len != NULL) if (match_len != NULL)
*needle_len = found_len; *match_len = found_len;
return TRUE; return TRUE;
} }