diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2000-02-29 16:00:24 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2000-02-29 16:00:24 +0000 |
commit | 36e031c7ab3edb9a631825a86f7f161f1797307d (patch) | |
tree | e3274b0d92f8e6b05748d0c37a7825505efb6cdb /usr.bin/mg | |
parent | f10a92d1ad16e55c16d6fd3fa6b5d64ae03682d0 (diff) |
Better backwards regexp searching. POSIX regexp's don't really give
a good way to do this.
Diffstat (limited to 'usr.bin/mg')
-rw-r--r-- | usr.bin/mg/re_search.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/usr.bin/mg/re_search.c b/usr.bin/mg/re_search.c index 59641ca9a33..4be7c271c82 100644 --- a/usr.bin/mg/re_search.c +++ b/usr.bin/mg/re_search.c @@ -411,17 +411,18 @@ re_backsrch() { while (clp != (curbp->b_linep)) { re_match[0].rm_so = 0; - re_match[0].rm_eo = tbo; + re_match[0].rm_eo = llength(clp); lastmatch.rm_so = -1; /* Keep searching until we don't match any longer. Assumes a non-match - does not modify the re_match array. + does not modify the re_match array. We have to do this + character-by-character after the first match since POSIX regexps don't + give you a way to do reverse matches. */ - while (!regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND)) { + while (!regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND) && + re_match[0].rm_so < tbo) { memcpy(&lastmatch, &re_match[0], sizeof(regmatch_t)); - if (re_match[0].rm_eo >= tbo) - break; - re_match[0].rm_so = re_match[0].rm_eo; - re_match[0].rm_eo = tbo; + re_match[0].rm_so++; + re_match[0].rm_eo = llength(clp); } if (lastmatch.rm_so == -1) { |