find all beginning-of-line and/or end-of-line regexes once per line, not
just the zero-length ones; this fixes multiple replaces occurring with them in conjunction with "*" git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@1608 35c25a1d-7b9e-4130-9fde-d3aeb78583b8master
parent
afb75f22b2
commit
e190ff30f2
16
ChangeLog
16
ChangeLog
|
@ -80,14 +80,14 @@ CVS code -
|
||||||
- search.c:
|
- search.c:
|
||||||
findnextstr(), do_replace_loop()
|
findnextstr(), do_replace_loop()
|
||||||
- Fix potential infinite loops and other misbehavior when doing
|
- Fix potential infinite loops and other misbehavior when doing
|
||||||
certain zero-length regex replacements ("^", "$", and "^$").
|
beginning-of-line or end-of-line regex replacements ("^", "$",
|
||||||
Add a no_sameline parameter to findnextstr(), and set it in
|
and "^$"). Add a no_sameline parameter to findnextstr(), and
|
||||||
the calls in do_replace_loop() when such regexes are found, so
|
set it in the calls in do_replace_loop() when such regexes are
|
||||||
that such regexes are only found once per line. Also change
|
found, so that such regexes are only found once per line.
|
||||||
length_change from a long to an int; size_t is unsuitable due
|
Also change length_change from a long to an int; size_t is
|
||||||
to its being unsigned. (DLR; found by Mike Frysinger and DLR)
|
unsuitable due to its being unsigned. (DLR; found by Mike
|
||||||
David Benbennick: Add a few minor cleanups to
|
Frysinger and DLR) David Benbennick: Add a few minor cleanups
|
||||||
do_replace_loop().
|
to do_replace_loop().
|
||||||
- winio.c:
|
- winio.c:
|
||||||
get_kbinput(), get_accepted_kbinput()
|
get_kbinput(), get_accepted_kbinput()
|
||||||
- Don't pass in the value of the REBIND_DELETE flag anymore.
|
- Don't pass in the value of the REBIND_DELETE flag anymore.
|
||||||
|
|
|
@ -109,7 +109,7 @@ void update_color(void)
|
||||||
|
|
||||||
for (e = tmpsyntax->extensions; e != NULL; e = e->next) {
|
for (e = tmpsyntax->extensions; e != NULL; e = e->next) {
|
||||||
/* Set colorstrings if we matched the extension regex */
|
/* Set colorstrings if we matched the extension regex */
|
||||||
if (!regexec(&e->val, filename, 0, NULL, 0))
|
if (regexec(&e->val, filename, 0, NULL, 0) == 0)
|
||||||
colorstrings = tmpsyntax->color;
|
colorstrings = tmpsyntax->color;
|
||||||
|
|
||||||
if (colorstrings != NULL)
|
if (colorstrings != NULL)
|
||||||
|
|
29
src/search.c
29
src/search.c
|
@ -618,8 +618,8 @@ int do_replace_loop(const char *prevanswer, const filestruct *begin,
|
||||||
{
|
{
|
||||||
int replaceall = 0, numreplaced = -1;
|
int replaceall = 0, numreplaced = -1;
|
||||||
#ifdef HAVE_REGEX_H
|
#ifdef HAVE_REGEX_H
|
||||||
/* The starting-line match and zero-length regex flags. */
|
/* The starting-line match and bol/eol regex flags. */
|
||||||
int beginline = 0, caretdollar = 0;
|
int beginline = 0, bol_eol = 0;
|
||||||
#endif
|
#endif
|
||||||
filestruct *fileptr = NULL;
|
filestruct *fileptr = NULL;
|
||||||
|
|
||||||
|
@ -649,31 +649,30 @@ int do_replace_loop(const char *prevanswer, const filestruct *begin,
|
||||||
fileptr = findnextstr(fileptr || replaceall || search_last_line,
|
fileptr = findnextstr(fileptr || replaceall || search_last_line,
|
||||||
FALSE, begin, *beginx, prevanswer,
|
FALSE, begin, *beginx, prevanswer,
|
||||||
#ifdef HAVE_REGEX_H
|
#ifdef HAVE_REGEX_H
|
||||||
/* We should find a zero-length regex only once per
|
/* We should find a bol and/or eol regex only once per
|
||||||
* line. If the caretdollar flag is set, it means that
|
* line. If the bol_eol flag is set, it means that the
|
||||||
* the last search found one on the beginning line, so we
|
* last search found one on the beginning line, so we
|
||||||
* should skip over the beginning line when doing this
|
* should skip over the beginning line when doing this
|
||||||
* search. */
|
* search. */
|
||||||
caretdollar
|
bol_eol
|
||||||
#else
|
#else
|
||||||
0
|
0
|
||||||
#endif
|
#endif
|
||||||
);
|
);
|
||||||
|
|
||||||
#ifdef HAVE_REGEX_H
|
#ifdef HAVE_REGEX_H
|
||||||
/* If the caretdollar flag is set, we've found a match on the
|
/* If the bol_eol flag is set, we've found a match on the
|
||||||
* beginning line already, and we're still on the beginning line
|
* beginning line already, and we're still on the beginning line
|
||||||
* after the search, it means that we've wrapped around, so
|
* after the search, it means that we've wrapped around, so
|
||||||
* we're done. */
|
* we're done. */
|
||||||
if (caretdollar && beginline && fileptr == begin)
|
if (bol_eol && beginline && fileptr == begin)
|
||||||
fileptr = NULL;
|
fileptr = NULL;
|
||||||
/* Otherwise, set the beginline flag if we've found a match on
|
/* Otherwise, set the beginline flag if we've found a match on
|
||||||
* the beginning line, reset the caretdollar flag, and
|
* the beginning line, reset the bol_eol flag, and continue. */
|
||||||
* continue. */
|
|
||||||
else {
|
else {
|
||||||
if (fileptr == begin)
|
if (fileptr == begin)
|
||||||
beginline = 1;
|
beginline = 1;
|
||||||
caretdollar = 0;
|
bol_eol = 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -721,10 +720,10 @@ int do_replace_loop(const char *prevanswer, const filestruct *begin,
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_REGEX_H
|
#ifdef HAVE_REGEX_H
|
||||||
/* Set the caretdollar flag if we're doing a zero-length regex
|
/* Set the bol_eol flag if we're doing a bol and/or eol regex
|
||||||
* replace (such as "^", "$", or "^$"). */
|
* replace ("^", "$", or "^$"). */
|
||||||
if (ISSET(USE_REGEXP) && match_len == 0)
|
if (ISSET(USE_REGEXP) && regexec(&search_regexp, prevanswer, 1, NULL, REG_NOTBOL | REG_NOTEOL) == REG_NOMATCH)
|
||||||
caretdollar = 1;
|
bol_eol = 1;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (*i > 0 || replaceall) { /* Yes, replace it!!!! */
|
if (*i > 0 || replaceall) { /* Yes, replace it!!!! */
|
||||||
|
|
10
src/utils.c
10
src/utils.c
|
@ -197,13 +197,13 @@ const char *strstrwrapper(const char *haystack, const char *needle,
|
||||||
#ifndef NANO_SMALL
|
#ifndef NANO_SMALL
|
||||||
if (ISSET(REVERSE_SEARCH)) {
|
if (ISSET(REVERSE_SEARCH)) {
|
||||||
/* When doing a backwards search, haystack is a whole line. */
|
/* When doing a backwards search, haystack is a whole line. */
|
||||||
if (!regexec(&search_regexp, haystack, 1, regmatches, 0) &&
|
if (regexec(&search_regexp, haystack, 1, regmatches, 0) == 0 &&
|
||||||
haystack + regmatches[0].rm_so <= rev_start) {
|
haystack + regmatches[0].rm_so <= rev_start) {
|
||||||
const char *retval = haystack + regmatches[0].rm_so;
|
const char *retval = haystack + regmatches[0].rm_so;
|
||||||
|
|
||||||
/* Search forward until there is no more match. */
|
/* Search forward until there is no more match. */
|
||||||
while (!regexec(&search_regexp, retval + 1, 1, regmatches,
|
while (regexec(&search_regexp, retval + 1, 1, regmatches,
|
||||||
REG_NOTBOL) &&
|
REG_NOTBOL) == 0 &&
|
||||||
retval + 1 + regmatches[0].rm_so <= rev_start)
|
retval + 1 + regmatches[0].rm_so <= rev_start)
|
||||||
retval += 1 + regmatches[0].rm_so;
|
retval += 1 + regmatches[0].rm_so;
|
||||||
/* Finally, put the subexpression matches in global
|
/* Finally, put the subexpression matches in global
|
||||||
|
@ -214,8 +214,8 @@ const char *strstrwrapper(const char *haystack, const char *needle,
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
#endif /* !NANO_SMALL */
|
#endif /* !NANO_SMALL */
|
||||||
if (!regexec(&search_regexp, haystack, 10, regmatches,
|
if (regexec(&search_regexp, haystack, 10, regmatches,
|
||||||
line_pos > 0 ? REG_NOTBOL : 0)) {
|
line_pos > 0 ? REG_NOTBOL : 0) == 0) {
|
||||||
const char *retval = haystack + regmatches[0].rm_so;
|
const char *retval = haystack + regmatches[0].rm_so;
|
||||||
|
|
||||||
regexec(&search_regexp, retval, 10, regmatches, 0);
|
regexec(&search_regexp, retval, 10, regmatches, 0);
|
||||||
|
|
Loading…
Reference in New Issue