Removing the unintended special case for replacing

multiple occurrences of a literal ^ or $.


git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@5214 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
master
Benno Schulenberg 2015-04-25 14:52:58 +00:00
parent ca1983adb4
commit af708843f6
4 changed files with 7 additions and 50 deletions

View File

@ -1,3 +1,7 @@
2015-04-25 Benno Schulenberg <bensberg@justemail.net>
* src/search.c (do_replace_loop): Remove the unintended special
case for replacing multiple occurrences of a literal ^ or $.
2015-04-21 Benno Schulenberg <bensberg@justemail.net> 2015-04-21 Benno Schulenberg <bensberg@justemail.net>
* src/browser.c (findnextfile): Save the settings of the global * src/browser.c (findnextfile): Save the settings of the global
case-sens, direction, and regexp flags, and restore them on exit. case-sens, direction, and regexp flags, and restore them on exit.

View File

@ -712,7 +712,6 @@ ssize_t ngetdelim(char **lineptr, size_t *n, int delim, FILE *stream);
#endif #endif
#endif #endif
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
bool regexp_bol_or_eol(const regex_t *preg, const char *string);
const char *fixbounds(const char *r); const char *fixbounds(const char *r);
#endif #endif
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER

View File

@ -632,10 +632,6 @@ ssize_t do_replace_loop(
ssize_t numreplaced = -1; ssize_t numreplaced = -1;
size_t match_len; size_t match_len;
bool replaceall = FALSE; bool replaceall = FALSE;
#ifdef HAVE_REGEX_H
/* The starting-line match and bol/eol regex flags. */
bool begin_line = FALSE, bol_or_eol = FALSE;
#endif
#ifndef NANO_TINY #ifndef NANO_TINY
bool old_mark_set = openfile->mark_set; bool old_mark_set = openfile->mark_set;
filestruct *top, *bot; filestruct *top, *bot;
@ -669,16 +665,7 @@ ssize_t do_replace_loop(
#ifndef DISABLE_SPELLER #ifndef DISABLE_SPELLER
whole_word, whole_word,
#endif #endif
#ifdef HAVE_REGEX_H FALSE, real_current, *real_current_x, needle, &match_len)) {
/* 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
* found one on the beginning line, so we should skip over the
* beginning line when doing this search. */
bol_or_eol
#else
FALSE
#endif
, real_current, *real_current_x, needle, &match_len)) {
int i = 0; int i = 0;
#ifndef NANO_TINY #ifndef NANO_TINY
@ -693,22 +680,6 @@ ssize_t do_replace_loop(
} }
#endif #endif
#ifdef HAVE_REGEX_H
/* If the bol_or_eol flag is set, we've found a match on the
* beginning line already, and we're still on the beginning line
* after the search, it means that we've wrapped around, so
* we're done. */
if (bol_or_eol && begin_line && openfile->current == real_current)
break;
/* Otherwise, set the begin_line flag if we've found a match on
* the beginning line, reset the bol_or_eol flag, and continue. */
else {
if (openfile->current == real_current)
begin_line = TRUE;
bol_or_eol = FALSE;
}
#endif
/* Indicate that we found the search string. */ /* Indicate that we found the search string. */
if (numreplaced == -1) if (numreplaced == -1)
numreplaced = 0; numreplaced = 0;
@ -741,13 +712,6 @@ ssize_t do_replace_loop(
} }
} }
#ifdef HAVE_REGEX_H
/* Set the bol_or_eol flag if we're doing a bol and/or eol regex
* replace ("^", "$", or "^$"). */
if (ISSET(USE_REGEXP) && regexp_bol_or_eol(&search_regexp, needle))
bol_or_eol = TRUE;
#endif
if (i > 0 || replaceall) { /* Yes, replace it!!!! */ if (i > 0 || replaceall) { /* Yes, replace it!!!! */
char *copy; char *copy;
size_t length_change; size_t length_change;

View File

@ -250,15 +250,6 @@ ssize_t ngetline(char **lineptr, size_t *n, FILE *stream)
#endif /* !DISABLE_NANORC */ #endif /* !DISABLE_NANORC */
#ifdef HAVE_REGEX_H #ifdef HAVE_REGEX_H
/* Do the compiled regex in preg and the regex in string match the
* beginning or end of a line? */
bool regexp_bol_or_eol(const regex_t *preg, const char *string)
{
return (regexec(preg, string, 0, NULL, 0) == 0 &&
regexec(preg, string, 0, NULL, REG_NOTBOL | REG_NOTEOL) ==
REG_NOMATCH);
}
/* Fix the regex if we're on platforms which require an adjustment /* Fix the regex if we're on platforms which require an adjustment
* from GNU-style to BSD-style word boundaries. */ * from GNU-style to BSD-style word boundaries. */
const char *fixbounds(const char *r) const char *fixbounds(const char *r)
@ -290,12 +281,11 @@ const char *fixbounds(const char *r)
fprintf(stderr, "fixbounds(): Ending string = \"%s\"\n", r3); fprintf(stderr, "fixbounds(): Ending string = \"%s\"\n", r3);
#endif #endif
return (const char *) r3; return (const char *) r3;
#endif #endif /* !GNU_WORDBOUNDS */
return r; return r;
} }
#endif /* HAVE_REGEX_H */
#endif
#ifndef DISABLE_SPELLER #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? */