summaryrefslogtreecommitdiff
path: root/usr.bin/mg/re_search.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2000-02-29 01:44:34 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2000-02-29 01:44:34 +0000
commit620f73a9e03d8c6bdcf404f200eadfeaf8b9c92a (patch)
treef680b69603ff938bce7f21145767f52e50266aff /usr.bin/mg/re_search.c
parentfd089231ba3f5470566f08edad4d1a83315b2e31 (diff)
Make reverse searching work.
Diffstat (limited to 'usr.bin/mg/re_search.c')
-rw-r--r--usr.bin/mg/re_search.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/usr.bin/mg/re_search.c b/usr.bin/mg/re_search.c
index 6c5a9b9f115..59641ca9a33 100644
--- a/usr.bin/mg/re_search.c
+++ b/usr.bin/mg/re_search.c
@@ -390,7 +390,7 @@ re_backsrch() {
register LINE *clp;
register int tbo;
- int error, startpos;
+ regmatch_t lastmatch;
char m[1];
clp = curwp->w_dotp;
@@ -410,15 +410,25 @@ re_backsrch() {
while (clp != (curbp->b_linep)) {
- re_match[0].rm_so = tbo;
- re_match[0].rm_eo = llength(clp);
- /* XXX - does not search backwards! */
- error = regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND);
+ re_match[0].rm_so = 0;
+ re_match[0].rm_eo = tbo;
+ lastmatch.rm_so = -1;
+ /* Keep searching until we don't match any longer. Assumes a non-match
+ does not modify the re_match array.
+ */
+ while (!regexec(&re_buff, ltext(clp), RE_NMATCH, re_match, REG_STARTEND)) {
+ 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;
+ }
- if (error) {
+ if (lastmatch.rm_so == -1) {
clp = lback(clp);
tbo = llength(clp);
} else {
+ memcpy(&re_match[0], &lastmatch, sizeof(regmatch_t));
curwp->w_doto = re_match[0].rm_so;
curwp->w_dotp = clp;
curwp->w_flag |= WFMOVE;