Index: search.c =================================================================== RCS file: /cvsroot/nano/nano/search.c,v retrieving revision 1.80 diff -u -r1.80 search.c --- search.c 21 Jan 2002 20:40:14 -0000 1.80 +++ search.c 13 Feb 2002 19:46:59 -0000 @@ -240,15 +240,19 @@ return FALSE; } -int past_editbuff; /* search is now looking through lines not displayed */ +int past_editbuff; /* findnextstr() is now searching lines not displayed */ filestruct *findnextstr(int quiet, int bracket_mode, filestruct * begin, int beginx, char *needle) { filestruct *fileptr; char *searchstr, *rev_start = NULL, *found = NULL; +#if 0 int current_x_find = 0; - +#else + /* no need for initializer */ + int current_x_find; +#endif fileptr = current; past_editbuff = 0; @@ -316,13 +320,13 @@ else { /* reverse search */ current_x_find = current_x - 1; - +#if 0 /* Are we now back to the place where the search started) */ if ((fileptr == begin) && (current_x_find > beginx)) search_last_line = 1; - +#endif /* Make sure we haven't passed the begining of the string */ -#if 1 /* Is this required here ? */ +#if 0 /* Is this required here ? */ if (!(&fileptr->data[current_x_find] - fileptr->data)) current_x_find++; #endif @@ -597,7 +601,12 @@ int wholewords, int *i) { int replaceall = 0, numreplaced = 0; + +#if 0 filestruct *fileptr; +#else + filestruct *fileptr = 0; +#endif char *copy; switch (*i) { @@ -625,7 +634,14 @@ while (1) { /* Sweet optimization by Rocco here */ +#if 0 fileptr = findnextstr(replaceall, FALSE, begin, *beginx, prevanswer); +#else + if (fileptr != 0) + fileptr = findnextstr(1, FALSE, begin, *beginx, prevanswer); + else + fileptr = findnextstr(replaceall || (search_last_line ? 1 : 0), FALSE, begin, *beginx, prevanswer); +#endif /* No more matches. Done! */ if (!fileptr) @@ -664,17 +680,29 @@ current->data = copy; totsize += strlen(current->data); - /* Stop bug where we replace a substring of the replacement text */ - current_x += strlen(last_replace) - 1; + if (!ISSET(REVERSE_SEARCH)) { + /* Stop bug where we replace a substring of the replacement text */ + current_x += strlen(last_replace) - 1; + + /* Adjust the original cursor position - COULD BE IMPROVED */ + if (search_last_line) { + *beginx += strlen(last_replace) - strlen(last_search); + + /* For strings that cross the search start/end boundary */ + /* Don't go outside of allocated memory */ + if (*beginx < 1) + *beginx = 1; + } + } else { + if (current_x > 1) + current_x--; - /* Adjust the original cursor position - COULD BE IMPROVED */ - if (search_last_line) { - *beginx += strlen(last_replace) - strlen(last_search); + if (search_last_line) { + *beginx += strlen(last_replace) - strlen(last_search); - /* For strings that cross the search start/end boundary */ - /* Don't go outside of allocated memory */ - if (*beginx < 1) - *beginx = 1; + if (*beginx > strlen(current->data)) + *beginx = strlen(current->data); + } } edit_refresh(); @@ -756,15 +784,23 @@ /* save where we are */ begin = current; +#if 0 + /* why + 1 ? isn't this taken care of in findnextstr() ? */ beginx = current_x + 1; - +#else + beginx = current_x; +#endif search_last_line = 0; numreplaced = do_replace_loop(prevanswer, begin, &beginx, FALSE, &i); /* restore where we were */ current = begin; +#if 0 current_x = beginx - 1; +#else + current_x = beginx; +#endif renumber_all(); edit_update(current, CENTER); print_replaced(numreplaced); Index: utils.c =================================================================== RCS file: /cvsroot/nano/nano/utils.c,v retrieving revision 1.34 diff -u -r1.34 utils.c --- utils.c 28 Jan 2002 15:56:15 -0000 1.34 +++ utils.c 13 Feb 2002 19:46:59 -0000 @@ -1,4 +1,4 @@ -/* $Id: utils.c,v 1.34 2002/01/28 15:56:15 astyanax Exp $ */ +/* $Id: utils.c,v 1.34 2002/01/27 23:09:32 astyanax Exp $ */ /************************************************************************** * utils.c * * * @@ -112,16 +112,15 @@ } else { char *i, *j; - /* do quick check first */ + /* do a quick search forward first */ if (!(regexec(&search_regexp, haystack, 10, regmatches, 0))) { - /* there is a match */ + /* there's a match somewhere in the line - now search for it backwards, much slower */ for(i = rev_start ; i >= haystack ; --i) if (!(result = regexec(&search_regexp, i, 10, regmatches, 0))) { j = i + regmatches[0].rm_so; if (j <= rev_start) return j; } - } #endif }